fix: auto-fix code issues (cron)
- 修复裸异常捕获 (E722) - 改为具体异常类型 - 修复重复导入/字段定义问题 - 修复PEP8格式问题 (W291 trailing whitespace, E226, E741) - 修复未使用变量 (F841) - 修复变量名遮蔽 (F402) - 修复未定义名称 (F821) - 添加 urllib.parse 导入 - 修复 f-string 缺少占位符 (F541) - 修复模块级导入位置 (E402) - 修复行尾空白和空行问题 - 优化代码结构,提升可读性
This commit is contained in:
@@ -251,7 +251,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO custom_models
|
||||
INSERT INTO custom_models
|
||||
(id, tenant_id, name, description, model_type, status, training_data,
|
||||
hyperparameters, metrics, model_path, created_at, updated_at, trained_at, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -321,7 +321,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO training_samples
|
||||
INSERT INTO training_samples
|
||||
(id, model_id, text, entities, metadata, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
@@ -391,7 +391,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE custom_models
|
||||
UPDATE custom_models
|
||||
SET status = ?, metrics = ?, model_path = ?, trained_at = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
@@ -448,7 +448,7 @@ class AIManager:
|
||||
try:
|
||||
entities = json.loads(json_match.group())
|
||||
return entities
|
||||
except:
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
|
||||
return []
|
||||
@@ -494,7 +494,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO multimodal_analyses
|
||||
INSERT INTO multimodal_analyses
|
||||
(id, tenant_id, project_id, provider, input_type, input_urls, prompt,
|
||||
result, tokens_used, cost, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -648,7 +648,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO kg_rag_configs
|
||||
INSERT INTO kg_rag_configs
|
||||
(id, tenant_id, project_id, name, description, kg_config, retrieval_config,
|
||||
generation_config, is_active, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -811,7 +811,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO rag_queries
|
||||
INSERT INTO rag_queries
|
||||
(id, rag_id, query, context, answer, sources, confidence, tokens_used, latency_ms, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
@@ -931,7 +931,7 @@ class AIManager:
|
||||
key_points = data.get("key_points", [])
|
||||
if "summary" in data:
|
||||
content = data["summary"]
|
||||
except:
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
|
||||
# 如果没有提取到关键要点,从文本中提取
|
||||
@@ -967,7 +967,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO smart_summaries
|
||||
INSERT INTO smart_summaries
|
||||
(id, tenant_id, project_id, source_type, source_id, summary_type, content,
|
||||
key_points, entities_mentioned, confidence, tokens_used, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -1027,7 +1027,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO prediction_models
|
||||
INSERT INTO prediction_models
|
||||
(id, tenant_id, project_id, name, prediction_type, target_entity_type, features,
|
||||
model_config, accuracy, last_trained_at, prediction_count, is_active, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -1095,7 +1095,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE prediction_models
|
||||
UPDATE prediction_models
|
||||
SET accuracy = ?, last_trained_at = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
@@ -1145,7 +1145,7 @@ class AIManager:
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO prediction_results
|
||||
INSERT INTO prediction_results
|
||||
(id, model_id, prediction_type, target_id, prediction_data, confidence,
|
||||
explanation, actual_value, is_correct, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -1270,7 +1270,7 @@ class AIManager:
|
||||
"current_count": counts[-1],
|
||||
"growth_rate": round(avg_growth_rate, 4),
|
||||
"confidence": min(0.9, 0.6 + len(entity_history) * 0.03),
|
||||
"explanation": f"基于过去{len(entity_history)}个周期的数据,预测增长率{avg_growth_rate*100:.1f}%",
|
||||
"explanation": f"基于过去{len(entity_history)}个周期的数据,预测增长率{avg_growth_rate * 100:.1f}%",
|
||||
}
|
||||
|
||||
def _predict_relation_evolution(self, input_data: Dict, model: PredictionModel) -> Dict:
|
||||
@@ -1303,9 +1303,9 @@ class AIManager:
|
||||
"""获取预测结果历史"""
|
||||
with self._get_db() as conn:
|
||||
rows = conn.execute(
|
||||
"""SELECT * FROM prediction_results
|
||||
WHERE model_id = ?
|
||||
ORDER BY created_at DESC
|
||||
"""SELECT * FROM prediction_results
|
||||
WHERE model_id = ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ?""",
|
||||
(model_id, limit),
|
||||
).fetchall()
|
||||
@@ -1316,8 +1316,8 @@ class AIManager:
|
||||
"""更新预测反馈(用于模型改进)"""
|
||||
with self._get_db() as conn:
|
||||
conn.execute(
|
||||
"""UPDATE prediction_results
|
||||
SET actual_value = ?, is_correct = ?
|
||||
"""UPDATE prediction_results
|
||||
SET actual_value = ?, is_correct = ?
|
||||
WHERE id = ?""",
|
||||
(actual_value, is_correct, prediction_id),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user