Skip to content

Commit fd5c77b

Browse files
authored
Add sample code for chat app in hub-get-started guide
1 parent 38d85fd commit fd5c77b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

articles/ai-foundry/quickstarts/hub-get-started-code.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,28 @@ pip install azure-ai-inference azure-identity azure-ai-projects==1.0.0b10
4545

4646
Create chat.py with sample code:
4747
```python
48-
# minimal outline referencing deployed model
49-
# (Full sample in azureai-samples repository path scenarios/projects/basic/chat-simple.py)
48+
from azure.ai.projects import AIProjectClient
49+
from azure.identity import DefaultAzureCredential
50+
51+
project_connection_string = "<your-connection-string-goes-here>"
52+
53+
project = AIProjectClient.from_connection_string(
54+
conn_str=project_connection_string, credential=DefaultAzureCredential()
55+
)
56+
57+
chat = project.inference.get_chat_completions_client()
58+
response = chat.complete(
59+
model="gpt-4o-mini",
60+
messages=[
61+
{
62+
"role": "system",
63+
"content": "You are an AI assistant that speaks like a techno punk rocker from 2350. Be cool but not too cool. Ya dig?",
64+
},
65+
{"role": "user", "content": "Hey, can you help me with my taxes? I'm a freelancer."},
66+
],
67+
)
68+
69+
print(response.choices[0].message.content)
5070
```
5171

5272
Insert your project connection string from the project Overview page (copy, replace placeholder in code).

0 commit comments

Comments
 (0)