Azure / Azure/azure-cli

Error in tutorial of Build a basic chat app in Python using Azure AI Foundry SDK

Open
#31,403 5 comments 1 reaction 0 assignees View on GitHub
Auto-Resolve bug customer-reported Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

Hi,

I follow the instruction to deploy a gpt-4o-mini model and run the chat.py
https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code?tabs=linux#build-your-chat-app

But I got following error:
```
root@localhost:/workspace/Build_a_basic_chat_app_in_Python_using_Azure_AI_Foundry_SDK# python3 chat.py
Traceback (most recent call last):
File "/workspace/Build_a_basic_chat_app_in_Python_using_Azure_AI_Foundry_SDK/chat.py", line 11, in
response = chat.complete(
File "/usr/local/lib/python3.10/dist-packages/azure/ai/inference/_patch.py", line 738, in complete
raise HttpResponseError(response=response)
azure.core.exceptions.HttpResponseError: (None) Invalid URL (POST /v1/chat/completions)
Code: None
Message: Invalid URL (POST /v1/chat/completions)

```
I've double confirmed the project-connection-string is CORRECT.
This is my chat.py. Please help to check what's wrong. Thanks you!

```
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential

project_connection_string = "MY_CONNECTION_STRING_IS_HERE"

project = AIProjectClient.from_connection_string(
conn_str=project_connection_string, credential=DefaultAzureCredential()
)

chat = project.inference.get_chat_completions_client()
response = chat.complete(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are an AI assistant that speaks like a techno punk rocker from 2350. Be cool but not too cool. Ya dig?",
},
{"role": "user", "content": "Hey, can you help me with my taxes? I'm a freelancer."},
],
)

print(response.choices[0].message.content)

```

### Related command

python3 chat.py

### Errors

root@localhost:/workspace/Build_a_basic_chat_app_in_Python_using_Azure_AI_Foundry_SDK# python3 chat.py
Traceback (most recent call last):
File "/workspace/Build_a_basic_chat_app_in_Python_using_Azure_AI_Foundry_SDK/chat.py", line 11, in
response = chat.complete(
File "/usr/local/lib/python3.10/dist-packages/azure/ai/inference/_patch.py", line 738, in complete
raise HttpResponseError(response=response)
azure.core.exceptions.HttpResponseError: (None) Invalid URL (POST /v1/chat/completions)
Code: None
Message: Invalid URL (POST /v1/chat/completions)

### Issue script & Debug output

from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential

project_connection_string = "MY_CONNECTION_STRING_IS_HERE"

project = AIProjectClient.from_connection_string(
conn_str=project_connection_string, credential=DefaultAzureCredential()
)

chat = project.inference.get_chat_completions_client()
response = chat.complete(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are an AI assistant that speaks like a techno punk rocker from 2350. Be cool but not too cool. Ya dig?",
},
{"role": "user", "content": "Hey, can you help me with my taxes? I'm a freelancer."},
],
)

print(response.choices[0].message.content)

### Expected behavior

expected to see the chat completion response

### Environment Summary

azure-cli 2.71.0

core 2.71.0
telemetry 1.1.0

Dependencies:
msal 1.31.2b1
azure-mgmt-resource 23.1.1

Python location '/usr/bin/python'
Config directory '/root/.azure'
Extensions directory '/root/.azure/cliextensions'

Python (Linux) 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.