Skip to content

Commit 74e41af

Browse files
committed
mockup outline for foundry quickstart
1 parent e92dace commit 74e41af

7 files changed

Lines changed: 189 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
## Install dependencies
3+
4+
- install azure CLI
5+
- pip install azure-ai-projects openai azure-identity
6+
-
7+
8+
## Create a project
9+
see: create_project.py
10+
11+
## Create a project client
12+
see: create_project.py
13+
14+
## Run a chat completion
15+
16+
see: quickstart.py
17+
18+
## Create and run an agent
19+
20+
see: quickstart.py
21+
22+
## Add file search to agent
23+
24+
see: quickstart.py
25+
26+
## Evaluate agent run
27+
28+
This will return scores for how good the agent performed on the task
29+
30+
see: quickstart.py

doc-samples/getting-started/csharp/quickstart.cs

Whitespace-only changes.

doc-samples/getting-started/java/quickstart.java

Whitespace-only changes.

doc-samples/getting-started/javascript/quickstart.js

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# source: https://github.com/Azure/agent-first-sdk/blob/main/tests/management_sdk/manage_ai_foundry.ipynb
2+
3+
# <create_project>
4+
from azure.identity import DefaultAzureCredential
5+
from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient
6+
import os
7+
import json
8+
9+
subscription_id = 'your-subscription-id'
10+
resource_group_name = 'your-resource-group-name'
11+
foundry_resource_name = 'your-foundry-resource-name'
12+
foundry_project_name = 'your-foundry-project-name'
13+
location = 'eastus'
14+
15+
# TODO: add code to create create a new resource group
16+
17+
client = CognitiveServicesManagementClient(
18+
subscription_id=subscription_id,
19+
credential=DefaultAzureCredential(),
20+
api_version="2025-04-01-preview"
21+
)
22+
23+
account = client.accounts.begin_create(
24+
resource_group_name=resource_group_name,
25+
account_name=foundry_resource_name,
26+
foundry_project_name=foundry_project_name,
27+
account={
28+
"location": location,
29+
"kind": "AIServices",
30+
"sku": {
31+
"name": "S0",
32+
},
33+
"identity": {
34+
"type": "SystemAssigned"
35+
},
36+
"properties": {
37+
"allowProjectManagement": True
38+
}
39+
}
40+
)
41+
42+
# TODO: code to do role assignment to give user project manager role on the account
43+
44+
# </create_project>
45+
46+
# <deploy_model>
47+
48+
# </deploy_model>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from dotenv import load_dotenv
2+
load_dotenv()
3+
4+
## - pre-reqs: install openai and azure-ai-projects packages
5+
## pip install openai azure-ai-projects azure-identity
6+
## - deploy a gpt-4o model
7+
8+
## <chat_completion>
9+
from azure.ai.projects import AIProjectClient
10+
from azure.identity import DefaultAzureCredential
11+
from azure.ai.projects import FileSearchTool
12+
13+
project = AIProjectClient(
14+
endpoint="https://your-foundry-resource-name.ai.azure.com/api/projects",
15+
credential=DefaultAzureCredential(),
16+
)
17+
18+
openai = project.inference.get_azure_openai_client(api_version="2024-06-01")
19+
response = openai.chat.completions.create(
20+
model="gpt-4o",
21+
messages=[
22+
{"role": "system", "content": "You are a helpful writing assistant"},
23+
{"role": "user", "content": "Write me a poem about flowers"},
24+
],
25+
)
26+
27+
print(response.choices[0].message.content)
28+
# </chat_completion>
29+
30+
# <create_and_run_agent>
31+
agent = project.agents.create_agent(
32+
model="gpt-4o"
33+
name="my-agent",
34+
instructions="You are a helpful writing assistant")
35+
36+
thread = project.agents.create_thread()
37+
message = agents_client.create_message(
38+
thread_id=thread.id,
39+
role="user",
40+
content="Write me a poem about flowers")
41+
42+
run = project.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id)
43+
if run.status == "failed":
44+
# Check if you got "Rate limit is exceeded.", then you want to get more quota
45+
print(f"Run failed: {run.last_error}")
46+
47+
# Get messages from the thread
48+
messages = project.agents.list_messages(thread_id=thread.id)
49+
50+
# Get the last message from the sender
51+
last_msg = messages.get_last_text_message_by_role("assistant")
52+
if last_msg:
53+
print(f"Last Message: {last_msg.text.value}")
54+
55+
# Delete the agent once done
56+
project.agents.delete_agent(agent.id)
57+
print("Deleted agent")
58+
# </create_and_run_agent>
59+
60+
61+
# <create_filesearch_agent>
62+
# Upload file and create vector store
63+
file = project.agents.upload_file(file_path="product_info_1.md", purpose="agents")
64+
vector_store = project.agents.create_vector_store_and_poll(file_ids=[file.id], name="my_vectorstore")
65+
66+
# Create file search tool and agent
67+
file_search = FileSearchTool(vector_store_ids=[vector_store.id])
68+
agent = project.agents.create_agent(
69+
model="gpt-4o",
70+
name="my-assistant",
71+
instructions="You are a helpful assistant and can search information from uploaded files",
72+
tools=file_search.definitions,
73+
tool_resources=file_search.resources,
74+
)
75+
76+
# Create thread and process user message
77+
thread = project.agents.create_thread()
78+
project.agents.create_message(thread_id=thread.id, role="user", content="Hello, what Contoso products do you know?")
79+
run = project.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id)
80+
81+
# Handle run status
82+
if run.status == "failed":
83+
print(f"Run failed: {run.last_error}")
84+
85+
# Cleanup resources
86+
project.agents.delete_vector_store(vector_store.id)
87+
project.agents.delete_file(file_id=file.id)
88+
project.agents.delete_agent(agent.id)
89+
90+
# Print thread messages
91+
for message in project.agents.list_messages(thread_id=thread.id).text_messages:
92+
print(message)
93+
# </create_filesearch_agent>
94+
95+
# <evaluate_agent_run>
96+
from azure.ai.projects import EvaluatorIds
97+
98+
result = project.evaluation.create_agent_evaluation(
99+
thread=thread.id,
100+
run=run.id,
101+
evaluators=[EvaluatorIds.AGENT_QUALITY_EVALUATOR])
102+
103+
# wait for evaluation to complete
104+
result.wait_for_completion()
105+
106+
# result
107+
print(result.output())
108+
# </evaluate_agent_run>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
openai
2+
azure-ai-projects
3+
azure-identity

0 commit comments

Comments
 (0)