Skip to content

Commit 9acddc6

Browse files
committed
Updated Python SDK
1 parent bfa0ef4 commit 9acddc6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

learn-pr/wwl-data-ai/ai-foundry-sdk/includes/04-chat-client.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ When you have deployed models to the Azure AI model inference service, you can u
2121
The following Python code sample uses a **ChatCompletionsClient** object to chat with a model deployment named **phi-4-model**.
2222

2323
```python
24-
from azure.ai.projects import AIProjectClient
2524
from azure.identity import DefaultAzureCredential
2625
from azure.ai.inference.models import SystemMessage, UserMessage
2726

2827
try:
2928

30-
# Initialize the project client
31-
project_client = AIProjectClient(
32-
credential=DefaultAzureCredential(),
33-
endpoint=project_endpoint)
34-
3529
## Get a chat client
36-
chat_client = project_client.inference.get_chat_completions_client()
30+
inference_endpoint = f"https://{urlparse(project_endpoint).netloc}/models"
31+
32+
credential = DefaultAzureCredential()
33+
34+
chat_client = ChatCompletionsClient(
35+
endpoint=inference_endpoint,
36+
credential=credential,
37+
credential_scopes=["https://ai.azure.com/.default"])
3738

3839
# Get a chat completion based on a user-provided prompt
3940
user_prompt = input("Enter a question:")
@@ -52,7 +53,7 @@ except Exception as ex:
5253
```
5354

5455
> [!NOTE]
55-
> The **ChatCompletionsClient** class uses **Azure AI Inference** library. In addition to the **azure-ai-projects** and **azure-identity** packages discussed previously, the sample code shown here assumes that the **azure-ai-inference** package has been installed:
56+
> The **ChatCompletionsClient** class uses **Azure AI Inference** library. In addition to the **azure-identity** package discussed previously, the sample code shown here assumes that the **azure-ai-inference** package has been installed:
5657
>
5758
> `pip install azure-ai-inference`
5859

0 commit comments

Comments
 (0)