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>
This commit is contained in:
Copilot
2025-10-01 18:34:31 -07:00
committed by GitHub
Unverified
parent 4f4890cf6a
commit cd1bdc1483
2 changed files with 40 additions and 12 deletions
@@ -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
@@ -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