1
1
# Copyright (c) Microsoft. All rights reserved.
2
2
# Licensed under the MIT license.
3
3
# See LICENSE file in the project root for full license information.
4
- from typing import Dict
4
+ from typing import Dict , List
5
5
6
6
import asyncio
7
7
import csv
@@ -110,7 +110,7 @@ async def get_available_toolset(
110
110
:return: The tool set, available based on the environment.
111
111
"""
112
112
# File name -> {"id": file_id, "path": file_path}
113
- files : Dict [str , Dict [ str , str ]] = {}
113
+ file_ids : List [str ] = []
114
114
# First try to get an index search.
115
115
conn_id = ""
116
116
if os .environ .get ('AZURE_AI_SEARCH_INDEX_NAME' ):
@@ -129,11 +129,6 @@ async def get_available_toolset(
129
129
index_name = os .environ .get ('AZURE_AI_SEARCH_INDEX_NAME' ))
130
130
131
131
toolset .add (ai_search )
132
- # Register the files
133
- for file_name in FILES_NAMES :
134
- file_path = _get_file_path (file_name )
135
- files [file_name ] = {"id" : file_name , "path" : file_path }
136
- logger .info ("agent: initialized index" )
137
132
else :
138
133
logger .info (
139
134
"agent: index was not initialized, falling back to file search." )
@@ -144,22 +139,17 @@ async def get_available_toolset(
144
139
file = await ai_client .agents .upload_file_and_poll (
145
140
file_path = file_path , purpose = FilePurpose .AGENTS )
146
141
# Store both file id and the file path using the file name as key.
147
- files [ file_name ] = { "id" : file .id , "path" : file_path }
142
+ file_ids . append ( file .id )
148
143
149
144
# Create the vector store using the file IDs.
150
145
vector_store = await ai_client .agents .create_vector_store_and_poll (
151
- file_ids = [ info [ "id" ] for info in files . values ()] ,
146
+ file_ids = file_ids ,
152
147
name = "sample_store"
153
148
)
154
149
logger .info ("agent: file store and vector store success" )
155
150
156
151
file_search_tool = FileSearchTool (vector_store_ids = [vector_store .id ])
157
152
toolset .add (file_search_tool )
158
- # Serialize and store files information in the environment variable (so
159
- # workers see it)
160
- os .environ ["UPLOADED_FILE_MAP" ] = json .dumps (files )
161
- logger .info (
162
- f"Set env UPLOADED_FILE_MAP = { os .environ ['UPLOADED_FILE_MAP' ]} " )
163
153
164
154
return toolset
165
155
0 commit comments