Skip to content

Commit

Permalink
Fix setting response format for Python Inference SDK, following beta.…
Browse files Browse the repository at this point in the history
…4 release
  • Loading branch information
dargilco committed Aug 28, 2024
1 parent 2226dcb commit e851d56
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 35 deletions.
8 changes: 5 additions & 3 deletions articles/ai-studio/how-to/deploy-models-cohere-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -244,7 +244,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand All @@ -256,13 +256,15 @@ Cohere Command chat models can create JSON outputs. Set `response_format` to `js


```python
from azure.ai.inference.models import ChatCompletionsResponseFormatJSON

response = client.complete(
messages=[
SystemMessage(content="You are a helpful assistant that always generate responses in JSON format, using."
" the following format: { ""answer"": ""response"" }."),
UserMessage(content="How many languages are in the world?"),
],
response_format={ "type": ChatCompletionsResponseFormat.JSON_OBJECT }
response_format=ChatCompletionsResponseFormatJSON()
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/how-to/deploy-models-jais.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -214,7 +214,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/how-to/deploy-models-llama.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -268,7 +268,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
8 changes: 5 additions & 3 deletions articles/ai-studio/how-to/deploy-models-mistral-nemo.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -222,7 +222,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand All @@ -234,13 +234,15 @@ Mistral Nemo chat model can create JSON outputs. Set `response_format` to `json_


```python
from azure.ai.inference.models import ChatCompletionsResponseFormatJSON

response = client.complete(
messages=[
SystemMessage(content="You are a helpful assistant that always generate responses in JSON format, using."
" the following format: { ""answer"": ""response"" }."),
UserMessage(content="How many languages are in the world?"),
],
response_format={ "type": ChatCompletionsResponseFormat.JSON_OBJECT }
response_format=ChatCompletionsResponseFormatJSON()
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/how-to/deploy-models-mistral-open.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -270,7 +270,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
8 changes: 5 additions & 3 deletions articles/ai-studio/how-to/deploy-models-mistral.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -252,7 +252,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand All @@ -264,13 +264,15 @@ Mistral premium chat models can create JSON outputs. Set `response_format` to `j


```python
from azure.ai.inference.models import ChatCompletionsResponseFormatJSON

response = client.complete(
messages=[
SystemMessage(content="You are a helpful assistant that always generate responses in JSON format, using."
" the following format: { ""answer"": ""response"" }."),
UserMessage(content="How many languages are in the world?"),
],
response_format={ "type": ChatCompletionsResponseFormat.JSON_OBJECT }
response_format=ChatCompletionsResponseFormatJSON()
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/how-to/deploy-models-phi-3-5-moe.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -232,7 +232,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/how-to/deploy-models-phi-3-5-vision.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -228,7 +228,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/how-to/deploy-models-phi-3-vision.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -228,7 +228,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/how-to/deploy-models-phi-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -269,7 +269,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/ai-studio/reference/reference-model-inference-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ The following example shows the response for a chat completion request indicatin

```python
import json
from azure.ai.inference.models import SystemMessage, UserMessage, ChatCompletionsResponseFormat
from azure.ai.inference.models import SystemMessage, UserMessage, ChatCompletionsResponseFormatJSON
from azure.core.exceptions import HttpResponseError

try:
Expand All @@ -327,7 +327,7 @@ try:
SystemMessage(content="You are a helpful assistant."),
UserMessage(content="How many languages are in the world?"),
],
response_format={ "type": ChatCompletionsResponseFormat.JSON_OBJECT }
response_format=ChatCompletionsResponseFormatJSON()
)
except HttpResponseError as ex:
if ex.status_code == 422:
Expand Down
4 changes: 2 additions & 2 deletions articles/machine-learning/how-to-deploy-models-phi-3-5-moe.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](reference-model-inference-api.md).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -232,7 +232,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](reference-model-inference-api.md).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -227,7 +227,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](reference-model-inference-api.md).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -226,7 +226,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/machine-learning/how-to-deploy-models-phi-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ print_stream(result)
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).

```python
from azure.ai.inference.models import ChatCompletionsResponseFormat
from azure.ai.inference.models import ChatCompletionsResponseFormatText

response = client.complete(
messages=[
Expand All @@ -270,7 +270,7 @@ response = client.complete(
stop=["<|endoftext|>"],
temperature=0,
top_p=1,
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
response_format=ChatCompletionsResponseFormatText(),
)
```

Expand Down
4 changes: 2 additions & 2 deletions articles/machine-learning/reference-model-inference-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ The following example shows the response for a chat completion request indicatin

```python
import json
from azure.ai.inference.models import SystemMessage, UserMessage, ChatCompletionsResponseFormat
from azure.ai.inference.models import SystemMessage, UserMessage, ChatCompletionsResponseFormatJSON
from azure.core.exceptions import HttpResponseError

try:
Expand All @@ -322,7 +322,7 @@ try:
SystemMessage(content="You are a helpful assistant."),
UserMessage(content="How many languages are in the world?"),
],
response_format={ "type": ChatCompletionsResponseFormat.JSON_OBJECT }
response_format=ChatCompletionsResponseFormatJSON()
)
except HttpResponseError as ex:
if ex.status_code == 422:
Expand Down

0 comments on commit e851d56

Please sign in to comment.