AI-901 ยท Generative AI apps in Foundry
Chat client with the Foundry SDK (Python)
Reading and writing lightweight Python that creates a project client, gets a chat or responses client, sends messages with roles and prints the reply; streaming and conversation history.
Key points
- pip install azure-ai-projects azure-identity.
- Create AIProjectClient(endpoint=<project endpoint>, credential=DefaultAzureCredential()), call project.get_openai_client(), then openai.responses.create(model=<deployment>, input=...) and print response.output_text.
- Add instructions= for system-level behavior, stream=True for streaming, and previous_response_id (or a conversation) to keep history.
Source: https://learn.microsoft.com/en-us/azure/foundry/quickstarts/get-started-code
Practice questions
Which Python class from the azure-ai-projects package connects your code to a Foundry project?
- DefaultAzureCredential
- AIProjectClient
- PromptAgentDefinition
- ProjectEndpoint
Show answer
Answer: B. AIProjectClient
AIProjectClient takes the project endpoint and a credential. DefaultAzureCredential only supplies identity, and the other names are not the project client.
Which statements about the Foundry SDK quickstart pattern in Python are true?
- The project client is built from the project endpoint and a credential such as DefaultAzureCredential
- You must call a separate Azure OpenAI endpoint with AzureOpenAI()
- project.get_openai_client() returns a client that offers responses.create
- A monthly api-version string is required on every call
- response.output_text holds the model's text reply
Show answer
Answer: A. The project client is built from the project endpoint and a credential such as DefaultAzureCredential, C. project.get_openai_client() returns a client that offers responses.create, E. response.output_text holds the model's text reply
The project client uses the project endpoint and DefaultAzureCredential, and get_openai_client() returns an OpenAI-style client for calls such as responses.create. It does not require a separate AzureOpenAI endpoint or monthly api-version values.
True or false: Setting stream=True makes responses.create return the whole reply as one string in a single step.
Show answer
Answer: False
False. With streaming you receive a sequence of events (for example text deltas) and print each piece as it arrives.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
