fix: auto-fix code issues (cron)

- 修复隐式 Optional 类型注解 (RUF013)
- 修复不必要的赋值后返回 (RET504)
- 优化列表推导式 (PERF401)
- 修复未使用的参数 (ARG002)
- 清理重复导入
- 优化异常处理
This commit is contained in:
AutoFix Bot
2026-03-03 21:11:47 +08:00
parent d17a58ceae
commit 259f2c90d0
36 changed files with 1651 additions and 863 deletions

View File

@@ -43,7 +43,7 @@ class RelationExtractionResult:
class LLMClient:
"""Kimi API 客户端"""
def __init__(self, api_key: str = None, base_url: str = None) -> None:
def __init__(self, api_key: str | None = None, base_url: str = None) -> None:
self.api_key = api_key or KIMI_API_KEY
self.base_url = base_url or KIMI_BASE_URL
self.headers = {
@@ -52,7 +52,10 @@ 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 +80,9 @@ 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,13 +95,16 @@ class LLMClient:
"stream": True,
}
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:
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: "):
@@ -112,7 +120,8 @@ class LLMClient:
pass
async def extract_entities_with_confidence(
self, text: str,
self,
text: str,
) -> tuple[list[EntityExtractionResult], list[RelationExtractionResult]]:
"""提取实体和关系,带置信度分数"""
prompt = f"""从以下会议文本中提取关键实体和它们之间的关系,以 JSON 格式返回:
@@ -189,7 +198,8 @@ class LLMClient:
messages = [
ChatMessage(
role="system", content="你是一个专业的项目分析助手,擅长从会议记录中提取洞察。",
role="system",
content="你是一个专业的项目分析助手,擅长从会议记录中提取洞察。",
),
ChatMessage(role="user", content=prompt),
]