mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fix sample bugs in file search and web search samples (#4049)
- Fix file search samples: return vector_store.id string instead of Content object to avoid JSON serialization error - Fix web search sample: use correct web_search_options parameter for ChatClient instead of ResponsesClient's user_location parameter - Fix assistants client: pass tool_resources from options to run_options so vector store IDs reach thread creation - Add error handling for cleanup in Azure file search sample Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+8
-5
@@ -1,8 +1,9 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
|
||||
from agent_framework import Agent, Content
|
||||
from agent_framework import Agent
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
@@ -22,7 +23,7 @@ Prerequisites:
|
||||
# Helper functions
|
||||
|
||||
|
||||
async def create_vector_store(client: AzureOpenAIResponsesClient) -> tuple[str, Content]:
|
||||
async def create_vector_store(client: AzureOpenAIResponsesClient) -> tuple[str, str]:
|
||||
"""Create a vector store with sample documents."""
|
||||
file = await client.client.files.create(
|
||||
file=("todays_weather.txt", b"The weather today is sunny with a high of 75F."), purpose="assistants"
|
||||
@@ -35,13 +36,15 @@ async def create_vector_store(client: AzureOpenAIResponsesClient) -> tuple[str,
|
||||
if result.last_error is not None:
|
||||
raise Exception(f"Vector store file processing failed with status: {result.last_error.message}")
|
||||
|
||||
return file.id, Content.from_hosted_vector_store(vector_store_id=vector_store.id)
|
||||
return file.id, vector_store.id
|
||||
|
||||
|
||||
async def delete_vector_store(client: AzureOpenAIResponsesClient, file_id: str, vector_store_id: str) -> None:
|
||||
"""Delete the vector store after using it."""
|
||||
await client.client.vector_stores.delete(vector_store_id=vector_store_id)
|
||||
await client.client.files.delete(file_id=file_id)
|
||||
with contextlib.suppress(Exception):
|
||||
await client.client.vector_stores.delete(vector_store_id=vector_store_id)
|
||||
with contextlib.suppress(Exception):
|
||||
await client.client.files.delete(file_id=file_id)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
||||
Reference in New Issue
Block a user