Skip to content

Commit

Permalink
CodeGen from PR 31869 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
Merge 41bbb0705062205769a3360373705880ee98b6a5 into 5d48b962e325123b8a3514f7eff49702838a942d
  • Loading branch information
SDKAuto committed Feb 11, 2025
1 parent 5e04ce6 commit 1179395
Show file tree
Hide file tree
Showing 31 changed files with 391 additions and 6,561 deletions.
6 changes: 6 additions & 0 deletions sdk/ai/azure-ai-inference/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"commit": "03dbe6c563a5196704d5381e97d1df4d1da1dea6",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"typespec_src": "specification/ai/ModelClient",
"@azure-tools/typespec-python": "0.38.3"
}
41 changes: 41 additions & 0 deletions sdk/ai/azure-ai-inference/apiview-properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"CrossLanguagePackageId": "AI.Model",
"CrossLanguageDefinitionId": {
"azure.ai.inference.models.ContentItem": "AI.Model.ChatMessageContentItem",
"azure.ai.inference.models.AudioUrlContentItem": "AI.Model.ChatMessageAudioUrlContentItem",
"azure.ai.inference.models.ChatChoice": "AI.Model.ChatChoice",
"azure.ai.inference.models.ChatCompletions": "AI.Model.ChatCompletions",
"azure.ai.inference.models.ChatCompletionsNamedToolChoice": "AI.Model.ChatCompletionsNamedToolChoice",
"azure.ai.inference.models.ChatCompletionsNamedToolChoiceFunction": "AI.Model.ChatCompletionsNamedToolChoiceFunction",
"azure.ai.inference.models.ChatCompletionsToolCall": "AI.Model.ChatCompletionsToolCall",
"azure.ai.inference.models.ChatCompletionsToolDefinition": "AI.Model.ChatCompletionsToolDefinition",
"azure.ai.inference.models.ChatMessageAudioDataContentItem": "AI.Model.ChatMessageAudioDataContentItem",
"azure.ai.inference.models.ChatMessageInputAudioUrl": "AI.Model.ChatMessageInputAudioUrl",
"azure.ai.inference.models.ChatResponseMessage": "AI.Model.ChatResponseMessage",
"azure.ai.inference.models.CompletionsUsage": "AI.Model.CompletionsUsage",
"azure.ai.inference.models.EmbeddingItem": "AI.Model.EmbeddingItem",
"azure.ai.inference.models.EmbeddingsResult": "AI.Model.EmbeddingsResult",
"azure.ai.inference.models.EmbeddingsUsage": "AI.Model.EmbeddingsUsage",
"azure.ai.inference.models.FunctionCall": "AI.Model.FunctionCall",
"azure.ai.inference.models.FunctionDefinition": "AI.Model.FunctionDefinition",
"azure.ai.inference.models.ImageContentItem": "AI.Model.ChatMessageImageContentItem",
"azure.ai.inference.models.ImageEmbeddingInput": "AI.Model.ImageEmbeddingInput",
"azure.ai.inference.models.ImageUrl": "AI.Model.ChatMessageImageUrl",
"azure.ai.inference.models.InputAudio": "AI.Model.ChatMessageInputAudio",
"azure.ai.inference.models.JsonSchemaFormat": "AI.Model.ChatCompletionsResponseFormatJsonSchemaDefinition",
"azure.ai.inference.models.ModelInfo": "AI.Model.ModelInfo",
"azure.ai.inference.models.StreamingChatChoiceUpdate": "AI.Model.StreamingChatChoiceUpdate",
"azure.ai.inference.models.StreamingChatCompletionsUpdate": "AI.Model.StreamingChatCompletionsUpdate",
"azure.ai.inference.models.StreamingChatResponseMessageUpdate": "AI.Model.StreamingChatResponseMessageUpdate",
"azure.ai.inference.models.StreamingChatResponseToolCallUpdate": "AI.Model.StreamingChatResponseToolCallUpdate",
"azure.ai.inference.models.TextContentItem": "AI.Model.ChatMessageTextContentItem",
"azure.ai.inference.models.CompletionsFinishReason": "AI.Model.CompletionsFinishReason",
"azure.ai.inference.models.ChatRole": "AI.Model.ChatRole",
"azure.ai.inference.models.ImageDetailLevel": "AI.Model.ChatMessageImageDetailLevel",
"azure.ai.inference.models.AudioContentFormat": "AI.Model.AudioContentFormat",
"azure.ai.inference.models.ChatCompletionsToolChoicePreset": "AI.Model.ChatCompletionsToolChoicePreset",
"azure.ai.inference.models.ModelType": "AI.Model.ModelType",
"azure.ai.inference.models.EmbeddingEncodingFormat": "AI.Model.EmbeddingEncodingFormat",
"azure.ai.inference.models.EmbeddingInputType": "AI.Model.EmbeddingInputType"
}
}
6 changes: 3 additions & 3 deletions sdk/ai/azure-ai-inference/azure/ai/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ChatCompletionsClient(ChatCompletionsClientOperationsMixin):
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2024-05-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand Down Expand Up @@ -117,7 +117,7 @@ class EmbeddingsClient(EmbeddingsClientOperationsMixin):
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2024-05-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand Down Expand Up @@ -195,7 +195,7 @@ class ImageEmbeddingsClient(ImageEmbeddingsClientOperationsMixin):
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2024-05-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand Down
12 changes: 3 additions & 9 deletions sdk/ai/azure-ai-inference/azure/ai/inference/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ChatCompletionsClientConfiguration: # pylint: disable=too-many-instance-a
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2024-05-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand All @@ -54,8 +54,6 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCr
def _infer_policy(self, **kwargs):
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "Authorization", prefix="Bearer", **kwargs)
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "api-key", **kwargs)
if hasattr(self.credential, "get_token"):
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
raise TypeError(f"Unsupported credential: {self.credential}")
Expand Down Expand Up @@ -85,7 +83,7 @@ class EmbeddingsClientConfiguration: # pylint: disable=too-many-instance-attrib
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2024-05-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand All @@ -111,8 +109,6 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCr
def _infer_policy(self, **kwargs):
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "Authorization", prefix="Bearer", **kwargs)
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "api-key", **kwargs)
if hasattr(self.credential, "get_token"):
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
raise TypeError(f"Unsupported credential: {self.credential}")
Expand Down Expand Up @@ -142,7 +138,7 @@ class ImageEmbeddingsClientConfiguration: # pylint: disable=too-many-instance-a
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2024-05-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand All @@ -168,8 +164,6 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCr
def _infer_policy(self, **kwargs):
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "Authorization", prefix="Bearer", **kwargs)
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "api-key", **kwargs)
if hasattr(self.credential, "get_token"):
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
raise TypeError(f"Unsupported credential: {self.credential}")
Expand Down
62 changes: 61 additions & 1 deletion sdk/ai/azure-ai-inference/azure/ai/inference/_model_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=too-many-lines,arguments-differ,signature-differs,no-member
# pylint: disable=too-many-lines
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
Expand Down Expand Up @@ -373,15 +373,34 @@ def __ne__(self, other: typing.Any) -> bool:
return not self.__eq__(other)

def keys(self) -> typing.KeysView[str]:
"""
:returns: a set-like object providing a view on D's keys
:rtype: ~typing.KeysView
"""
return self._data.keys()

def values(self) -> typing.ValuesView[typing.Any]:
"""
:returns: an object providing a view on D's values
:rtype: ~typing.ValuesView
"""
return self._data.values()

def items(self) -> typing.ItemsView[str, typing.Any]:
"""
:returns: set-like object providing a view on D's items
:rtype: ~typing.ItemsView
"""
return self._data.items()

def get(self, key: str, default: typing.Any = None) -> typing.Any:
"""
Get the value for key if key is in the dictionary, else default.
:param str key: The key to look up.
:param any default: The value to return if key is not in the dictionary. Defaults to None
:returns: D[k] if k in D, else d.
:rtype: any
"""
try:
return self[key]
except KeyError:
Expand All @@ -397,17 +416,38 @@ def pop(self, key: str, default: _T) -> _T: ...
def pop(self, key: str, default: typing.Any) -> typing.Any: ...

def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
"""
Removes specified key and return the corresponding value.
:param str key: The key to pop.
:param any default: The value to return if key is not in the dictionary
:returns: The value corresponding to the key.
:rtype: any
:raises KeyError: If key is not found and default is not given.
"""
if default is _UNSET:
return self._data.pop(key)
return self._data.pop(key, default)

def popitem(self) -> typing.Tuple[str, typing.Any]:
"""
Removes and returns some (key, value) pair
:returns: The (key, value) pair.
:rtype: tuple
:raises KeyError: if D is empty.
"""
return self._data.popitem()

def clear(self) -> None:
"""
Remove all items from D.
"""
self._data.clear()

def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
"""
Updates D from mapping/iterable E and F.
:param any args: Either a mapping object or an iterable of key-value pairs.
"""
self._data.update(*args, **kwargs)

@typing.overload
Expand All @@ -417,6 +457,13 @@ def setdefault(self, key: str, default: None = None) -> None: ...
def setdefault(self, key: str, default: typing.Any) -> typing.Any: ...

def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
"""
Same as calling D.get(k, d), and setting D[k]=d if k not found
:param str key: The key to look up.
:param any default: The value to set if key is not in the dictionary
:returns: D[k] if k in D, else d.
:rtype: any
"""
if default is _UNSET:
return self._data.setdefault(key)
return self._data.setdefault(key, default)
Expand Down Expand Up @@ -910,6 +957,19 @@ def _failsafe_deserialize(
return None


def _failsafe_deserialize_xml(
deserializer: typing.Any,
value: typing.Any,
) -> typing.Any:
try:
return _deserialize_xml(deserializer, value)
except DeserializationError:
_LOGGER.warning(
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True
)
return None


class _RestField:
def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=too-many-locals
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
Expand Down Expand Up @@ -181,15 +180,6 @@ def build_image_embeddings_get_model_info_request(**kwargs: Any) -> HttpRequest:

class ChatCompletionsClientOperationsMixin(ChatCompletionsClientMixinABC):

@overload
def _complete(
self,
body: JSON,
*,
extra_params: Optional[Union[str, _models._enums.ExtraParameters]] = None,
content_type: str = "application/json",
**kwargs: Any
) -> _models.ChatCompletions: ...
@overload
def _complete(
self,
Expand All @@ -214,6 +204,15 @@ def _complete(
**kwargs: Any
) -> _models.ChatCompletions: ...
@overload
def _complete(
self,
body: JSON,
*,
extra_params: Optional[Union[str, _models._enums.ExtraParameters]] = None,
content_type: str = "application/json",
**kwargs: Any
) -> _models.ChatCompletions: ...
@overload
def _complete(
self,
body: IO[bytes],
Expand Down Expand Up @@ -488,23 +487,23 @@ class EmbeddingsClientOperationsMixin(EmbeddingsClientMixinABC):
@overload
def _embed(
self,
body: JSON,
*,
input: List[str],
extra_params: Optional[Union[str, _models._enums.ExtraParameters]] = None,
content_type: str = "application/json",
dimensions: Optional[int] = None,
encoding_format: Optional[Union[str, _models.EmbeddingEncodingFormat]] = None,
input_type: Optional[Union[str, _models.EmbeddingInputType]] = None,
model: Optional[str] = None,
**kwargs: Any
) -> _models.EmbeddingsResult: ...
@overload
def _embed(
self,
body: JSON,
*,
input: List[str],
extra_params: Optional[Union[str, _models._enums.ExtraParameters]] = None,
content_type: str = "application/json",
dimensions: Optional[int] = None,
encoding_format: Optional[Union[str, _models.EmbeddingEncodingFormat]] = None,
input_type: Optional[Union[str, _models.EmbeddingInputType]] = None,
model: Optional[str] = None,
**kwargs: Any
) -> _models.EmbeddingsResult: ...
@overload
Expand Down Expand Up @@ -701,23 +700,23 @@ class ImageEmbeddingsClientOperationsMixin(ImageEmbeddingsClientMixinABC):
@overload
def _embed(
self,
body: JSON,
*,
input: List[_models.ImageEmbeddingInput],
extra_params: Optional[Union[str, _models._enums.ExtraParameters]] = None,
content_type: str = "application/json",
dimensions: Optional[int] = None,
encoding_format: Optional[Union[str, _models.EmbeddingEncodingFormat]] = None,
input_type: Optional[Union[str, _models.EmbeddingInputType]] = None,
model: Optional[str] = None,
**kwargs: Any
) -> _models.EmbeddingsResult: ...
@overload
def _embed(
self,
body: JSON,
*,
input: List[_models.ImageEmbeddingInput],
extra_params: Optional[Union[str, _models._enums.ExtraParameters]] = None,
content_type: str = "application/json",
dimensions: Optional[int] = None,
encoding_format: Optional[Union[str, _models.EmbeddingEncodingFormat]] = None,
input_type: Optional[Union[str, _models.EmbeddingInputType]] = None,
model: Optional[str] = None,
**kwargs: Any
) -> _models.EmbeddingsResult: ...
@overload
Expand Down
Loading

0 comments on commit 1179395

Please sign in to comment.