fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题
- 添加类型注解
This commit is contained in:
OpenClaw Bot
2026-03-01 06:03:17 +08:00
parent 1f33d203e8
commit 6a51f5ea49
44 changed files with 142 additions and 1115 deletions

View File

@@ -17,7 +17,6 @@ DB_PATH = os.getenv("DB_PATH", "/app/data/insightflow.db")
# Constants
UUID_LENGTH = 8 # UUID 截断长度
@dataclass
class Project:
id: str
@@ -26,7 +25,6 @@ class Project:
created_at: str = ""
updated_at: str = ""
@dataclass
class Entity:
id: str
@@ -47,7 +45,6 @@ class Entity:
if self.attributes is None:
self.attributes = {}
@dataclass
class AttributeTemplate:
"""属性模板定义"""
@@ -68,7 +65,6 @@ class AttributeTemplate:
if self.options is None:
self.options = []
@dataclass
class EntityAttribute:
"""实体属性值"""
@@ -89,7 +85,6 @@ class EntityAttribute:
if self.options is None:
self.options = []
@dataclass
class AttributeHistory:
"""属性变更历史"""
@@ -103,7 +98,6 @@ class AttributeHistory:
changed_at: str = ""
change_reason: str = ""
@dataclass
class EntityMention:
id: str
@@ -114,7 +108,6 @@ class EntityMention:
text_snippet: str
confidence: float = 1.0
class DatabaseManager:
def __init__(self, db_path: str = DB_PATH):
self.db_path = db_path
@@ -1401,11 +1394,9 @@ class DatabaseManager:
conn.close()
return stats
# Singleton instance
_db_manager = None
def get_db_manager() -> DatabaseManager:
global _db_manager
if _db_manager is None:

View File

@@ -15,13 +15,11 @@ 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
@@ -29,7 +27,6 @@ class EntityExtractionResult:
definition: str
confidence: float
@dataclass
class RelationExtractionResult:
source: str
@@ -37,7 +34,6 @@ class RelationExtractionResult:
type: str
confidence: float
class LLMClient:
"""Kimi API 客户端"""
@@ -258,11 +254,9 @@ 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:

View File

@@ -12,7 +12,6 @@ from collections.abc import Callable
from dataclasses import dataclass
from functools import wraps
@dataclass
class RateLimitConfig:
"""限流配置"""
@@ -21,7 +20,6 @@ class RateLimitConfig:
burst_size: int = 10 # 突发请求数
window_size: int = 60 # 窗口大小(秒)
@dataclass
class RateLimitInfo:
"""限流信息"""
@@ -31,7 +29,6 @@ class RateLimitInfo:
reset_time: int # 重置时间戳
retry_after: int # 需要等待的秒数
class SlidingWindowCounter:
"""滑动窗口计数器"""
@@ -63,7 +60,6 @@ class SlidingWindowCounter:
for k in old_keys:
self.requests.pop(k, None)
class RateLimiter:
"""API 限流器"""
@@ -159,11 +155,9 @@ class RateLimiter:
self.counters.clear()
self.configs.clear()
# 全局限流器实例
_rate_limiter: RateLimiter | None = None
def get_rate_limiter() -> RateLimiter:
"""获取限流器实例"""
global _rate_limiter
@@ -173,7 +167,6 @@ def get_rate_limiter() -> RateLimiter:
# 限流装饰器(用于函数级别限流)
def rate_limit(requests_per_minute: int = 60, key_func: Callable | None = None) -> None:
"""
限流装饰器
@@ -216,6 +209,5 @@ def rate_limit(requests_per_minute: int = 60, key_func: Callable | None = None)
return decorator
class RateLimitExceeded(Exception):
"""限流异常"""

View File

@@ -8,7 +8,6 @@ import time
from datetime import datetime
from typing import Any
class TingwuClient:
def __init__(self):
self.access_key = os.getenv("ALI_ACCESS_KEY", "")