Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1285,6 +1285,13 @@ def parse_query(query: str) -> dict:
|
|
| 1285 |
|
| 1286 |
def autogen_multi_document_analysis(query: str, docs: list, file_names: list) -> str:
|
| 1287 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1288 |
# 準備文件上下文
|
| 1289 |
context = "\n\n".join(
|
| 1290 |
f"Document {name}:\n{doc[:2000]}..."
|
|
@@ -1302,14 +1309,16 @@ def autogen_multi_document_analysis(query: str, docs: list, file_names: list) ->
|
|
| 1302 |
"config_list": config_list,
|
| 1303 |
"temperature": 0,
|
| 1304 |
"request_timeout": 120,
|
| 1305 |
-
"seed": 42
|
|
|
|
| 1306 |
}
|
| 1307 |
|
| 1308 |
# 代碼執行配置
|
| 1309 |
code_execution_config = {
|
| 1310 |
-
"use_docker": False,
|
| 1311 |
"last_n_messages": 3,
|
| 1312 |
-
"timeout": 60
|
|
|
|
| 1313 |
}
|
| 1314 |
|
| 1315 |
# 定義代理人
|
|
@@ -1317,7 +1326,7 @@ def autogen_multi_document_analysis(query: str, docs: list, file_names: list) ->
|
|
| 1317 |
name="User",
|
| 1318 |
system_message="A user seeking information from multiple documents.",
|
| 1319 |
human_input_mode="NEVER",
|
| 1320 |
-
code_execution_config=code_execution_config
|
| 1321 |
)
|
| 1322 |
|
| 1323 |
# 定義專家代理人們
|
|
@@ -1385,7 +1394,16 @@ def autogen_multi_document_analysis(query: str, docs: list, file_names: list) ->
|
|
| 1385 |
|
| 1386 |
# 執行群組討論
|
| 1387 |
user_proxy.initiate_chat(manager, message=task_prompt)
|
| 1388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1389 |
|
| 1390 |
except Exception as e:
|
| 1391 |
print(f"ERROR in AutoGen processing: {str(e)}")
|
|
|
|
| 1285 |
|
| 1286 |
def autogen_multi_document_analysis(query: str, docs: list, file_names: list) -> str:
|
| 1287 |
try:
|
| 1288 |
+
import os
|
| 1289 |
+
import tempfile
|
| 1290 |
+
|
| 1291 |
+
# 創建臨時目錄作為緩存目錄
|
| 1292 |
+
cache_dir = tempfile.mkdtemp()
|
| 1293 |
+
os.environ['AUTOGEN_CACHE_DIR'] = cache_dir
|
| 1294 |
+
|
| 1295 |
# 準備文件上下文
|
| 1296 |
context = "\n\n".join(
|
| 1297 |
f"Document {name}:\n{doc[:2000]}..."
|
|
|
|
| 1309 |
"config_list": config_list,
|
| 1310 |
"temperature": 0,
|
| 1311 |
"request_timeout": 120,
|
| 1312 |
+
"seed": 42,
|
| 1313 |
+
"cache_dir": cache_dir # 使用臨時目錄作為緩存
|
| 1314 |
}
|
| 1315 |
|
| 1316 |
# 代碼執行配置
|
| 1317 |
code_execution_config = {
|
| 1318 |
+
"use_docker": False,
|
| 1319 |
"last_n_messages": 3,
|
| 1320 |
+
"timeout": 60,
|
| 1321 |
+
"work_dir": cache_dir # 使用臨時目錄作為工作目錄
|
| 1322 |
}
|
| 1323 |
|
| 1324 |
# 定義代理人
|
|
|
|
| 1326 |
name="User",
|
| 1327 |
system_message="A user seeking information from multiple documents.",
|
| 1328 |
human_input_mode="NEVER",
|
| 1329 |
+
code_execution_config=code_execution_config
|
| 1330 |
)
|
| 1331 |
|
| 1332 |
# 定義專家代理人們
|
|
|
|
| 1394 |
|
| 1395 |
# 執行群組討論
|
| 1396 |
user_proxy.initiate_chat(manager, message=task_prompt)
|
| 1397 |
+
result = user_proxy.last_message()["content"]
|
| 1398 |
+
|
| 1399 |
+
# 清理臨時目錄
|
| 1400 |
+
import shutil
|
| 1401 |
+
try:
|
| 1402 |
+
shutil.rmtree(cache_dir)
|
| 1403 |
+
except:
|
| 1404 |
+
pass
|
| 1405 |
+
|
| 1406 |
+
return result
|
| 1407 |
|
| 1408 |
except Exception as e:
|
| 1409 |
print(f"ERROR in AutoGen processing: {str(e)}")
|