@@ -69,79 +69,6 @@ for direct document-based question answering and information retrieval.
6969# Helper functions
7070
7171
72- async def create_vector_store (client : OpenAIChatClient) -> tuple[str , Content]:
73- """ Create a vector store with sample documents."""
74- file = await client.client.files.create(
75- file = (" todays_weather.txt" , b " The weather today is sunny with a high of 75F." ), purpose = " user_data"
76- )
77- vector_store = await client.client.vector_stores.create(
78- name = " knowledge_base" ,
79- expires_after = {" anchor" : " last_active_at" , " days" : 1 },
80- )
81- result = await client.client.vector_stores.files.create_and_poll(vector_store_id = vector_store.id, file_id = file .id)
82- if result.last_error is not None :
83- raise Exception (f " Vector store file processing failed with status: { result.last_error.message} " )
84-
85- return file .id, Content.from_hosted_vector_store(vector_store_id = vector_store.id)
86-
87-
88- async def delete_vector_store (client : OpenAIChatClient, file_id : str , vector_store_id : str ) -> None :
89- """ Delete the vector store after using it."""
90- await client.client.vector_stores.delete(vector_store_id = vector_store_id)
91- await client.client.files.delete(file_id = file_id)
92-
93-
94- async def main () -> None :
95- client = OpenAIChatClient()
96-
97- message = " What is the weather today? Do a file search to find the answer."
98-
99- stream = False
100- print (f " User: { message} " )
101- file_id, vector_store_id = await create_vector_store(client)
102-
103- agent = Agent(
104- client = client,
105- instructions = " You are a helpful assistant that can search through files to find information." ,
106- tools = [client.get_file_search_tool(vector_store_ids = [vector_store_id])],
107- )
108-
109- if stream:
110- print (" Assistant: " , end = " " )
111- async for chunk in agent.run(message, stream = True ):
112- if chunk.text:
113- print (chunk.text, end = " " )
114- print (" " )
115- else :
116- response = await agent.run(message)
117- print (f " Assistant: { response} " )
118- await delete_vector_store(client, file_id, vector_store_id)
119-
120-
121- if __name__ == " __main__" :
122- asyncio.run(main())
123- ```
124-
125- ### Run the agent
126-
127- ``` python
128- # Copyright (c) Microsoft. All rights reserved.
129-
130- import asyncio
131-
132- from agent_framework import Agent, Content
133- from agent_framework.openai import OpenAIChatClient
134-
135- """
136- OpenAI Responses Client with File Search Example
137-
138- This sample demonstrates using get_file_search_tool() with OpenAI Responses Client
139- for direct document-based question answering and information retrieval.
140- """
141-
142- # Helper functions
143-
144-
14572async def create_vector_store (client : OpenAIChatClient) -> tuple[str , Content]:
14673 """ Create a vector store with sample documents."""
14774 file = await client.client.files.create(
0 commit comments