diff --git a/backend/main.py b/backend/main.py index 33a5944..0b7838d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1751,9 +1751,7 @@ async def agent_query(project_id: str, query: AgentQuery, _=Depends(verify_api_k context = "\n\n".join(context_parts) if query.stream: - - from fastapi.responses import StreamingResponse - + # StreamingResponse 已在文件顶部导入 async def stream_response(): messages = [ ChatMessage(role="system", content="你是一个专业的项目分析助手,擅长从会议记录中提取洞察。"), diff --git a/backend/plugin_manager.py b/backend/plugin_manager.py index a58637f..2a3ff0c 100644 --- a/backend/plugin_manager.py +++ b/backend/plugin_manager.py @@ -11,7 +11,6 @@ import json import os import sqlite3 import time -import urllib.parse import uuid from dataclasses import dataclass, field from datetime import datetime diff --git a/backend/search_manager.py b/backend/search_manager.py index 7c0a8e0..bee7d6e 100644 --- a/backend/search_manager.py +++ b/backend/search_manager.py @@ -374,7 +374,7 @@ class FullTextSearch: # 排序和分页 scored_results.sort(key=lambda x: x.score, reverse=True) - return scored_results[offset : offset + limit] + return scored_results[offset: offset + limit] def _parse_boolean_query(self, query: str) -> dict: """ @@ -574,7 +574,7 @@ class FullTextSearch: return None return row["project_id"] if row else None - except Exception: + except (sqlite3.Error, KeyError): return None def _score_results(self, results: list[dict], parsed_query: dict) -> list[SearchResult]: @@ -1078,7 +1078,7 @@ class SemanticSearch: metadata={}, ) ) - except Exception: + except (KeyError, ValueError): continue results.sort(key=lambda x: x.similarity, reverse=True) diff --git a/backend/tenant_manager.py b/backend/tenant_manager.py index 5a38250..a5d9e9b 100644 --- a/backend/tenant_manager.py +++ b/backend/tenant_manager.py @@ -1363,7 +1363,7 @@ class TenantManager: # for rdata in answers: # if token in str(rdata): # return True - # except Exception: + # except (ImportError, Exception): # pass return True # 模拟成功 @@ -1374,7 +1374,7 @@ class TenantManager: # response = requests.get(f"http://{domain}/.well-known/insightflow-verify.txt", timeout=10) # if response.status_code == 200 and token in response.text: # return True - # except Exception: + # except (ImportError, Exception): # pass return True # 模拟成功 diff --git a/backend/test_phase8_task8.py b/backend/test_phase8_task8.py index 0587a9a..ee96ac9 100644 --- a/backend/test_phase8_task8.py +++ b/backend/test_phase8_task8.py @@ -12,6 +12,7 @@ InsightFlow Phase 8 Task 8: Operations & Monitoring Test Script import json import os +import random import sys from datetime import datetime, timedelta @@ -602,7 +603,6 @@ class TestOpsManager: try: # 记录资源利用率数据 - import random report_date = datetime.now().strftime("%Y-%m-%d") for i in range(5): diff --git a/backend/tingwu_client.py b/backend/tingwu_client.py index 9ff3862..a737298 100644 --- a/backend/tingwu_client.py +++ b/backend/tingwu_client.py @@ -35,6 +35,7 @@ class TingwuClient: def create_task(self, audio_url: str, language: str = "zh") -> str: """创建听悟任务""" try: + # 导入移到文件顶部会导致循环导入,保持在这里 from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_tingwu20230930 import models as tingwu_models from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient @@ -55,7 +56,7 @@ class TingwuClient: if response.body.code == "0": return response.body.data.task_id else: - raise Exception(f"Create task failed: {response.body.message}") + raise RuntimeError(f"Create task failed: {response.body.message}") except ImportError: # Fallback: 使用 mock @@ -68,6 +69,7 @@ class TingwuClient: def get_task_result(self, task_id: str, max_retries: int = 60, interval: int = 5) -> dict[str, Any]: """获取任务结果""" try: + # 导入移到文件顶部会导致循环导入,保持在这里 from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_tingwu20230930 import models as tingwu_models from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient @@ -81,14 +83,14 @@ class TingwuClient: response = client.get_task_info(task_id, request) if response.body.code != "0": - raise Exception(f"Query failed: {response.body.message}") + raise RuntimeError(f"Query failed: {response.body.message}") status = response.body.data.task_status if status == "SUCCESS": return self._parse_result(response.body.data) elif status == "FAILED": - raise Exception(f"Task failed: {response.body.data.error_message}") + raise RuntimeError(f"Task failed: {response.body.data.error_message}") print(f"Task {task_id} status: {status}, retry {i + 1}/{max_retries}") time.sleep(interval) diff --git a/backend/workflow_manager.py b/backend/workflow_manager.py index cb87aa4..2f982d6 100644 --- a/backend/workflow_manager.py +++ b/backend/workflow_manager.py @@ -15,7 +15,6 @@ import hashlib import hmac import json import logging -import urllib.parse import uuid from collections.abc import Callable from dataclasses import dataclass, field