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:
@@ -14,6 +14,10 @@ from datetime import datetime
|
||||
|
||||
DB_PATH = os.getenv("DB_PATH", "/app/data/insightflow.db")
|
||||
|
||||
# Constants
|
||||
UUID_LENGTH = 8 # UUID 截断长度
|
||||
|
||||
|
||||
@dataclass
|
||||
class Project:
|
||||
id: str
|
||||
@@ -22,6 +26,7 @@ class Project:
|
||||
created_at: str = ""
|
||||
updated_at: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class Entity:
|
||||
id: str
|
||||
@@ -42,6 +47,7 @@ class Entity:
|
||||
if self.attributes is None:
|
||||
self.attributes = {}
|
||||
|
||||
|
||||
@dataclass
|
||||
class AttributeTemplate:
|
||||
"""属性模板定义"""
|
||||
@@ -62,6 +68,7 @@ class AttributeTemplate:
|
||||
if self.options is None:
|
||||
self.options = []
|
||||
|
||||
|
||||
@dataclass
|
||||
class EntityAttribute:
|
||||
"""实体属性值"""
|
||||
@@ -82,6 +89,7 @@ class EntityAttribute:
|
||||
if self.options is None:
|
||||
self.options = []
|
||||
|
||||
|
||||
@dataclass
|
||||
class AttributeHistory:
|
||||
"""属性变更历史"""
|
||||
@@ -95,6 +103,7 @@ class AttributeHistory:
|
||||
changed_at: str = ""
|
||||
change_reason: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class EntityMention:
|
||||
id: str
|
||||
@@ -105,6 +114,7 @@ class EntityMention:
|
||||
text_snippet: str
|
||||
confidence: float = 1.0
|
||||
|
||||
|
||||
class DatabaseManager:
|
||||
def __init__(self, db_path: str = DB_PATH):
|
||||
self.db_path = db_path
|
||||
@@ -321,15 +331,14 @@ class DatabaseManager:
|
||||
conn.execute(
|
||||
"""INSERT INTO entity_mentions (id, entity_id, transcript_id, start_pos, end_pos, text_snippet, confidence)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)""",
|
||||
(
|
||||
mention.id,
|
||||
mention.entity_id,
|
||||
mention.transcript_id,
|
||||
mention.start_pos,
|
||||
mention.end_pos,
|
||||
mention.text_snippet,
|
||||
mention.confidence,
|
||||
),
|
||||
(mention.id,
|
||||
mention.entity_id,
|
||||
mention.transcript_id,
|
||||
mention.start_pos,
|
||||
mention.end_pos,
|
||||
mention.text_snippet,
|
||||
mention.confidence,
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
@@ -358,7 +367,12 @@ class DatabaseManager:
|
||||
now = datetime.now().isoformat()
|
||||
conn.execute(
|
||||
"INSERT INTO transcripts (id, project_id, filename, full_text, type, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
(transcript_id, project_id, filename, full_text, transcript_type, now),
|
||||
(transcript_id,
|
||||
project_id,
|
||||
filename,
|
||||
full_text,
|
||||
transcript_type,
|
||||
now),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
@@ -401,7 +415,7 @@ class DatabaseManager:
|
||||
transcript_id: str = "",
|
||||
):
|
||||
conn = self.get_conn()
|
||||
relation_id = str(uuid.uuid4())[:8]
|
||||
relation_id = str(uuid.uuid4())[:UUID_LENGTH]
|
||||
now = datetime.now().isoformat()
|
||||
conn.execute(
|
||||
"""INSERT INTO entity_relations
|
||||
@@ -485,7 +499,7 @@ class DatabaseManager:
|
||||
conn.close()
|
||||
return existing["id"]
|
||||
|
||||
term_id = str(uuid.uuid4())[:8]
|
||||
term_id = str(uuid.uuid4())[:UUID_LENGTH]
|
||||
conn.execute(
|
||||
"INSERT INTO glossary (id, project_id, term, pronunciation, frequency) VALUES (?, ?, ?, ?, ?)",
|
||||
(term_id, project_id, term, pronunciation, 1),
|
||||
@@ -836,7 +850,7 @@ class DatabaseManager:
|
||||
(id, entity_id, template_id, old_value, new_value, changed_by, changed_at, change_reason)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(
|
||||
str(uuid.uuid4())[:8],
|
||||
str(uuid.uuid4())[:UUID_LENGTH],
|
||||
attr.entity_id,
|
||||
attr.template_id,
|
||||
old_value,
|
||||
@@ -915,7 +929,7 @@ class DatabaseManager:
|
||||
(id, entity_id, template_id, old_value, new_value, changed_by, changed_at, change_reason)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(
|
||||
str(uuid.uuid4())[:8],
|
||||
str(uuid.uuid4())[:UUID_LENGTH],
|
||||
entity_id,
|
||||
template_id,
|
||||
old_row["value"],
|
||||
@@ -1387,9 +1401,11 @@ class DatabaseManager:
|
||||
conn.close()
|
||||
return stats
|
||||
|
||||
|
||||
# Singleton instance
|
||||
_db_manager = None
|
||||
|
||||
|
||||
def get_db_manager() -> DatabaseManager:
|
||||
global _db_manager
|
||||
if _db_manager is None:
|
||||
|
||||
Reference in New Issue
Block a user