fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题
- 添加类型注解
This commit is contained in:
AutoFix Bot
2026-03-03 06:03:38 +08:00
parent 2a0ed6af4d
commit 9fd1da8fb7
41 changed files with 901 additions and 768 deletions

View File

@@ -52,7 +52,7 @@ class LLMClient:
}
async def chat(
self, messages: list[ChatMessage], temperature: float = 0.3, stream: bool = False
self, messages: list[ChatMessage], temperature: float = 0.3, stream: bool = False,
) -> str:
"""发送聊天请求"""
if not self.api_key:
@@ -77,7 +77,7 @@ class LLMClient:
return result["choices"][0]["message"]["content"]
async def chat_stream(
self, messages: list[ChatMessage], temperature: float = 0.3
self, messages: list[ChatMessage], temperature: float = 0.3,
) -> AsyncGenerator[str, None]:
"""流式聊天请求"""
if not self.api_key:
@@ -90,30 +90,29 @@ class LLMClient:
"stream": True,
}
async with httpx.AsyncClient() as client:
async with client.stream(
"POST",
f"{self.base_url}/v1/chat/completions",
headers=self.headers,
json=payload,
timeout=120.0,
) as response:
response.raise_for_status()
async for line in response.aiter_lines():
if line.startswith("data: "):
data = line[6:]
if data == "[DONE]":
break
try:
chunk = json.loads(data)
delta = chunk["choices"][0]["delta"]
if "content" in delta:
yield delta["content"]
except (json.JSONDecodeError, KeyError, IndexError):
pass
async with httpx.AsyncClient() as client, client.stream(
"POST",
f"{self.base_url}/v1/chat/completions",
headers=self.headers,
json=payload,
timeout=120.0,
) as response:
response.raise_for_status()
async for line in response.aiter_lines():
if line.startswith("data: "):
data = line[6:]
if data == "[DONE]":
break
try:
chunk = json.loads(data)
delta = chunk["choices"][0]["delta"]
if "content" in delta:
yield delta["content"]
except (json.JSONDecodeError, KeyError, IndexError):
pass
async def extract_entities_with_confidence(
self, text: str
self, text: str,
) -> tuple[list[EntityExtractionResult], list[RelationExtractionResult]]:
"""提取实体和关系,带置信度分数"""
prompt = f"""从以下会议文本中提取关键实体和它们之间的关系,以 JSON 格式返回:
@@ -190,7 +189,7 @@ class LLMClient:
messages = [
ChatMessage(
role="system", content="你是一个专业的项目分析助手,擅长从会议记录中提取洞察。"
role="system", content="你是一个专业的项目分析助手,擅长从会议记录中提取洞察。",
),
ChatMessage(role="user", content=prompt),
]
@@ -241,7 +240,7 @@ class LLMClient:
[
f"[{m.get('created_at', '未知时间')}] {m.get('text_snippet', '')}"
for m in mentions[:20]
] # 限制数量
], # 限制数量
)
prompt = f"""分析实体 "{entity_name}" 在项目中的演变和态度变化: