Skip to content

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

@wennycooper

Description

@wennycooper

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 <module>
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Auto-ResolveAuto resolve by botService AttentionThis issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions