Python: Fix Azure AI Getting Started samples: Improve documentation and code readability (#1089)

* Initial plan

* Fix Azure AI samples: Add dotenv support, fix async input, improve docs

Co-authored-by: dmytrostruk <13853051+dmytrostruk@users.noreply.github.com>

* Remove dotenv.load_dotenv() and revert async input() changes per review feedback

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 20:22:44 -07:00
committed by GitHub
Unverified
parent cd1bdc1483
commit 07db91174b
4 changed files with 61 additions and 5 deletions
+2
View File
@@ -1,6 +1,8 @@
# Azure AI
AZURE_AI_PROJECT_ENDPOINT=""
AZURE_AI_MODEL_DEPLOYMENT_NAME=""
# Bing connection for web search (optional, used by samples with web search)
BING_CONNECTION_ID=""
# OpenAI
OPENAI_API_KEY=""
OPENAI_CHAT_MODEL_ID=""
@@ -22,7 +22,47 @@ This folder contains examples demonstrating different ways to create and use age
## Environment Variables
Make sure to set the following environment variables before running the examples:
Before running the examples, you need to set up your environment variables. You can do this in one of two ways:
- `AZURE_AI_PROJECT_ENDPOINT`: Your Azure AI project endpoint
- `AZURE_AI_MODEL_DEPLOYMENT_NAME`: The name of your model deployment
### Option 1: Using a .env file (Recommended)
1. Copy the `.env.example` file from the `python` directory to create a `.env` file:
```bash
cp ../../.env.example ../../.env
```
2. Edit the `.env` file and add your values:
```
AZURE_AI_PROJECT_ENDPOINT="your-project-endpoint"
AZURE_AI_MODEL_DEPLOYMENT_NAME="your-model-deployment-name"
```
3. For samples using Bing Grounding search (like `azure_ai_with_bing_grounding.py` and `azure_ai_with_multiple_tools.py`), you'll also need:
```
BING_CONNECTION_ID="/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.CognitiveServices/accounts/{ai-service-name}/projects/{project-name}/connections/{connection-name}"
```
To get your Bing connection ID:
- Go to [Azure AI Foundry portal](https://ai.azure.com)
- Navigate to your project's "Connected resources" section
- Add a new connection for "Grounding with Bing Search"
- Copy the connection ID
### Option 2: Using environment variables directly
Set the environment variables in your shell:
```bash
export AZURE_AI_PROJECT_ENDPOINT="your-project-endpoint"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="your-model-deployment-name"
export BING_CONNECTION_ID="your-bing-connection-id" # Optional, only needed for web search samples
```
### Required Variables
- `AZURE_AI_PROJECT_ENDPOINT`: Your Azure AI project endpoint (required for all examples)
- `AZURE_AI_MODEL_DEPLOYMENT_NAME`: The name of your model deployment (required for all examples)
### Optional Variables
- `BING_CONNECTION_ID`: Your Bing connection ID (required for `azure_ai_with_bing_grounding.py` and `azure_ai_with_multiple_tools.py`)
@@ -43,7 +43,9 @@ async def main() -> None:
):
agent = chat_client.create_agent(
name="CodingAgent",
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
instructions=(
"You are a helpful assistant that can write and execute Python code to solve problems."
),
tools=HostedCodeInterpreterTool(),
)
query = "Generate the factorial of 100 using python code, show the code and execute it."
@@ -18,6 +18,19 @@ Azure AI Agent with Multiple Tools Example
This sample demonstrates integrating multiple tools (MCP and Web Search) with Azure AI Agents,
including user approval workflows for function call security.
Prerequisites:
1. Set AZURE_AI_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME environment variables
2. For Bing search functionality, set BING_CONNECTION_ID environment variable to your Bing connection ID
Example: BING_CONNECTION_ID="/subscriptions/{subscription-id}/resourceGroups/{resource-group}/
providers/Microsoft.CognitiveServices/accounts/{ai-service-name}/projects/{project-name}/
connections/{connection-name}"
To set up Bing Grounding:
1. Go to Azure AI Foundry portal (https://ai.azure.com)
2. Navigate to your project's "Connected resources" section
3. Add a new connection for "Grounding with Bing Search"
4. Copy the connection ID and set it as the BING_CONNECTION_ID environment variable
"""
@@ -66,7 +79,6 @@ async def main() -> None:
name="Microsoft Learn MCP",
url="https://learn.microsoft.com/api/mcp",
),
# needs BING_CONNECTION_ID set in the env
HostedWebSearchTool(count=5),
get_time,
],