|
@@ -39,10 +39,16 @@ class FileSearchTool(BaseTool):
|
|
|
self.loop = None
|
|
|
|
|
|
def configure(self, session: Session, run: Run, **kwargs):
|
|
|
+ """
|
|
|
+ # 提交任务到事件循环
|
|
|
+ future = asyncio.run_coroutine_threadsafe(async_task(), loop)
|
|
|
+ # 阻塞等待结果
|
|
|
+ result = future.result()
|
|
|
+ """
|
|
|
"""
|
|
|
置当前 Retrieval 涉及文件信息
|
|
|
"""
|
|
|
- # self.loop = asyncio.get_event_loop() # 获取当前事件循环
|
|
|
+ self.loop = asyncio.get_event_loop() # 获取当前事件循环
|
|
|
document_id = []
|
|
|
file_key = []
|
|
|
filesinfo = []
|
|
@@ -66,9 +72,14 @@ class FileSearchTool(BaseTool):
|
|
|
print(files)
|
|
|
# r2r接口不提供多条件,否则上面没必要存在
|
|
|
if len(document_id) > 0:
|
|
|
- filesinfo += asyncio.run(
|
|
|
- FileService.list_in_files(ids=document_id, offset=0, limit=100)
|
|
|
+ future = asyncio.run_coroutine_threadsafe(
|
|
|
+ FileService.list_in_files(ids=document_id, offset=0, limit=100),
|
|
|
+ self.loop,
|
|
|
)
|
|
|
+ filesinfo += future.result()
|
|
|
+ # asyncio.run(
|
|
|
+ # FileService.list_in_files(ids=document_id, offset=0, limit=100)
|
|
|
+ # )
|
|
|
for file in filesinfo:
|
|
|
self.__filenames.append(file.get("title"))
|
|
|
self.__keys.append(file.get("id"))
|
|
@@ -90,9 +101,14 @@ class FileSearchTool(BaseTool):
|
|
|
folder_fileinfo = []
|
|
|
if asst_folder_ids:
|
|
|
for fid in asst_folder_ids:
|
|
|
- folder_fileinfo += asyncio.run(
|
|
|
+ future = asyncio.run_coroutine_threadsafe(
|
|
|
FileService.list_documents(id=fid, offset=0, limit=100)
|
|
|
+ self.loop
|
|
|
)
|
|
|
+ folder_fileinfo += future.result()
|
|
|
+ #folder_fileinfo += asyncio.run(
|
|
|
+ # FileService.list_documents(id=fid, offset=0, limit=100)
|
|
|
+ #)
|
|
|
print(folder_fileinfo)
|
|
|
for file in folder_fileinfo:
|
|
|
self.__filenames.append(file.get("title"))
|
|
@@ -121,9 +137,14 @@ class FileSearchTool(BaseTool):
|
|
|
files = []
|
|
|
if len(file_keys) > 0:
|
|
|
# self.loop = asyncio.get_event_loop()
|
|
|
- files = asyncio.run(
|
|
|
- FileService.search_in_files(query=query, file_keys=file_keys)
|
|
|
- )
|
|
|
+ future = asyncio.run_coroutine_threadsafe(
|
|
|
+ FileService.search_in_files(query=query, file_keys=file_keys)
|
|
|
+ self.loop
|
|
|
+ )
|
|
|
+ files += future.result()
|
|
|
+ #files = asyncio.run(
|
|
|
+ # FileService.search_in_files(query=query, file_keys=file_keys)
|
|
|
+ #)
|
|
|
return files
|
|
|
|
|
|
def instruction_supplement(self) -> str:
|