From cd1bdc1483343893fcff10f4fc4dab400700ec20 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Oct 2025 18:34:31 -0700 Subject: [PATCH] Python: Fix multimodal input sample: Document required environment variables and configuration options (#1088) * Initial plan * Update multimodal input sample to document required environment variables Co-authored-by: dmytrostruk <13853051+dmytrostruk@users.noreply.github.com> * Add examples showing how to pass deployment_name as parameter Co-authored-by: dmytrostruk <13853051+dmytrostruk@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dmytrostruk <13853051+dmytrostruk@users.noreply.github.com> --- .../multimodal_input/README.md | 47 ++++++++++++++----- .../multimodal_input/azure_chat_multimodal.py | 5 ++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/python/samples/getting_started/multimodal_input/README.md b/python/samples/getting_started/multimodal_input/README.md index e4690724d2..b4b99a58f7 100644 --- a/python/samples/getting_started/multimodal_input/README.md +++ b/python/samples/getting_started/multimodal_input/README.md @@ -16,21 +16,44 @@ This folder contains examples demonstrating how to send multimodal content (imag - **Description**: Shows how to send multimodal content to Azure OpenAI service - **Supported formats**: PNG/JPEG images, WAV/MP3 audio, PDF documents +## Environment Variables + +Set the following environment variables before running the examples: + +**For OpenAI:** +- `OPENAI_API_KEY`: Your OpenAI API key + +**For Azure OpenAI:** +- `AZURE_OPENAI_ENDPOINT`: Your Azure OpenAI endpoint +- `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME`: The name of your Azure OpenAI chat model deployment + +Optionally for Azure OpenAI: +- `AZURE_OPENAI_API_VERSION`: The API version to use (default is `2024-10-21`) +- `AZURE_OPENAI_API_KEY`: Your Azure OpenAI API key (if not using `AzureCliCredential`) + +**Note:** You can also provide configuration directly in code instead of using environment variables: +```python +# Example: Pass deployment_name directly +client = AzureOpenAIChatClient( + credential=AzureCliCredential(), + deployment_name="your-deployment-name", + endpoint="https://your-resource.openai.azure.com" +) +``` + +## Authentication + +The Azure example uses `AzureCliCredential` for authentication. Run `az login` in your terminal before running the example, or replace `AzureCliCredential` with your preferred authentication method (e.g., provide `api_key` parameter). + ## Running the Examples -1. Set your API keys: +```bash +# Run OpenAI example +python openai_chat_multimodal.py - ```bash - export OPENAI_API_KEY="your-openai-key" - export AZURE_OPENAI_API_KEY="your-azure-key" - export AZURE_OPENAI_ENDPOINT="your-azure-endpoint" - ``` - -2. Run an example: - ```bash - python openai_chat_client_multimodal.py - python azure_chat_client_multimodal.py - ``` +# Run Azure example (requires az login or API key) +python azure_chat_multimodal.py +``` ## Using Your Own Files diff --git a/python/samples/getting_started/multimodal_input/azure_chat_multimodal.py b/python/samples/getting_started/multimodal_input/azure_chat_multimodal.py index ec31d8176d..031ae09da2 100644 --- a/python/samples/getting_started/multimodal_input/azure_chat_multimodal.py +++ b/python/samples/getting_started/multimodal_input/azure_chat_multimodal.py @@ -11,6 +11,11 @@ from azure.identity import AzureCliCredential async def test_image() -> None: """Test image analysis with Azure.""" + # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred + # authentication option. Requires AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_CHAT_DEPLOYMENT_NAME + # environment variables to be set. + # Alternatively, you can pass deployment_name explicitly: + # client = AzureOpenAIChatClient(credential=AzureCliCredential(), deployment_name="your-deployment-name") client = AzureOpenAIChatClient(credential=AzureCliCredential()) # Fetch image from httpbin