### Install C# NuGet Packages for Azure AI Services Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Installs required NuGet packages for .NET projects to integrate with Azure AI services, enabling functionalities like model deployment and interaction within C# applications. ```bash dotnet add package Azure.AI.OpenAI dotnet add package Azure.Core ``` -------------------------------- ### Install Azure AI Foundry Packages (Bash) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/hub-get-started-code Installs necessary Python packages for interacting with Azure AI services, including inference and project management. Ensure you have Python and Azure CLI installed. This command installs specific versions; isolate environments for different projects to prevent conflicts. ```bash pip install azure-ai-inference azure-identity azure-ai-projects==1.0.0b10 ``` -------------------------------- ### Install Python Packages for Azure AI Foundry Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Installs the necessary Python libraries for interacting with Azure AI Foundry projects, including the OpenAI client, project management, and identity authentication. ```python pip install openai azure-ai-projects azure-identity ``` -------------------------------- ### Install C# NuGet Packages for Azure AI Services Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Installs required .NET NuGet packages for integrating Azure AI services into your C# projects. This command is executed using the .NET CLI. ```bash dotnet add package Azure.AI.OpenAI dotnet add package Azure.Identity ``` -------------------------------- ### .NET Project Setup and Package Installation Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/text-to-speech-quickstart Commands to set up a new .NET console application, install the Azure OpenAI .NET client library, and the Azure Identity package for authentication. ```shell mkdir to-speech-quickstart && cd to-speech-quickstart ``` ```shell dotnet new console ``` ```csharp dotnet add package Azure.AI.OpenAI ``` ```csharp dotnet add package Azure.Identity ``` ```shell az login ``` -------------------------------- ### Install Foundry Local via CLI (Windows) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/foundry-local/get-started This command installs Foundry Local on Windows using the Windows Package Manager (winget). Ensure you have winget installed and administrator privileges. ```Bash winget install Microsoft.FoundryLocal ``` -------------------------------- ### Create Agent Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Creates a new AI agent with specified model, name, and instructions. ```APIDOC ## POST /api/projects/{projectName}/assistants ### Description Creates a new AI agent within a specified project. Agents are the core conversational entities. ### Method POST ### Endpoint /api/projects/{projectName}/assistants?api-version=v1 ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. #### Request Body - **model** (string) - Required - The name or ID of the AI model to use for the agent. - **name** (string) - Required - The name of the agent. - **instructions** (string) - Optional - Initial instructions or system prompt for the agent. ### Request Example ```json { "model": "gpt-4o", "name": "my-agent", "instructions": "You are a helpful writing assistant" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created agent. - **name** (string) - The name of the agent. - **model** (string) - The model used by the agent. #### Response Example ```json { "id": "asst_123456789", "name": "my-agent", "model": "gpt-4o" } ``` ``` -------------------------------- ### Build a Chat App with Azure AI Foundry (Python) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/hub-get-started-code Creates a Python script to instantiate an AI project client, get a chat completions client, and send a message to a deployed model (gpt-4o-mini). Requires a project connection string and the `azure-ai-projects` and `azure-identity` libraries. Outputs the model's response. ```python from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential project_connection_string = "" 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) ``` -------------------------------- ### Create Project Directory Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/use-your-data-quickstart_pivots=programming-language-studio Creates a new directory for the project and navigates into it. This is the initial setup step for the quickstart. ```shell mkdir use-data-quickstart && cd use-data-quickstart ``` -------------------------------- ### Create and Navigate Directory for Audio Completions Quickstart Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/audio-completions-quickstart_source=recommendations&tabs=keyless%2Clinux%2Ctypescript-keyless This command sequence creates a new directory named `audio-completions-quickstart` and then navigates into it. This is the initial setup step for a new project. ```shell mkdir audio-completions-quickstart && cd audio-completions-quickstart ``` -------------------------------- ### Create and Navigate Project Directory Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/realtime-audio-quickstart_source=recommendations&tabs=keyless%2Clinux Creates a new directory for the real-time audio quickstart project and changes the current directory into it. This is the first step in setting up the project environment. ```shell mkdir realtime-audio-quickstart && cd realtime-audio-quickstart ``` -------------------------------- ### Create Directory and Navigate Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/use-your-data-quickstart_pivots=ai-foundry-portal&source=recommendations&tabs=keyless%2Ctypescript-keyless%2Cpython-new This command creates a new directory named 'use-data-quickstart' and then navigates into it. It's a standard setup step for new projects. ```shell mkdir use-data-quickstart && cd use-data-quickstart ``` -------------------------------- ### Run Go Quickstart Sample Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/dall-e-quickstart_source=recommendations&tabs=command-line%2Cgpt-image-1%2Ckeyless%2Ctypescript-keyless Executes the Go quickstart application. This command compiles and runs the `quickstart.go` file, performing the image generation task as defined in the code. ```shell go run quickstart.go ``` -------------------------------- ### Chat Completions API Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations This section details how to send chat completion requests to the Azure AI Foundry service. It covers authentication methods, endpoint construction, and request/response examples. ```APIDOC ## POST /openai/deployments/{deployment-name}/chat/completions ### Description Sends a chat completion request to the specified deployment within Azure AI Foundry. ### Method POST ### Endpoint `/openai/deployments/{deployment-name}/chat/completions?api-version=2024-10-21` ### Parameters #### Path Parameters - **deployment-name** (string) - Required - The name of the deployment to use for the chat completion. #### Query Parameters - **api-version** (string) - Required - Specifies the API version to use, e.g., `2024-10-21`. #### Request Body - **messages** (array) - Required - An array of message objects, each with a `role` (system, user, or assistant) and `content`. - **model** (string) - Optional - The model to use for the chat completion. If not provided, it may default based on the deployment. ### Request Example ```json { "messages": [ {"role": "system", "content": "You are a helpful writing assistant"}, {"role": "user", "content": "Write me a poem about flowers"} ], "model": "gpt-4o" } ``` ### Response #### Success Response (200) - **choices** (array) - Contains the model's response(s). - **message** (object) - The message content from the model. - **content** (string) - The actual text response from the AI. #### Response Example ```json { "choices": [ { "message": { "role": "assistant", "content": "Here is a poem about flowers..." } } ] } ``` ### Error Handling - **401/403**: Authentication failed. Check API key or Azure credentials. - **404**: Deployment not found. Verify deployment name and endpoint. - **429**: Rate limit exceeded. Please retry later. ``` -------------------------------- ### Install Foundry Local via CLI (macOS) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/foundry-local/get-started This command installs Foundry Local on macOS using Homebrew. It first adds the Microsoft foundrylocal tap and then installs the foundrylocal package. Ensure Homebrew is installed. ```Bash brew tap microsoft/foundrylocal brew install foundrylocal ``` -------------------------------- ### Create Project Directory and Navigate Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/realtime-audio-quickstart_source=recommendations Creates a new directory for the project and changes the current directory into it. This is a standard setup step for new projects. ```shell mkdir realtime-audio-quickstart && cd realtime-audio-quickstart ``` -------------------------------- ### Full Quickstart: Image Description with Azure OpenAI (C#) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/gpt-v-quickstart_source=recommendations A comprehensive C# code example for the quickstart, demonstrating keyless authentication, setting up a chat client, defining multimodal messages with text and image parts, and generating a chat completion to describe an image. It requires setting environment variables or placeholders for endpoint and key. ```csharp using Azure; using Azure.AI.OpenAI; using Azure.Identity; using OpenAI.Chat; // Required for Passwordless auth string deploymentName = "gpt-4"; string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? "https://.openai.azure.com/"; string key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? ""; // Use the recommended keyless credential instead of the AzureKeyCredential credential. AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential()); //AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(key)); var chatClient = openAIClient.GetChatClient(deploymentName); var imageUrl = "YOUR_IMAGE_URL"; var textPart = ChatMessageContentPart.CreateTextPart("Describe this picture:"); var imgPart = ChatMessageContentPart.CreateImagePart(imageUrl); var chatMessages = new List { new SystemChatMessage("You are a helpful assistant."), new UserChatMessage(textPart, imgPart) }; ChatCompletion chatCompletion = await chatClient.CompleteChatAsync(chatMessages); Console.WriteLine("[ASSISTANT]:"); Console.WriteLine($"{chatCompletion.Content[0].Text}"); ``` -------------------------------- ### GET /api/projects/{projectName}/threads/{threadId}/messages Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Lists all messages within a specified thread using the thread ID. ```APIDOC ## GET /api/projects/{projectName}/threads/{threadId}/messages ### Description Lists all messages within a specified thread using the thread ID. ### Method GET ### Endpoint `https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/threads/thread_123456789/messages?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread to list messages from. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. #### Request Body (Not applicable for GET requests) ### Request Example (No request body for GET requests) ### Response #### Success Response (200) (Response details not provided in the source text) #### Response Example (Response example not provided in the source text) ``` -------------------------------- ### Run Go Sample Application Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/use-your-data-quickstart This command executes the Go sample application after dependencies have been installed. It runs the `quickstart.go` file, which utilizes the Azure OpenAI SDK to interact with the chat completions API. ```shell go run quickstart.go ``` -------------------------------- ### Delete Agent Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Removes an agent from the project. This action is irreversible. ```APIDOC ## DELETE /api/projects/{projectName}/assistants/{agentId} ### Description Deletes an agent from the specified project. ### Method DELETE ### Endpoint `https://.services.ai.azure.com/api/projects/{projectName}/assistants/{agentId}?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **agentId** (string) - Required - The ID of the agent to delete. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the agent was deleted. #### Response Example ```json { "message": "Agent asst_123456789 deleted successfully." } ``` ``` -------------------------------- ### Initialize Go Module and Install Dependencies Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/use-your-data-quickstart_pivots=ai-foundry-portal&source=recommendations&tabs=keyless%2Ctypescript-keyless%2Cpython-new These commands are used to set up a new Go project and fetch its dependencies. `go mod init` creates a new Go module in the current directory, defining the project's module path. `go mod tidy` then analyzes the source code, identifies the necessary external packages, and downloads them, ensuring all required dependencies are available. ```shell go mod init quickstart.go go mod tidy ``` -------------------------------- ### List Messages Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Retrieves all messages within a specific conversation thread. ```APIDOC ## GET /api/projects/{projectName}/threads/{threadId}/messages ### Description Retrieves a list of all messages in a specified conversation thread. ### Method GET ### Endpoint `https://.services.ai.azure.com/api/projects/{projectName}/threads/{threadId}/messages?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread whose messages are to be listed. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. ### Response #### Success Response (200) - **data** (array) - An array of message objects. - **id** (string) - The unique identifier of the message. - **threadId** (string) - The ID of the thread the message belongs to. - **role** (string) - The role of the message sender. - **content** (string) - The content of the message. #### Response Example ```json { "data": [ { "id": "msg_abcdef123456", "threadId": "thread_123456789", "role": "user", "content": "Write me a poem about flowers" }, { "id": "msg_ghijkl789012", "threadId": "thread_123456789", "role": "assistant", "content": "Here is a poem about flowers..." } ] } ``` ``` -------------------------------- ### Create and Navigate to Project Directory Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/gpt-v-quickstart Creates a new directory named `vision-quickstart` and then changes the current directory to the newly created folder. This is the first step in setting up the project environment. ```shell mkdir vision-quickstart && cd vision-quickstart ``` -------------------------------- ### Complete Azure OpenAI Quickstart with API Key and Azure AI Search (Go) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/use-your-data-quickstart_pivots=programming-language-studio This Go program demonstrates how to run the Azure OpenAI quickstart using an API key for authentication and integrating with Azure AI Search. It requires environment variables for API keys, endpoints, and deployment names. The code initializes the client, sets up the search extension, and makes a chat completion request. ```go package main import ( "context" "fmt" "log" "os" "github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" ) func main() { azureOpenAIEndpoint := os.Getenv("AZURE_OPENAI_ENDPOINT") azureOpenAIKey := os.Getenv("AZURE_OPENAI_API_KEY") modelDeploymentID := os.Getenv("AZURE_OPENAI_DEPLOYMENT_NAME") // Azure AI Search configuration searchIndex := os.Getenv("AZURE_AI_SEARCH_INDEX") searchEndpoint := os.Getenv("AZURE_AI_SEARCH_ENDPOINT") searchAPIKey := os.Getenv("AZURE_AI_SEARCH_API_KEY") if azureOpenAIKey == "" || modelDeploymentID == "" || azureOpenAIEndpoint == "" || searchIndex == "" || searchEndpoint == "" || searchAPIKey == "" { fmt.Fprintf(os.Stderr, "Skipping example, environment variables missing\n") return } credential := azcore.NewKeyCredential(azureOpenAIKey) client, err := azopenai.NewClientWithKeyCredential(azureOpenAIEndpoint, credential, nil) if err != nil { // Implement application specific error handling logic. log.Printf("ERROR: %s", err) return } ``` -------------------------------- ### Create Message Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Adds a user message to an existing conversation thread. ```APIDOC ## POST /api/projects/{projectName}/threads/{threadId}/messages ### Description Adds a user message to a specified conversation thread. ### Method POST ### Endpoint `https://.services.ai.azure.com/api/projects/{projectName}/threads/{threadId}/messages?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread to add the message to. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. #### Request Body - **role** (string) - Required - The role of the message sender (e.g., `user`). - **content** (string) - Required - The content of the message. ### Request Example ```json { "role": "user", "content": "Write me a poem about flowers" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created message. - **threadId** (string) - The ID of the thread the message belongs to. - **role** (string) - The role of the message sender. - **content** (string) - The content of the message. #### Response Example ```json { "id": "msg_abcdef123456", "threadId": "thread_123456789", "role": "user", "content": "Write me a poem about flowers" } ``` ``` -------------------------------- ### Delete Agent Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Deletes an AI agent and all its associated resources. ```APIDOC ## DELETE /api/projects/{projectName}/assistants/{assistantId} ### Description Removes an AI agent from the project. This action is irreversible. ### Method DELETE ### Endpoint /api/projects/{projectName}/assistants/{assistantId}?api-version=v1 ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **assistantId** (string) - Required - The ID of the agent to delete. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. #### Request Body (None) ### Request Example (None) ### Response #### Success Response (200) (No content, typically returns an empty body or a confirmation message) #### Response Example (Empty body or a simple success confirmation) ``` -------------------------------- ### Initialize Go Module Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/dall-e-quickstart_source=recommendations&tabs=command-line%2Cgpt-image-1%2Ckeyless%2Ctypescript-keyless Initializes a new Go module for the quickstart project. This command is necessary to manage dependencies and structure the project correctly. ```shell go mod init quickstart.go ``` -------------------------------- ### GET /api/projects/{projectName}/threads/{threadId}/messages Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Retrieves a list of messages within a specified thread. This allows for reviewing the conversation history. ```APIDOC ## GET /api/projects/{projectName}/threads/{threadId}/messages ### Description Lists the messages in a thread using the thread ID. ### Method GET ### Endpoint `https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/threads/thread_123456789/messages?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread to retrieve messages from. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. ### Request Example (No request body for GET requests) ### Response #### Success Response (200) - **messages** (array) - A list of message objects. - **id** (string) - The ID of the message. - **thread_id** (string) - The ID of the thread the message belongs to. - **role** (string) - The role of the sender (e.g., 'user', 'assistant'). - **content** (string) - The content of the message. - **created_at** (integer) - Timestamp of message creation. #### Response Example ```json { "messages": [ { "id": "msg_xyz789", "thread_id": "thread_123456789", "role": "user", "content": "Hello, how are you?", "created_at": 1678886400 }, { "id": "msg_abc123", "thread_id": "thread_123456789", "role": "assistant", "content": "I am doing well, thank you!", "created_at": 1678886460 } ] } ``` ``` -------------------------------- ### Create Sample Markdown Document (Java) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations This Java method creates a temporary markdown file with cloud computing information. It utilizes `Files.createTempFile` and `Files.writeString` to write content and logs the file creation process. This serves as a practical example for generating documents to be used with AI agents. ```java /** * Creates a sample markdown document with cloud computing information. * * This method demonstrates: * - Creating a temporary file that will be automatically deleted when the JVM exits * - Writing structured markdown content to the file * - Logging file creation and preview of content * * In a real application, you might read existing files or create more complex documents. * You could also upload them to a document storage service for persistent access. * * @return Path to the created temporary file * @throws IOException if an I/O error occurs during file creation or writing */ private static Path createSampleDocument() throws IOException { logger.info("Creating sample document"); String content = """ # Cloud Computing Overview Cloud computing is the delivery of computing services over the internet, including servers, storage, databases, networking, software, analytics, and intelligence. Cloud services offer faster innovation, flexible resources, and economies of scale. ## Key Cloud Service Models 1. **Infrastructure as a Service (IaaS)** - Provides virtualized computing resources 2. **Platform as a Service (PaaS)** - Provides hardware and software tools over the internet 3. **Software as a Service (SaaS)** - Delivers software applications over the internet ## Major Cloud Providers - Microsoft Azure - Amazon Web Services (AWS) - Google Cloud Platform (GCP) - IBM Cloud ## Benefits of Cloud Computing - Cost efficiency - Scalability - Reliability - Performance - Security """; Path tempFile = Files.createTempFile("cloud-doc", ".md"); Files.writeString(tempFile, content); logger.info("Sample document created at: {}", tempFile); return tempFile; } } ``` -------------------------------- ### Create Image Generation Directory and Setup npm Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/dall-e-quickstart_source=recommendations&tabs=command-line%2Cgpt-image-1%2Ckeyless%2Ctypescript-keyless These commands set up a new directory for the image generation quickstart and initialize a Node.js project using npm. This is the initial step for the JavaScript implementation. ```shell mkdir image-quickstart && cd image-quickstart npm init -y ``` -------------------------------- ### Create and Navigate Directory Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/gpt-v-quickstart Creates a new directory named 'vision-quickstart' and changes the current directory to it. This is the initial step for setting up a new project. ```shell mkdir vision-quickstart && cd vision-quickstart ``` -------------------------------- ### List Messages Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Retrieves all messages within a specific conversation thread. ```APIDOC ## GET /api/projects/{projectName}/threads/{threadId}/messages ### Description Fetches a list of all messages exchanged in a given thread, ordered chronologically. ### Method GET ### Endpoint /api/projects/{projectName}/threads/{threadId}/messages?api-version=v1 ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread to list messages from. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. ### Request Example (None) ### Response #### Success Response (200) - **data** (array) - A list of message objects. - **id** (string) - The message ID. - **thread_id** (string) - The thread ID. - **role** (string) - The role of the sender. - **content** (string) - The message content. #### Response Example ```json { "data": [ { "id": "msg_abcdef12345", "thread_id": "thread_123456789", "role": "user", "content": "Write me a poem about flowers" }, { "id": "msg_ghijkl67890", "thread_id": "thread_123456789", "role": "assistant", "content": "Here is a poem about flowers..." } ] } ``` ``` -------------------------------- ### Create Message Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Adds a user message to a specific conversation thread. ```APIDOC ## POST /api/projects/{projectName}/threads/{threadId}/messages ### Description Appends a message to an existing conversation thread. This allows users to send input to the agent. ### Method POST ### Endpoint /api/projects/{projectName}/threads/{threadId}/messages?api-version=v1 ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread to add the message to. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. #### Request Body - **role** (string) - Required - The role of the message sender (e.g., 'user'). - **content** (string) - Required - The actual content of the message. ### Request Example ```json { "role": "user", "content": "Write me a poem about flowers" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created message. - **thread_id** (string) - The ID of the thread the message belongs to. - **role** (string) - The role of the message sender. - **content** (string) - The content of the message. #### Response Example ```json { "id": "msg_abcdef12345", "thread_id": "thread_123456789", "role": "user", "content": "Write me a poem about flowers" } ``` ``` -------------------------------- ### Create and Navigate to Directory (Shell) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/dall-e-quickstart This command creates a new directory named 'dall-e-quickstart' and then navigates into that directory. It's the first step in setting up a new project for the quickstart. ```shell mkdir dall-e-quickstart && cd dall-e-quickstart ``` -------------------------------- ### Create Thread Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_source=recommendations Creates a new conversation thread for user interactions with an agent. ```APIDOC ## POST /api/projects/{projectName}/threads ### Description Initializes a new conversation thread. Threads store the history of messages between a user and an agent. ### Method POST ### Endpoint /api/projects/{projectName}/threads?api-version=v1 ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. #### Request Body (None) ### Request Example (None) ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created thread. #### Response Example ```json { "id": "thread_123456789" } ``` ``` -------------------------------- ### Setup Virtual Environment and Install Azure AI Projects (Console) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/deep-research-samples_pivots=csharp These console commands guide the user through setting up a Python virtual environment and installing the necessary prerelease version of the `azure-ai-projects` library. This is a prerequisite for using the Deep Research tool. ```bash # after creating the virtual environment, activate it with: # Windows # .\env\Scripts\activate # macOS/Linux # source env/bin/activate python -m venv env # after creating the virtual environment, activate it with: # .envScriptsactivate pip install --pre azure-ai-projects ``` -------------------------------- ### .NET Project Setup for Azure OpenAI Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/text-to-speech-quickstart_source=recommendations Sets up a new .NET console application and installs necessary NuGet packages for interacting with Azure OpenAI services. Includes packages for OpenAI client library and Azure Identity for authentication. ```shell mkdir to-speech-quickstart && cd to-speech-quickstart dotnet new console dotnet add package Azure.AI.OpenAI dotnet add package Azure.Identity ``` -------------------------------- ### Create and navigate to a new project folder Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/text-to-speech-quickstart_source=recommendations&tabs=command-line%2Ckeyless%2Ctypescript-keyless Creates a new directory named `to-speech-quickstart` and then changes the current working directory to the newly created folder. This is a common step for starting a new project. ```shell mkdir to-speech-quickstart && cd to-speech-quickstart ``` -------------------------------- ### Run Thread Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Initiates a run of a thread with a specified agent. This is where the agent processes the messages in the thread. ```APIDOC ## POST /api/projects/{projectName}/threads/{threadId}/runs ### Description Starts a new run for a specified thread using a given agent. ### Method POST ### Endpoint `https://.services.ai.azure.com/api/projects/{projectName}/threads/{threadId}/runs?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread to run. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. #### Request Body - **assistant_id** (string) - Required - The ID of the agent to use for the run. ### Request Example ```json { "assistant_id": "asst_123456789" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the run. - **threadId** (string) - The ID of the thread associated with the run. - **assistantId** (string) - The ID of the agent used for the run. - **status** (string) - The current status of the run (e.g., `queued`, `in_progress`, `completed`). #### Response Example ```json { "id": "run_abcdef123456", "threadId": "thread_123456789", "assistantId": "asst_123456789", "status": "queued" } ``` ``` -------------------------------- ### Create Project Directory and Initialize npm Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/realtime-audio-quickstart_source=recommendations&tabs=keyless%2Clinux These commands set up a new project directory and initialize npm for managing project dependencies. They are essential for starting any Node.js based project. ```shell mkdir realtime-audio-quickstart && cd realtime-audio-quickstart ``` ```shell npm init -y ``` -------------------------------- ### Create Thread Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Initializes a new conversation thread. Threads are used to maintain context for agent interactions. ```APIDOC ## POST /api/projects/{projectName}/threads ### Description Creates a new conversation thread within the specified project. ### Method POST ### Endpoint `https://.services.ai.azure.com/api/projects/{projectName}/threads?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. #### Request Body None ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created thread. #### Response Example ```json { "id": "thread_123456789" } ``` ``` -------------------------------- ### Create and Navigate Directory for DALL-E Quickstart Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/dall-e-quickstart_tabs=command-line%2Cgpt-image-1%2Ckeyless%2Ctypescript-keyless This command creates a new directory named 'dall-e-quickstart' and then changes the current directory to it. This is the initial step to organize the project files for the quickstart. ```shell mkdir dall-e-quickstart && cd dall-e-quickstart ``` -------------------------------- ### Create Project Directory and Navigate Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/text-to-speech-quickstart This command creates a new directory for the project and then changes the current directory into the newly created one. This is a standard first step for initializing a new project. ```shell mkdir synthesis-quickstart && cd synthesis-quickstart ``` -------------------------------- ### Thread Creation API Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Creates a new conversation thread. Threads are used to manage the history of interactions with an assistant. ```APIDOC ## POST /api/projects/{projectName}/threads ### Description Creates a new conversation thread. Threads are used to manage the history of interactions with an assistant. ### Method POST ### Endpoint `https://{yourFoundryResourceName}.services.ai.azure.com/api/projects/{projectName}/threads?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. #### Request Body - **authorization** (string) - Required - Bearer token for authentication. - **content-type** (string) - Required - `application/json`. ### Request Example ```bash curl --request POST --url 'https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/threads?api-version=v1' \ -h 'authorization: Bearer $AZURE_AI_AUTH_TOKEN' \ -h 'content-type: application/json' ``` ### Response #### Success Response (200) - **thread_id** (string) - The ID of the created thread. #### Response Example ```json { "thread_id": "thread_123456789" } ``` ``` -------------------------------- ### Create Project Directory and Navigate Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/video-generation-quickstart Creates a new directory for the video generation project and changes the current directory to it. This is a standard setup step for new projects. ```shell mkdir video-generation-quickstart && cd video-generation-quickstart ``` -------------------------------- ### DELETE /api/projects/{projectName}/assistants/{assistantId} Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Deletes an agent using its agent ID. Use this once the agent is no longer needed. ```APIDOC ## DELETE /api/projects/{projectName}/assistants/{assistantId} ### Description Deletes an agent using its agent ID. Use this once the agent is no longer needed. ### Method DELETE ### Endpoint `https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/assistants/asst_123456789?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **assistantId** (string) - Required - The ID of the assistant to delete. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. #### Request Body (Not applicable for DELETE requests) ### Request Example (No request body for DELETE requests) ### Response #### Success Response (200) (Response details not provided in the source text) #### Response Example (Response example not provided in the source text) ``` -------------------------------- ### Restart Foundry Local Service Source: https://learn.microsoft.com/en-us/azure/ai-foundry/foundry-local/get-started This command restarts the Foundry Local service. It is a troubleshooting step recommended if you encounter service connection errors after installation. ```Bash foundry service restart ``` -------------------------------- ### Full Quickstart: Azure OpenAI Chat with Your Data (Go) Source: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/use-your-data-quickstart_source=recommendations A comprehensive Go program demonstrating the setup and execution of Azure OpenAI chat with data retrieval from Azure AI Search. It handles both Microsoft Entra ID and API key authentication, requires several environment variables for configuration, and makes a chat completion request with integrated search extensions. ```go package main import ( "context" "fmt" "log" "os" "github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" ) func main() { azureOpenAIEndpoint := os.Getenv("AZURE_OPENAI_ENDPOINT") credential, err := azidentity.NewDefaultAzureCredential(nil) client, err := azopenai.NewClient(azureOpenAIEndpoint, credential, nil) modelDeploymentID := os.Getenv("AZURE_OPENAI_DEPLOYMENT_NAME") // Azure AI Search configuration searchIndex := os.Getenv("AZURE_AI_SEARCH_INDEX") searchEndpoint := os.Getenv("AZURE_AI_SEARCH_ENDPOINT") searchAPIKey := os.Getenv("AZURE_AI_SEARCH_API_KEY") if modelDeploymentID == "" || azureOpenAIEndpoint == "" || searchIndex == "" || searchEndpoint == "" || searchAPIKey == "" { fmt.Fprintf(os.Stderr, "Skipping example, environment variables missing\n") return } client, err := azopenai.NewClientWithKeyCredential(azureOpenAIEndpoint, credential, nil) if err != nil { // Implement application specific error handling logic. log.Printf("ERROR: %s", err) return } resp, err := client.GetChatCompletions(context.TODO(), azopenai.ChatCompletionsOptions{ Messages: []azopenai.ChatRequestMessageClassification{ &azopenai.ChatRequestUserMessage{Content: azopenai.NewChatRequestUserMessageContent("What are my available health plans?")}, }, MaxTokens: to.Ptr[int32](512), AzureExtensionsOptions: []azopenai.AzureChatExtensionConfigurationClassification{ &azopenai.AzureSearchChatExtensionConfiguration{ // This allows Azure OpenAI to use an Azure AI Search index. // Answers are based on the model's pretrained knowledge // and the latest information available in the designated data source. Parameters: &azopenai.AzureSearchChatExtensionParameters{ Endpoint: &searchEndpoint, IndexName: &searchIndex, Authentication: &azopenai.OnYourDataAPIKeyAuthenticationOptions{ Key: &searchAPIKey, }, }, }, }, DeploymentName: &modelDeploymentID, }, nil) if err != nil { // Implement application specific error handling logic. log.Printf("ERROR: %s", err) return } fmt.Fprintf(os.Stderr, "Extensions Context Role: %s\nExtensions Context (length): %d\n", *resp.Choices[0].Message.Role, len(*resp.Choices[0].Message.Content)) fmt.Fprintf(os.Stderr, "ChatRole: %s\nChat content: %s\n", *resp.Choices[0].Message.Role, *resp.Choices[0].Message.Content, ) } ``` -------------------------------- ### POST /api/projects/{projectName}/threads/{threadId}/runs Source: https://learn.microsoft.com/en-us/azure/ai-foundry/quickstarts/get-started-code_tabs=azure-ai-foundry Runs a thread with a specified agent. Requires both agent ID and thread ID. ```APIDOC ## POST /api/projects/{projectName}/threads/{threadId}/runs ### Description Runs a thread with a specified agent. Requires both agent ID and thread ID. ### Method POST ### Endpoint `https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/threads/thread_123456789/runs?api-version=v1` ### Parameters #### Path Parameters - **projectName** (string) - Required - The name of the project. - **threadId** (string) - Required - The ID of the thread to run. #### Query Parameters - **api-version** (string) - Required - The API version, e.g., `v1`. #### Request Body - **assistant_id** (string) - Required - The ID of the assistant to use for running the thread. ### Request Example ```json { "assistant_id": "asst_123456789" } ``` ### Response #### Success Response (200) (Response details not provided in the source text) #### Response Example (Response example not provided in the source text) ```