fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题 (816+ 处)
- 添加缺失的导入 (json, re)
- 统一SQL查询格式
- 修复赋值语句空格问题

修复文件:
- db_manager.py (96处)
- search_manager.py (77处)
- ops_manager.py (66处)
- developer_ecosystem_manager.py (68处)
- growth_manager.py (60处)
- enterprise_manager.py (61处)
- tenant_manager.py (57处)
- plugin_manager.py (48处)
- subscription_manager.py (46处)
- security_manager.py (29处)
- workflow_manager.py (32处)
- localization_manager.py (31处)
- api_key_manager.py (20处)
- ai_manager.py (23处)
- performance_manager.py (24处)
- neo4j_manager.py (25处)
- collaboration_manager.py (33处)
- test_phase8_task8.py (16处)
- test_phase8_task6.py (4处)
- knowledge_reasoner.py (添加import json)
- llm_client.py (添加import json)
This commit is contained in:
AutoFix Bot
2026-03-03 00:11:51 +08:00
parent c695e99eaf
commit 2a0ed6af4d
23 changed files with 1160 additions and 947 deletions

View File

@@ -283,7 +283,7 @@ class AIManager:
def get_custom_model(self, model_id: str) -> CustomModel | None:
"""获取自定义模型"""
with self._get_db() as conn:
row = conn.execute("SELECT * FROM custom_models WHERE id = ?", (model_id,)).fetchone()
row = conn.execute("SELECT * FROM custom_models WHERE id = ?", (model_id,)).fetchone()
if not row:
return None
@@ -294,14 +294,14 @@ class AIManager:
self, tenant_id: str, model_type: ModelType | None = None, status: ModelStatus | None = None
) -> list[CustomModel]:
"""列出自定义模型"""
query = "SELECT * FROM custom_models WHERE tenant_id = ?"
query = "SELECT * FROM custom_models WHERE tenant_id = ?"
params = [tenant_id]
if model_type:
query += " AND model_type = ?"
query += " AND model_type = ?"
params.append(model_type.value)
if status:
query += " AND status = ?"
query += " AND status = ?"
params.append(status.value)
query += " ORDER BY created_at DESC"
@@ -350,7 +350,7 @@ class AIManager:
"""获取训练样本"""
with self._get_db() as conn:
rows = conn.execute(
"SELECT * FROM training_samples WHERE model_id = ? ORDER BY created_at",
"SELECT * FROM training_samples WHERE model_id = ? ORDER BY created_at",
(model_id,),
).fetchall()
@@ -365,7 +365,7 @@ class AIManager:
# 更新状态为训练中
with self._get_db() as conn:
conn.execute(
"UPDATE custom_models SET status = ?, updated_at = ? WHERE id = ?",
"UPDATE custom_models SET status = ?, updated_at = ? WHERE id = ?",
(ModelStatus.TRAINING.value, datetime.now().isoformat(), model_id),
)
conn.commit()
@@ -401,8 +401,8 @@ class AIManager:
conn.execute(
"""
UPDATE custom_models
SET status = ?, metrics = ?, model_path = ?, trained_at = ?, updated_at = ?
WHERE id = ?
SET status = ?, metrics = ?, model_path = ?, trained_at = ?, updated_at = ?
WHERE id = ?
""",
(ModelStatus.READY.value, json.dumps(metrics), model_path, now, now, model_id),
)
@@ -413,7 +413,7 @@ class AIManager:
except Exception as e:
with self._get_db() as conn:
conn.execute(
"UPDATE custom_models SET status = ?, updated_at = ? WHERE id = ?",
"UPDATE custom_models SET status = ?, updated_at = ? WHERE id = ?",
(ModelStatus.FAILED.value, datetime.now().isoformat(), model_id),
)
conn.commit()
@@ -641,11 +641,11 @@ class AIManager:
self, tenant_id: str, project_id: str | None = None
) -> list[MultimodalAnalysis]:
"""获取多模态分析历史"""
query = "SELECT * FROM multimodal_analyses WHERE tenant_id = ?"
query = "SELECT * FROM multimodal_analyses WHERE tenant_id = ?"
params = [tenant_id]
if project_id:
query += " AND project_id = ?"
query += " AND project_id = ?"
params.append(project_id)
query += " ORDER BY created_at DESC"
@@ -713,7 +713,7 @@ class AIManager:
def get_kg_rag(self, rag_id: str) -> KnowledgeGraphRAG | None:
"""获取知识图谱 RAG 配置"""
with self._get_db() as conn:
row = conn.execute("SELECT * FROM kg_rag_configs WHERE id = ?", (rag_id,)).fetchone()
row = conn.execute("SELECT * FROM kg_rag_configs WHERE id = ?", (rag_id,)).fetchone()
if not row:
return None
@@ -724,11 +724,11 @@ class AIManager:
self, tenant_id: str, project_id: str | None = None
) -> list[KnowledgeGraphRAG]:
"""列出知识图谱 RAG 配置"""
query = "SELECT * FROM kg_rag_configs WHERE tenant_id = ?"
query = "SELECT * FROM kg_rag_configs WHERE tenant_id = ?"
params = [tenant_id]
if project_id:
query += " AND project_id = ?"
query += " AND project_id = ?"
params.append(project_id)
query += " ORDER BY created_at DESC"
@@ -1123,7 +1123,7 @@ class AIManager:
"""获取预测模型"""
with self._get_db() as conn:
row = conn.execute(
"SELECT * FROM prediction_models WHERE id = ?", (model_id,)
"SELECT * FROM prediction_models WHERE id = ?", (model_id,)
).fetchone()
if not row:
@@ -1135,11 +1135,11 @@ class AIManager:
self, tenant_id: str, project_id: str | None = None
) -> list[PredictionModel]:
"""列出预测模型"""
query = "SELECT * FROM prediction_models WHERE tenant_id = ?"
query = "SELECT * FROM prediction_models WHERE tenant_id = ?"
params = [tenant_id]
if project_id:
query += " AND project_id = ?"
query += " AND project_id = ?"
params.append(project_id)
query += " ORDER BY created_at DESC"
@@ -1168,8 +1168,8 @@ class AIManager:
conn.execute(
"""
UPDATE prediction_models
SET accuracy = ?, last_trained_at = ?, updated_at = ?
WHERE id = ?
SET accuracy = ?, last_trained_at = ?, updated_at = ?
WHERE id = ?
""",
(accuracy, now, now, model_id),
)
@@ -1238,7 +1238,7 @@ class AIManager:
# 更新预测计数
conn.execute(
"UPDATE prediction_models SET prediction_count = prediction_count + 1 WHERE id = ?",
"UPDATE prediction_models SET prediction_count = prediction_count + 1 WHERE id = ?",
(model_id,),
)
conn.commit()
@@ -1385,7 +1385,7 @@ class AIManager:
with self._get_db() as conn:
rows = conn.execute(
"""SELECT * FROM prediction_results
WHERE model_id = ?
WHERE model_id = ?
ORDER BY created_at DESC
LIMIT ?""",
(model_id, limit),
@@ -1400,8 +1400,8 @@ class AIManager:
with self._get_db() as conn:
conn.execute(
"""UPDATE prediction_results
SET actual_value = ?, is_correct = ?
WHERE id = ?""",
SET actual_value = ?, is_correct = ?
WHERE id = ?""",
(actual_value, is_correct, prediction_id),
)
conn.commit()