Skip to content

Commit 633ff37

Browse files
authored
Update Projects SDK samples to read .env file (#43465)
1 parent 5139b01 commit 633ff37

File tree

38 files changed

+263
-167
lines changed

38 files changed

+263
-167
lines changed
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
#
2-
# Environment variables that define secrets required for running tests.
2+
# Environment variables that define secrets required for running tests and samples.
33
#
44
# All values should be empty by default in this template.
55
#
66
# To run tests locally on your device:
7-
# 1. Rename the file to azure_ai_projects_tests.env
7+
# 1. Rename the file to `.env.template` to `.env`
88
# 2. Fill in the values for the environment variables below (do not commit these changes to the repository!)
9-
# 3. Run the test (`pytest`)
9+
# 3. Run the tests (`pytest`) or run samples in the `samples` folder
1010
#
1111

12+
# Used in samples
1213
# Project endpoint has the format:
1314
# `https://<your-ai-services-account-name>.services.ai.azure.com/api/projects/<your-project-name>`
15+
AZURE_AI_PROJECT_ENDPOINT=
16+
AZURE_AI_MODEL_DEPLOYMENT_NAME=
17+
18+
# Used in tests
1419
AZURE_AI_PROJECTS_TESTS_PROJECT_ENDPOINT=
1520

sdk/ai/azure-ai-projects/dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
../../core/azure-core
33
../../identity/azure-identity
44
aiohttp
5+
python-dotenv
56
azure.ai.inference
67
openai

sdk/ai/azure-ai-projects/samples/agents/sample_agents.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@
1515
1616
Before running the sample:
1717
18-
pip install azure-ai-projects azure-identity
18+
pip install azure-ai-projects azure-identity python-dotenv
1919
20-
Set this environment variables with your own values:
21-
1) PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the overview page of your
20+
Set these environment variables with your own values:
21+
1) AZURE_AI_PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the overview page of your
2222
Azure AI Foundry project.
23-
2) MODEL_DEPLOYMENT_NAME - The AI model deployment name, to be used by your Agent, as found
23+
2) AZURE_AI_MODEL_DEPLOYMENT_NAME - The AI model deployment name, to be used by your Agent, as found
2424
in your AI Foundry project.
2525
"""
2626

2727
import os
28+
from dotenv import load_dotenv
2829
from azure.identity import DefaultAzureCredential
2930
from azure.ai.projects import AIProjectClient
3031

31-
endpoint = os.environ["PROJECT_ENDPOINT"]
32-
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"]
32+
load_dotenv()
33+
34+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
35+
model_deployment_name = os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"]
3336

3437
with DefaultAzureCredential(exclude_interactive_browser_credential=False) as credential:
3538

sdk/ai/azure-ai-projects/samples/agents/sample_agents_async.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@
1515
1616
Before running the sample:
1717
18-
pip install azure-ai-projects azure-identity aiohttp
18+
pip install azure-ai-projects azure-identity aiohttp python-dotenv
1919
20-
Set this environment variables with your own values:
21-
1) PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the overview page of your
20+
Set these environment variables with your own values:
21+
1) AZURE_AI_PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the overview page of your
2222
Azure AI Foundry project.
23-
2) MODEL_DEPLOYMENT_NAME - The AI model deployment name, to be used by your Agent, as found
23+
2) AZURE_AI_MODEL_DEPLOYMENT_NAME - The AI model deployment name, to be used by your Agent, as found
2424
in your AI Foundry project.
2525
"""
2626

2727
import os, asyncio
28+
from dotenv import load_dotenv
2829
from azure.identity.aio import DefaultAzureCredential
2930
from azure.ai.projects.aio import AIProjectClient
3031

32+
load_dotenv()
33+
3134

3235
async def main() -> None:
3336

34-
endpoint = os.environ["PROJECT_ENDPOINT"]
35-
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"]
37+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
38+
model_deployment_name = os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"]
3639

3740
async with DefaultAzureCredential() as credential:
3841

sdk/ai/azure-ai-projects/samples/connections/sample_connections.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@
1414
1515
Before running the sample:
1616
17-
pip install azure-ai-projects azure-identity
17+
pip install azure-ai-projects azure-identity python-dotenv
1818
1919
Set these environment variables with your own values:
20-
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
20+
1) AZURE_AI_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
2121
Azure AI Foundry project.
2222
2) CONNECTION_NAME - The name of a connection, as found in the "Connected resources" tab
2323
in the Management Center of your AI Foundry project.
2424
"""
2525

2626
import os
27+
from dotenv import load_dotenv
2728
from azure.identity import DefaultAzureCredential
2829
from azure.ai.projects import AIProjectClient
2930
from azure.ai.projects.models import ConnectionType
3031

31-
endpoint = os.environ["PROJECT_ENDPOINT"]
32+
load_dotenv()
33+
34+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
3235
connection_name = os.environ["CONNECTION_NAME"]
3336

3437
with DefaultAzureCredential(exclude_interactive_browser_credential=False) as credential:

sdk/ai/azure-ai-projects/samples/connections/sample_connections_async.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,28 @@
1414
1515
Before running the sample:
1616
17-
pip install azure-ai-projects azure-identity aiohttp
17+
pip install azure-ai-projects azure-identity aiohttp python-dotenv
1818
1919
Set these environment variables with your own values:
20-
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
20+
1) AZURE_AI_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
2121
Azure AI Foundry project.
2222
2) CONNECTION_NAME - The name of a connection, as found in the "Connected resources" tab
2323
in the Management Center of your AI Foundry project.
2424
"""
2525

2626
import asyncio
2727
import os
28+
from dotenv import load_dotenv
2829
from azure.identity.aio import DefaultAzureCredential
2930
from azure.ai.projects.aio import AIProjectClient
3031
from azure.ai.projects.models import ConnectionType
3132

33+
load_dotenv()
34+
3235

3336
async def main() -> None:
3437

35-
endpoint = os.environ["PROJECT_ENDPOINT"]
38+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
3639
connection_name = os.environ["CONNECTION_NAME"]
3740

3841
async with DefaultAzureCredential() as credential:

sdk/ai/azure-ai-projects/samples/datasets/sample_datasets.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
1616
Before running the sample:
1717
18-
pip install azure-ai-projects azure-identity
18+
pip install azure-ai-projects azure-identity python-dotenv
1919
2020
Set these environment variables with your own values:
21-
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
21+
1) AZURE_AI_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
2222
Azure AI Foundry project.
2323
2) CONNECTION_NAME - Required. The name of the Azure Storage Account connection to use for uploading files.
2424
3) DATASET_NAME - Optional. The name of the Dataset to create and use in this sample.
@@ -29,11 +29,14 @@
2929

3030
import os
3131
import re
32+
from dotenv import load_dotenv
3233
from azure.identity import DefaultAzureCredential
3334
from azure.ai.projects import AIProjectClient
3435
from azure.ai.projects.models import DatasetVersion
3536

36-
endpoint = os.environ["PROJECT_ENDPOINT"]
37+
load_dotenv()
38+
39+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
3740
connection_name = os.environ["CONNECTION_NAME"]
3841
dataset_name = os.environ.get("DATASET_NAME", "dataset-test")
3942
dataset_version_1 = os.environ.get("DATASET_VERSION_1", "1.0")

sdk/ai/azure-ai-projects/samples/datasets/sample_datasets_async.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
1616
Before running the sample:
1717
18-
pip install azure-ai-projects azure-identity aiohttp
18+
pip install azure-ai-projects azure-identity aiohttp python-dotenv
1919
2020
Set these environment variables with your own values:
21-
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
21+
1) AZURE_AI_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
2222
Azure AI Foundry project.
2323
2) CONNECTION_NAME - Required. The name of the Azure Storage Account connection to use for uploading files.
2424
3) DATASET_NAME - Optional. The name of the Dataset to create and use in this sample.
@@ -30,10 +30,13 @@
3030
import asyncio
3131
import os
3232
import re
33+
from dotenv import load_dotenv
3334
from azure.identity.aio import DefaultAzureCredential
3435
from azure.ai.projects.aio import AIProjectClient
3536
from azure.ai.projects.models import DatasetVersion
3637

38+
load_dotenv()
39+
3740
# Construct the paths to the data folder and data file used in this sample
3841
script_dir = os.path.dirname(os.path.abspath(__file__))
3942
data_folder = os.environ.get("DATA_FOLDER", os.path.join(script_dir, "data_folder"))
@@ -42,7 +45,7 @@
4245

4346
async def main() -> None:
4447

45-
endpoint = os.environ["PROJECT_ENDPOINT"]
48+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
4649
connection_name = os.environ["CONNECTION_NAME"]
4750
dataset_name = os.environ.get("DATASET_NAME", "dataset-test")
4851
dataset_version_1 = os.environ.get("DATASET_VERSION_1", "1.0")

sdk/ai/azure-ai-projects/samples/datasets/sample_datasets_download.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
1717
Before running the sample:
1818
19-
pip install azure-ai-projects azure-identity
19+
pip install azure-ai-projects azure-identity python-dotenv
2020
2121
Set these environment variables with your own values:
22-
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
22+
1) AZURE_AI_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
2323
Azure AI Foundry project.
2424
2) CONNECTION_NAME - Required. The name of the Azure Storage Account connection to use for uploading files.
2525
3) DATASET_NAME - Optional. The name of the Dataset to create and use in this sample.
@@ -30,11 +30,14 @@
3030

3131
import os
3232
import re
33+
from dotenv import load_dotenv
3334
from azure.identity import DefaultAzureCredential
3435
from azure.ai.projects import AIProjectClient
3536
from azure.storage.blob import ContainerClient
3637

37-
endpoint = os.environ["PROJECT_ENDPOINT"]
38+
load_dotenv()
39+
40+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
3841
connection_name = os.environ["CONNECTION_NAME"]
3942
dataset_name = os.environ.get("DATASET_NAME", "dataset-test")
4043
dataset_version = os.environ.get("DATASET_VERSION", "1.0")

sdk/ai/azure-ai-projects/samples/deployments/sample_deployments.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@
1313
1414
Before running the sample:
1515
16-
pip install azure-ai-projects azure-identity
16+
pip install azure-ai-projects azure-identity python-dotenv
1717
1818
Set these environment variables with your own values:
19-
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
19+
1) AZURE_AI_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
2020
Azure AI Foundry project.
21-
2) MODEL_DEPLOYMENT_NAME - Required. The name of the deployment to retrieve.
21+
2) AZURE_AI_MODEL_DEPLOYMENT_NAME - Required. The name of the deployment to retrieve.
2222
3) MODEL_PUBLISHER - Optional. The publisher of the model to filter by.
2323
4) MODEL_NAME - Optional. The name of the model to filter by.
2424
"""
2525

2626
import os
27+
from dotenv import load_dotenv
2728
from azure.identity import DefaultAzureCredential
2829
from azure.ai.projects import AIProjectClient
2930
from azure.ai.projects.models import ModelDeployment
3031

31-
endpoint = os.environ["PROJECT_ENDPOINT"]
32-
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"]
32+
load_dotenv()
33+
34+
endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
35+
model_deployment_name = os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"]
3336
model_publisher = os.environ.get("MODEL_PUBLISHER", "Microsoft")
3437
model_name = os.environ.get("MODEL_NAME", "Phi-4")
3538

0 commit comments

Comments
 (0)