Azure foundry client code for using response API

OpenAI Respose API is supported by the framework and we can easily use the following code to call it. 




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

project_client = AIProjectClient(
    endpoint="https://<your-resource>.services.ai.azure.com/api/projects/<your-project>",
    credential=DefaultAzureCredential()
)

# Get an OpenAI-compatible client scoped to this project
openai_client = project_client.get_openai_client()

# First turn
response = openai_client.responses.create(
    model="gpt-4o",  # your deployment name
    input="What's the speed of light?"
)
print(response.output_text)

# Next turn — chain via previous_response_id, just send the new input
response2 = openai_client.responses.create(
    model="gpt-4o",
    input="And what about sound?",
    previous_response_id=response.id
)
print(response2.output_text)









Comments

Popular posts from this blog

mongosh install properly

gemini cli getting file not defined error

vllm : Failed to infer device type