fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 (E302, E305, E501) - 修复行长度超过100字符的问题 - 修复F821未定义名称错误
This commit is contained in:
@@ -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 进行相似度匹配"""
|
||||
|
||||
@@ -64,7 +66,7 @@ class EntityAligner:
|
||||
self.embedding_cache[cache_key] = embedding
|
||||
return embedding
|
||||
|
||||
except Exception as e:
|
||||
except (httpx.HTTPError, json.JSONDecodeError, KeyError) as e:
|
||||
print(f"Embedding API failed: {e}")
|
||||
return None
|
||||
|
||||
@@ -311,12 +313,14 @@ class EntityAligner:
|
||||
if json_match:
|
||||
data = json.loads(json_match.group())
|
||||
return data.get("aliases", [])
|
||||
except Exception as e:
|
||||
except (httpx.HTTPError, json.JSONDecodeError, KeyError) as e:
|
||||
print(f"Alias suggestion failed: {e}")
|
||||
|
||||
return []
|
||||
|
||||
# 简单的字符串相似度计算(不使用 embedding)
|
||||
|
||||
|
||||
def simple_similarity(str1: str, str2: str) -> float:
|
||||
"""
|
||||
计算两个字符串的简单相似度
|
||||
@@ -347,6 +351,7 @@ def simple_similarity(str1: str, str2: str) -> float:
|
||||
|
||||
return SequenceMatcher(None, s1, s2).ratio()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 测试
|
||||
aligner = EntityAligner()
|
||||
|
||||
Reference in New Issue
Block a user