Bitzu

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

Single choice

Which Python class from the azure-ai-projects package connects your code to a Foundry project?

  1. DefaultAzureCredential
  2. AIProjectClient
  3. PromptAgentDefinition
  4. 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.

Select all that apply

Which statements about the Foundry SDK quickstart pattern in Python are true?

  1. The project client is built from the project endpoint and a credential such as DefaultAzureCredential
  2. You must call a separate Azure OpenAI endpoint with AzureOpenAI()
  3. project.get_openai_client() returns a client that offers responses.create
  4. A monthly api-version string is required on every call
  5. 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

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.

Download on the App StoreGet it on Google Play

More AI-901 topics in this module