fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题
- 添加类型注解
- 修复缺失的urllib.parse导入
This commit is contained in:
OpenClaw Bot
2026-02-28 06:03:09 +08:00
parent ff83cab6c7
commit fe3d64a1d2
41 changed files with 4501 additions and 1176 deletions

View File

@@ -15,6 +15,7 @@ import numpy as np
KIMI_API_KEY = os.getenv("KIMI_API_KEY", "")
KIMI_BASE_URL = os.getenv("KIMI_BASE_URL", "https://api.kimi.com/coding")
@dataclass
class EntityEmbedding:
entity_id: str
@@ -22,6 +23,7 @@ class EntityEmbedding:
definition: str
embedding: list[float]
class EntityAligner:
"""实体对齐器 - 使用 embedding 进行相似度匹配"""
@@ -50,7 +52,10 @@ class EntityAligner:
try:
response = httpx.post(
f"{KIMI_BASE_URL}/v1/embeddings",
headers={"Authorization": f"Bearer {KIMI_API_KEY}", "Content-Type": "application/json"},
headers={
"Authorization": f"Bearer {KIMI_API_KEY}",
"Content-Type": "application/json",
},
json={"model": "k2p5", "input": text[:500]}, # 限制长度
timeout=30.0,
)
@@ -230,7 +235,12 @@ class EntityAligner:
project_id, new_ent["name"], new_ent.get("definition", ""), threshold=threshold
)
result = {"new_entity": new_ent, "matched_entity": None, "similarity": 0.0, "should_merge": False}
result = {
"new_entity": new_ent,
"matched_entity": None,
"similarity": 0.0,
"should_merge": False,
}
if matched:
# 计算相似度
@@ -282,8 +292,15 @@ class EntityAligner:
try:
response = httpx.post(
f"{KIMI_BASE_URL}/v1/chat/completions",
headers={"Authorization": f"Bearer {KIMI_API_KEY}", "Content-Type": "application/json"},
json={"model": "k2p5", "messages": [{"role": "user", "content": prompt}], "temperature": 0.3},
headers={
"Authorization": f"Bearer {KIMI_API_KEY}",
"Content-Type": "application/json",
},
json={
"model": "k2p5",
"messages": [{"role": "user", "content": prompt}],
"temperature": 0.3,
},
timeout=30.0,
)
response.raise_for_status()
@@ -301,6 +318,7 @@ class EntityAligner:
return []
# 简单的字符串相似度计算(不使用 embedding
def simple_similarity(str1: str, str2: str) -> float:
"""
@@ -332,6 +350,7 @@ def simple_similarity(str1: str, str2: str) -> float:
return SequenceMatcher(None, s1, s2).ratio()
if __name__ == "__main__":
# 测试
aligner = EntityAligner()