Skip to content

Commit 4157599

Browse files
dargilcotrangevinick863
authored
Beta 8 release of azure-ai-inference Python SDK (#39454)
* Remove mentioning of length of API key. I can now be longer than 32-chars. (#39363) * Changes to Support Audio Input in ChatCompletions (#39357) * Add classes to support audio input for chat completions. * Add corresponding tests and sample * Update to version beta 8 * Do not filter out the usage updates. (#39381) * Allow usage updates * Add changelog entry * Fix typo in CHANGELOG.md * Update changelog for audio input (#39443) * Update changelog for audio input Signed-off-by: trangevi <[email protected]> * Remove empty sections Signed-off-by: trangevi <[email protected]> --------- Signed-off-by: trangevi <[email protected]> * Update product link in pacakge README.md * Fix indentation. Add release date Signed-off-by: trangevi <[email protected]> --------- Signed-off-by: trangevi <[email protected]> Co-authored-by: Travis Angevine <[email protected]> Co-authored-by: nick863 <[email protected]>
1 parent ba7691f commit 4157599

File tree

61 files changed

+552
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+552
-212
lines changed

.vscode/cspell.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"sdk/batch/azure-batch/**",
3434
"sdk/ai/**/index/**",
3535
"sdk/ai/azure-ai-generative/tests/**",
36+
"sdk/ai/azure-ai-inference/samples/hello_how_are_you.mp3",
37+
"sdk/ai/azure-ai-inference/tests/hello_how_are_you.mp3",
3638
"sdk/ai/azure-ai-projects/samples/agents/nifty_500_quarterly_results.csv",
3739
"/sdk/ai/azure-ai-projects/samples/evaluations/async_samples/data/**",
3840
"/sdk/ai/azure-ai-projects/samples/evaluations/data/**",
@@ -1363,7 +1365,10 @@
13631365
"prompty",
13641366
"rdel",
13651367
"ubinary",
1366-
"wday"
1368+
"wday",
1369+
"Hola",
1370+
"cómo",
1371+
"estás"
13671372
]
13681373
},
13691374
{

sdk/ai/azure-ai-inference/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Release History
22

3+
## 1.0.0b8 (2025-01-29)
4+
5+
### Features Added
6+
7+
* Added support for Chat Completions with audio input. See new sample `sample_chat_completions_with_audio_data.py`.
8+
9+
### Bugs Fixed
10+
11+
* Fix a bug that caused filtering of a package with token usage from Azure OpenAI models in the streaming mode.
12+
313
## 1.0.0b7 (2025-01-15)
414

515
### Features Added

sdk/ai/azure-ai-inference/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The Inference client library supports AI models deployed to the following servic
1616

1717
The Inference client library makes services calls using REST API version `2024-05-01-preview`, as documented in [Azure AI Model Inference API](https://aka.ms/azureai/modelinference).
1818

19-
[Product documentation](https://aka.ms/azureai/modelinference)
19+
[Product documentation](https://aka.ms/aiservices/inference)
2020
| [Samples](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ai/azure-ai-inference/samples)
2121
| [API reference documentation](https://aka.ms/azsdk/azure-ai-inference/python/reference)
2222
| [Package (Pypi)](https://aka.ms/azsdk/azure-ai-inference/python/package)
@@ -38,12 +38,12 @@ To report an issue with the client library, or request additional features, plea
3838
* An [Azure subscription](https://azure.microsoft.com/free).
3939
* An [AI Model from the catalog](https://ai.azure.com/explore/models) deployed through Azure AI Foundry.
4040
* The endpoint URL of your model, in of the form `https://<your-host-name>.<your-azure-region>.models.ai.azure.com`, where `your-host-name` is your unique model deployment host name and `your-azure-region` is the Azure region where the model is deployed (e.g. `eastus2`).
41-
* Depending on your authentication preference, you either need an API key to authenticate against the service, or Entra ID credentials. The API key is a 32-character string.
41+
* Depending on your authentication preference, you either need an API key to authenticate against the service, or Entra ID credentials.
4242
* For Azure OpenAI (AOAI) service
4343
* An [Azure subscription](https://azure.microsoft.com/free).
4444
* An [OpenAI Model from the catalog](https://oai.azure.com/resource/models) deployed through Azure AI Foundry.
4545
* The endpoint URL of your model, in the form `https://<your-resouce-name>.openai.azure.com/openai/deployments/<your-deployment-name>`, where `your-resource-name` is your globally unique AOAI resource name, and `your-deployment-name` is your AI Model deployment name.
46-
* Depending on your authentication preference, you either need an API key to authenticate against the service, or Entra ID credentials. The API key is a 32-character string.
46+
* Depending on your authentication preference, you either need an API key to authenticate against the service, or Entra ID credentials.
4747
* An api-version. Latest preview or GA version listed in the `Data plane - inference` row in [the API Specs table](https://aka.ms/azsdk/azure-ai-inference/azure-openai-api-versions). At the time of writing, latest GA version was "2024-06-01".
4848

4949
### Install the package
@@ -281,6 +281,7 @@ The following types of messages are supported: `SystemMessage`,`UserMessage`, `A
281281
includes sending an image URL.
282282
* [sample_chat_completions_with_image_data.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_data.py) for usage of `UserMessage` that
283283
includes sending image data read from a local file.
284+
* [sample_chat_completions_with_audio_data.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_data.py) for usage of `UserMessage` that includes sending audio data read from a local file.
284285
* [sample_chat_completions_with_structured_output.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_structured_output.py) and [sample_chat_completions_with_structured_output_pydantic.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_structured_output_pydantic.py) for configuring the service to respond with a JSON-formatted string, adhering to your schema.
285286

286287

sdk/ai/azure-ai-inference/assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ai/azure-ai-inference",
5-
"Tag": "python/ai/azure-ai-inference_642ed25a8c"
5+
"Tag": "python/ai/azure-ai-inference_bc7c5bd581"
66
}

sdk/ai/azure-ai-inference/azure/ai/inference/_client.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class ChatCompletionsClient(ChatCompletionsClientOperationsMixin):
3636
3737
:param endpoint: Service host. Required.
3838
:type endpoint: str
39-
:param credential: Credential used to authenticate requests to the service. Is one of the
40-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
39+
:param credential: Credential used to authenticate requests to the service. Is either a key
40+
credential type or a token credential type. Required.
4141
:type credential: ~azure.core.credentials.AzureKeyCredential or
4242
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
4343
:keyword api_version: The API version to use for this operation. Default value is
@@ -114,8 +114,8 @@ class EmbeddingsClient(EmbeddingsClientOperationsMixin):
114114
115115
:param endpoint: Service host. Required.
116116
:type endpoint: str
117-
:param credential: Credential used to authenticate requests to the service. Is one of the
118-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
117+
:param credential: Credential used to authenticate requests to the service. Is either a key
118+
credential type or a token credential type. Required.
119119
:type credential: ~azure.core.credentials.AzureKeyCredential or
120120
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
121121
:keyword api_version: The API version to use for this operation. Default value is
@@ -192,8 +192,8 @@ class ImageEmbeddingsClient(ImageEmbeddingsClientOperationsMixin):
192192
193193
:param endpoint: Service host. Required.
194194
:type endpoint: str
195-
:param credential: Credential used to authenticate requests to the service. Is one of the
196-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
195+
:param credential: Credential used to authenticate requests to the service. Is either a key
196+
credential type or a token credential type. Required.
197197
:type credential: ~azure.core.credentials.AzureKeyCredential or
198198
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
199199
:keyword api_version: The API version to use for this operation. Default value is

sdk/ai/azure-ai-inference/azure/ai/inference/_configuration.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ChatCompletionsClientConfiguration: # pylint: disable=too-many-instance-a
2525
2626
:param endpoint: Service host. Required.
2727
:type endpoint: str
28-
:param credential: Credential used to authenticate requests to the service. Is one of the
29-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
28+
:param credential: Credential used to authenticate requests to the service. Is either a key
29+
credential type or a token credential type. Required.
3030
:type credential: ~azure.core.credentials.AzureKeyCredential or
3131
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
3232
:keyword api_version: The API version to use for this operation. Default value is
@@ -82,8 +82,8 @@ class EmbeddingsClientConfiguration: # pylint: disable=too-many-instance-attrib
8282
8383
:param endpoint: Service host. Required.
8484
:type endpoint: str
85-
:param credential: Credential used to authenticate requests to the service. Is one of the
86-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
85+
:param credential: Credential used to authenticate requests to the service. Is either a key
86+
credential type or a token credential type. Required.
8787
:type credential: ~azure.core.credentials.AzureKeyCredential or
8888
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
8989
:keyword api_version: The API version to use for this operation. Default value is
@@ -139,8 +139,8 @@ class ImageEmbeddingsClientConfiguration: # pylint: disable=too-many-instance-a
139139
140140
:param endpoint: Service host. Required.
141141
:type endpoint: str
142-
:param credential: Credential used to authenticate requests to the service. Is one of the
143-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
142+
:param credential: Credential used to authenticate requests to the service. Is either a key
143+
credential type or a token credential type. Required.
144144
:type credential: ~azure.core.credentials.AzureKeyCredential or
145145
~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential
146146
:keyword api_version: The API version to use for this operation. Default value is

sdk/ai/azure-ai-inference/azure/ai/inference/_patch.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ def _get_internal_response_format(
9898
_models._models.ChatCompletionsResponseFormatJsonObject() # pylint: disable=protected-access
9999
)
100100
elif isinstance(response_format, _models.JsonSchemaFormat):
101-
internal_response_format = _models._models.ChatCompletionsResponseFormatJsonSchema( # pylint: disable=protected-access
102-
json_schema=response_format
101+
internal_response_format = (
102+
_models._models.ChatCompletionsResponseFormatJsonSchema( # pylint: disable=protected-access
103+
json_schema=response_format
104+
)
103105
)
104106
else:
105107
raise ValueError(f"Unsupported `response_format` {response_format}")
@@ -119,8 +121,10 @@ def load_client(
119121
`api_version`, `logging_enable`, `user_agent`, etc., you can do so here.
120122
This method will only work when using Serverless API or Managed Compute endpoint.
121123
It will not work for GitHub Models endpoint or Azure OpenAI endpoint.
124+
Keyword arguments are passed through to the client constructor (you can set keywords such as
125+
`api_version`, `user_agent`, `logging_enable` etc. on the client constructor).
122126
123-
:param endpoint: Service host. Required.
127+
:param endpoint: Service endpoint URL for AI model inference. Required.
124128
:type endpoint: str
125129
:param credential: Credential used to authenticate requests to the service. Is either a
126130
AzureKeyCredential type or a TokenCredential type. Required.
@@ -192,7 +196,7 @@ def load_client(
192196
class ChatCompletionsClient(ChatCompletionsClientGenerated): # pylint: disable=too-many-instance-attributes
193197
"""ChatCompletionsClient.
194198
195-
:param endpoint: Service host. Required.
199+
:param endpoint: Service endpoint URL for AI model inference. Required.
196200
:type endpoint: str
197201
:param credential: Credential used to authenticate requests to the service. Is either a
198202
AzureKeyCredential type or a TokenCredential type. Required.
@@ -755,7 +759,7 @@ def __str__(self) -> str:
755759
class EmbeddingsClient(EmbeddingsClientGenerated):
756760
"""EmbeddingsClient.
757761
758-
:param endpoint: Service host. Required.
762+
:param endpoint: Service endpoint URL for AI model inference. Required.
759763
:type endpoint: str
760764
:param credential: Credential used to authenticate requests to the service. Is either a
761765
AzureKeyCredential type or a TokenCredential type. Required.
@@ -1051,7 +1055,7 @@ def __str__(self) -> str:
10511055
class ImageEmbeddingsClient(ImageEmbeddingsClientGenerated):
10521056
"""ImageEmbeddingsClient.
10531057
1054-
:param endpoint: Service host. Required.
1058+
:param endpoint: Service endpoint URL for AI model inference. Required.
10551059
:type endpoint: str
10561060
:param credential: Credential used to authenticate requests to the service. Is either a
10571061
AzureKeyCredential type or a TokenCredential type. Required.

sdk/ai/azure-ai-inference/azure/ai/inference/_serialization.py

+2-68
Original file line numberDiff line numberDiff line change
@@ -185,73 +185,7 @@ def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]],
185185
except NameError:
186186
_long_type = int
187187

188-
189-
class UTC(datetime.tzinfo):
190-
"""Time Zone info for handling UTC"""
191-
192-
def utcoffset(self, dt):
193-
"""UTF offset for UTC is 0.
194-
195-
:param datetime.datetime dt: The datetime
196-
:returns: The offset
197-
:rtype: datetime.timedelta
198-
"""
199-
return datetime.timedelta(0)
200-
201-
def tzname(self, dt):
202-
"""Timestamp representation.
203-
204-
:param datetime.datetime dt: The datetime
205-
:returns: The timestamp representation
206-
:rtype: str
207-
"""
208-
return "Z"
209-
210-
def dst(self, dt):
211-
"""No daylight saving for UTC.
212-
213-
:param datetime.datetime dt: The datetime
214-
:returns: The daylight saving time
215-
:rtype: datetime.timedelta
216-
"""
217-
return datetime.timedelta(hours=1)
218-
219-
220-
try:
221-
from datetime import timezone as _FixedOffset # type: ignore
222-
except ImportError: # Python 2.7
223-
224-
class _FixedOffset(datetime.tzinfo): # type: ignore
225-
"""Fixed offset in minutes east from UTC.
226-
Copy/pasted from Python doc
227-
:param datetime.timedelta offset: offset in timedelta format
228-
"""
229-
230-
def __init__(self, offset) -> None:
231-
self.__offset = offset
232-
233-
def utcoffset(self, dt):
234-
return self.__offset
235-
236-
def tzname(self, dt):
237-
return str(self.__offset.total_seconds() / 3600)
238-
239-
def __repr__(self):
240-
return "<FixedOffset {}>".format(self.tzname(None))
241-
242-
def dst(self, dt):
243-
return datetime.timedelta(0)
244-
245-
def __getinitargs__(self):
246-
return (self.__offset,)
247-
248-
249-
try:
250-
from datetime import timezone
251-
252-
TZ_UTC = timezone.utc
253-
except ImportError:
254-
TZ_UTC = UTC() # type: ignore
188+
TZ_UTC = datetime.timezone.utc
255189

256190
_FLATTEN = re.compile(r"(?<!\\)\.")
257191

@@ -2051,7 +1985,7 @@ def deserialize_rfc(attr):
20511985
try:
20521986
parsed_date = email.utils.parsedate_tz(attr) # type: ignore
20531987
date_obj = datetime.datetime(
2054-
*parsed_date[:6], tzinfo=_FixedOffset(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60))
1988+
*parsed_date[:6], tzinfo=datetime.timezone(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60))
20551989
)
20561990
if not date_obj.tzinfo:
20571991
date_obj = date_obj.astimezone(tz=TZ_UTC)

sdk/ai/azure-ai-inference/azure/ai/inference/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
VERSION = "1.0.0b7"
9+
VERSION = "1.0.0b8"

sdk/ai/azure-ai-inference/azure/ai/inference/aio/_client.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class ChatCompletionsClient(ChatCompletionsClientOperationsMixin):
3636
3737
:param endpoint: Service host. Required.
3838
:type endpoint: str
39-
:param credential: Credential used to authenticate requests to the service. Is one of the
40-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
39+
:param credential: Credential used to authenticate requests to the service. Is either a key
40+
credential type or a token credential type. Required.
4141
:type credential: ~azure.core.credentials.AzureKeyCredential or
4242
~azure.core.credentials.AzureKeyCredential or
4343
~azure.core.credentials_async.AsyncTokenCredential
@@ -119,8 +119,8 @@ class EmbeddingsClient(EmbeddingsClientOperationsMixin):
119119
120120
:param endpoint: Service host. Required.
121121
:type endpoint: str
122-
:param credential: Credential used to authenticate requests to the service. Is one of the
123-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
122+
:param credential: Credential used to authenticate requests to the service. Is either a key
123+
credential type or a token credential type. Required.
124124
:type credential: ~azure.core.credentials.AzureKeyCredential or
125125
~azure.core.credentials.AzureKeyCredential or
126126
~azure.core.credentials_async.AsyncTokenCredential
@@ -202,8 +202,8 @@ class ImageEmbeddingsClient(ImageEmbeddingsClientOperationsMixin):
202202
203203
:param endpoint: Service host. Required.
204204
:type endpoint: str
205-
:param credential: Credential used to authenticate requests to the service. Is one of the
206-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
205+
:param credential: Credential used to authenticate requests to the service. Is either a key
206+
credential type or a token credential type. Required.
207207
:type credential: ~azure.core.credentials.AzureKeyCredential or
208208
~azure.core.credentials.AzureKeyCredential or
209209
~azure.core.credentials_async.AsyncTokenCredential

sdk/ai/azure-ai-inference/azure/ai/inference/aio/_configuration.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ChatCompletionsClientConfiguration: # pylint: disable=too-many-instance-a
2525
2626
:param endpoint: Service host. Required.
2727
:type endpoint: str
28-
:param credential: Credential used to authenticate requests to the service. Is one of the
29-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
28+
:param credential: Credential used to authenticate requests to the service. Is either a key
29+
credential type or a token credential type. Required.
3030
:type credential: ~azure.core.credentials.AzureKeyCredential or
3131
~azure.core.credentials.AzureKeyCredential or
3232
~azure.core.credentials_async.AsyncTokenCredential
@@ -85,8 +85,8 @@ class EmbeddingsClientConfiguration: # pylint: disable=too-many-instance-attrib
8585
8686
:param endpoint: Service host. Required.
8787
:type endpoint: str
88-
:param credential: Credential used to authenticate requests to the service. Is one of the
89-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
88+
:param credential: Credential used to authenticate requests to the service. Is either a key
89+
credential type or a token credential type. Required.
9090
:type credential: ~azure.core.credentials.AzureKeyCredential or
9191
~azure.core.credentials.AzureKeyCredential or
9292
~azure.core.credentials_async.AsyncTokenCredential
@@ -145,8 +145,8 @@ class ImageEmbeddingsClientConfiguration: # pylint: disable=too-many-instance-a
145145
146146
:param endpoint: Service host. Required.
147147
:type endpoint: str
148-
:param credential: Credential used to authenticate requests to the service. Is one of the
149-
following types: AzureKeyCredential, AzureKeyCredential, TokenCredential Required.
148+
:param credential: Credential used to authenticate requests to the service. Is either a key
149+
credential type or a token credential type. Required.
150150
:type credential: ~azure.core.credentials.AzureKeyCredential or
151151
~azure.core.credentials.AzureKeyCredential or
152152
~azure.core.credentials_async.AsyncTokenCredential

0 commit comments

Comments
 (0)