Skip to content

Commit 14f2d66

Browse files
authored
Add tests for tools and improve samples for interprise file search. (#42446)
* Create new tests for tools. * Fix
1 parent faeb63a commit 14f2d66

10 files changed

+751
-84
lines changed

sdk/ai/azure-ai-agents/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ else:
294294
ds = VectorStoreDataSource(asset_identifier=asset_uri, asset_type=VectorStoreDataSourceAssetType.URI_ASSET)
295295
vector_store = agents_client.vector_stores.create_and_poll(data_sources=[ds], name="sample_vector_store")
296296
print(f"Created vector store, vector store ID: {vector_store.id}")
297+
vector_store_files = {}
298+
for fle in agents_client.vector_store_files.list(vector_store.id):
299+
uploaded_file = agents_client.files.get(fle.id)
300+
vector_store_files[fle.id] = uploaded_file.filename
297301

298302
# Create a file search tool
299303
file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])

sdk/ai/azure-ai-agents/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ai/azure-ai-agents",
5-
"Tag": "python/ai/azure-ai-agents_e418bdd70b"
5+
"Tag": "python/ai/azure-ai-agents_ad0998d8d9"
66
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
../../identity/azure-identity
44
../../core/azure-core-tracing-opentelemetry
55
aiohttp
6+
jsonref
67
opentelemetry-sdk
78
opentelemetry-exporter-otlp-proto-grpc
89
azure-ai-ml

sdk/ai/azure-ai-agents/samples/agents_async/sample_agents_vector_store_enterprise_file_search_async.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
VectorStoreDataSource,
2929
VectorStoreDataSourceAssetType,
3030
ListSortOrder,
31-
MessageTextContent,
3231
)
3332
from azure.identity.aio import DefaultAzureCredential
3433

@@ -47,6 +46,10 @@ async def main():
4746
ds = VectorStoreDataSource(asset_identifier=asset_uri, asset_type=VectorStoreDataSourceAssetType.URI_ASSET)
4847
vector_store = await agents_client.vector_stores.create_and_poll(data_sources=[ds], name="sample_vector_store")
4948
print(f"Created vector store, vector store ID: {vector_store.id}")
49+
vector_store_files = {}
50+
async for fle in agents_client.vector_store_files.list(vector_store.id):
51+
uploaded_file = await agents_client.files.get(fle.id)
52+
vector_store_files[fle.id] = uploaded_file.filename
5053

5154
# Create a file search tool
5255
file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
@@ -80,9 +83,16 @@ async def main():
8083

8184
messages = agents_client.messages.list(thread_id=thread.id, order=ListSortOrder.ASCENDING)
8285
async for msg in messages:
83-
last_part = msg.content[-1]
84-
if isinstance(last_part, MessageTextContent):
85-
print(f"{msg.role}: {last_part.text.value}")
86+
if msg.text_messages:
87+
last_text = msg.text_messages[-1].text.value
88+
for annotation in msg.text_messages[-1].text.annotations:
89+
90+
citation = (
91+
vector_store_files.get(
92+
annotation.file_citation.file_id, annotation.file_citation.file_id)
93+
)
94+
last_text = last_text.replace(annotation.text, f" [{citation}]")
95+
print(f"{msg.role}: {last_text}")
8696

8797

8898
if __name__ == "__main__":

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_enterprise_file_search.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
ds = VectorStoreDataSource(asset_identifier=asset_uri, asset_type=VectorStoreDataSourceAssetType.URI_ASSET)
5858
vector_store = agents_client.vector_stores.create_and_poll(data_sources=[ds], name="sample_vector_store")
5959
print(f"Created vector store, vector store ID: {vector_store.id}")
60+
vector_store_files = {}
61+
for fle in agents_client.vector_store_files.list(vector_store.id):
62+
uploaded_file = agents_client.files.get(fle.id)
63+
vector_store_files[fle.id] = uploaded_file.filename
6064

6165
# Create a file search tool
6266
file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
@@ -95,5 +99,12 @@
9599
messages = agents_client.messages.list(thread_id=thread.id, order=ListSortOrder.ASCENDING)
96100
for msg in messages:
97101
if msg.text_messages:
98-
last_text = msg.text_messages[-1]
99-
print(f"{msg.role}: {last_text.text.value}")
102+
last_text = msg.text_messages[-1].text.value
103+
for annotation in msg.text_messages[-1].text.annotations:
104+
105+
citation = (
106+
vector_store_files.get(
107+
annotation.file_citation.file_id, annotation.file_citation.file_id)
108+
)
109+
last_text = last_text.replace(annotation.text, f" [{citation}]")
110+
print(f"{msg.role}: {last_text}")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "get weather data",
5+
"description": "Retrieves current weather data for a location based on wttr.in.",
6+
"version": "v1.0.0"
7+
},
8+
"servers": [
9+
{
10+
"url": "https://wttr.in"
11+
}
12+
],
13+
"auth": [],
14+
"paths": {
15+
"/{location}": {
16+
"get": {
17+
"description": "Get weather information for a specific location",
18+
"operationId": "GetCurrentWeather",
19+
"parameters": [
20+
{
21+
"name": "location",
22+
"in": "path",
23+
"description": "City or location to retrieve the weather for",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
},
29+
{
30+
"name": "format",
31+
"in": "query",
32+
"description": "Always use j1 value for this parameter",
33+
"required": true,
34+
"schema": {
35+
"type": "string",
36+
"default": "j1"
37+
}
38+
}
39+
],
40+
"responses": {
41+
"200": {
42+
"description": "Successful response",
43+
"content": {
44+
"text/plain": {
45+
"schema": {
46+
"type": "string"
47+
}
48+
}
49+
}
50+
},
51+
"404": {
52+
"description": "Location not found"
53+
}
54+
},
55+
"deprecated": false
56+
}
57+
}
58+
},
59+
"components": {
60+
"schemes": {}
61+
}
62+
}

sdk/ai/azure-ai-agents/tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ def azure_workspace_triad_sanitizer():
147147
value="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/connections/someindex",
148148
)
149149

150+
# Sanitize the plain bing grounding.
151+
add_body_key_sanitizer(
152+
json_path="tools[*].bing_grounding.search_configurations[*].connection_id",
153+
value="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.CognitiveServices/accounts/00000/projects/00000/connections/00000",
154+
)
155+
150156
# Sanitize deep research tool bing connection ID
151157
add_body_key_sanitizer(
152158
json_path="tools[*].deep_research.bing_grounding_connections[*].connection_id",

0 commit comments

Comments
 (0)