fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理 (将裸 except Exception 改为具体异常类型)
- 修复PEP8格式问题
- 清理未使用导入
- 添加 UUID_LENGTH 常量替代魔法数字
- 添加 DEFAULT_RATE_LIMIT, MASTER_KEY_RATE_LIMIT, IP_RATE_LIMIT 常量
- 添加 MAX_TEXT_LENGTH, DEFAULT_TIMEOUT 常量

涉及文件:
- backend/main.py
- backend/db_manager.py
- backend/llm_client.py
- backend/neo4j_manager.py
- backend/tingwu_client.py
- backend/tenant_manager.py
- backend/growth_manager.py
- backend/workflow_manager.py
- backend/image_processor.py
- backend/multimodal_entity_linker.py
- backend/multimodal_processor.py
- backend/plugin_manager.py
- backend/rate_limiter.py
This commit is contained in:
OpenClaw Bot
2026-03-01 03:06:06 +08:00
parent ea58b6fe43
commit 1f33d203e8
13 changed files with 141 additions and 85 deletions

View File

@@ -15,11 +15,13 @@ import httpx
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
@dataclass
class ChatMessage:
role: str
content: str
@dataclass
class EntityExtractionResult:
name: str
@@ -27,6 +29,7 @@ class EntityExtractionResult:
definition: str
confidence: float
@dataclass
class RelationExtractionResult:
source: str
@@ -34,6 +37,7 @@ class RelationExtractionResult:
type: str
confidence: float
class LLMClient:
"""Kimi API 客户端"""
@@ -163,7 +167,7 @@ class LLMClient:
for r in data.get("relations", [])
]
return entities, relations
except Exception as e:
except (RuntimeError, ValueError, TypeError) as e:
print(f"Parse extraction result failed: {e}")
return [], []
@@ -254,9 +258,11 @@ class LLMClient:
messages = [ChatMessage(role="user", content=prompt)]
return await self.chat(messages, temperature=0.3)
# Singleton instance
_llm_client = None
def get_llm_client() -> LLMClient:
global _llm_client
if _llm_client is None: