Skip to content

Commit cb7c50e

Browse files
committed
resolved comments
1 parent 185de64 commit cb7c50e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/api/main.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
import sys
88
import json
9-
from typing import Dict
9+
from typing import Dict, Optional
1010

1111
from azure.ai.projects.aio import AIProjectClient
1212
from azure.ai.projects.models import FilePurpose, FileSearchTool, AsyncToolSet, FileSearchToolResource
@@ -81,21 +81,27 @@ async def lifespan(app: fastapi.FastAPI):
8181
file_map: Dict[str, Dict[str, str]] = {}
8282

8383
logger.info(f"Creating UPLOADED_FILE_MAP")
84+
folder_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'files'))
8485
if agent.tool_resources and agent.tool_resources.file_search:
8586
for vector_store_id in agent.tool_resources.file_search.vector_store_ids:
86-
file = await ai_client.agents.list_vector_store_files(vector_store_id)
87-
for file in file.data:
88-
openAI_file = await ai_client.agents.get_file(file.id)
89-
logger.info(f"Retrieved file, file ID: {openAI_file.filename}")
90-
file_name = openAI_file.filename
91-
file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..\\files', file_name))
92-
93-
if not os.path.exists(file_path):
94-
logger.warning(f"File path does not exist: {file_path}")
95-
continue
87+
after: Optional[str] = None
88+
has_more = True
89+
while has_more:
90+
files = await ai_client.agents.list_vector_store_files(vector_store_id, after=after)
91+
has_more = files.has_more
92+
after = files.last_id
93+
for file in files.data:
94+
openAI_file = await ai_client.agents.get_file(file.id)
95+
logger.info(f"Retrieved file, file ID: {openAI_file.filename}")
96+
file_name = openAI_file.filename
97+
file_path = os.path.join(folder_path, file_name)
98+
99+
if not os.path.exists(file_path):
100+
logger.warning(f"File path does not exist: {file_path}")
101+
continue
96102

97-
# Store both file id and the file path using the file name as key.
98-
file_map[file_name] = {"id": file.id, "path": file_path}
103+
# Store both file id and the file path using the file name as key.
104+
file_map[file_name] = {"id": file.id, "path": file_path}
99105
app.state.upload_file_map = file_map
100106
logger.info(f"Set UPLOADED_FILE_MAP {file_map}")
101107
yield

0 commit comments

Comments
 (0)