fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解 - 修复main.py中的语法错误(缺失try语句的from导入) - 添加缺失的timedelta导入到plugin_manager.py - 添加缺失的urllib.parse导入到plugin_manager.py和workflow_manager.py - 添加缺失的os导入到document_processor.py - 修复import排序问题 - 修复行长度超过100字符的问题 - 添加缺失的Alert导入到test_phase8_task8.py - 添加缺失的get_export_manager导入到main.py
This commit is contained in:
@@ -428,7 +428,8 @@ class AIManager:
|
||||
|
||||
文本: {text}
|
||||
|
||||
以 JSON 格式返回实体列表: [{{"text": "实体文本", "label": "类型", "start": 0, "end": 5, "confidence": 0.95}}]
|
||||
以 JSON 格式返回实体列表: [{{"text": "实体文本", "label": "类型",
|
||||
"start": 0, "end": 5, "confidence": 0.95}}]
|
||||
只返回 JSON 数组,不要其他内容。"""
|
||||
|
||||
headers = {
|
||||
@@ -603,7 +604,10 @@ class AIManager:
|
||||
# Kimi 目前可能不支持真正的多模态,这里模拟返回
|
||||
# 实际实现时需要根据 Kimi API 更新
|
||||
|
||||
content = f"图片 URL: {', '.join(image_urls)}\n\n{prompt}\n\n注意:请基于图片 URL 描述的内容进行回答。"
|
||||
content = (
|
||||
f"图片 URL: {', '.join(image_urls)}\n\n{prompt}\n\n"
|
||||
"注意:请基于图片 URL 描述的内容进行回答。"
|
||||
)
|
||||
|
||||
payload = {
|
||||
"model": "k2p5",
|
||||
@@ -1319,7 +1323,10 @@ class AIManager:
|
||||
"mean": round(mean, 2),
|
||||
"std": round(std, 2),
|
||||
"confidence": min(0.95, 0.7 + len(historical_values) * 0.01),
|
||||
"explanation": f"当前值偏离均值{z_score:.2f}个标准差,{'检测到异常' if is_anomaly else '处于正常范围'}",
|
||||
"explanation": (
|
||||
f"当前值偏离均值{z_score:.2f}个标准差,"
|
||||
f"{'检测到异常' if is_anomaly else '处于正常范围'}"
|
||||
),
|
||||
}
|
||||
|
||||
def _predict_entity_growth(self, input_data: dict, model: PredictionModel) -> dict:
|
||||
@@ -1349,7 +1356,10 @@ 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)}个周期的数据,"
|
||||
f"预测增长率{avg_growth_rate * 100:.1f}%"
|
||||
),
|
||||
}
|
||||
|
||||
def _predict_relation_evolution(self, input_data: dict, model: PredictionModel) -> dict:
|
||||
|
||||
@@ -11,6 +11,7 @@ from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
|
||||
class SharePermission(Enum):
|
||||
"""分享权限级别"""
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ Document Processor - Phase 3
|
||||
import io
|
||||
import os
|
||||
|
||||
|
||||
class DocumentProcessor:
|
||||
"""文档处理器 - 提取 PDF/DOCX 文本"""
|
||||
|
||||
|
||||
@@ -340,7 +340,9 @@ class KnowledgeReasoner:
|
||||
"answer": "关联分析结果",
|
||||
"direct_connections": ["直接关联1"],
|
||||
"indirect_connections": ["间接关联1"],
|
||||
"inferred_relations": [{{"source": "A", "target": "B", "relation": "可能关系", "confidence": 0.7}}],
|
||||
"inferred_relations": [
|
||||
{{"source": "A", "target": "B", "relation": "可能关系", "confidence": 0.7}}
|
||||
],
|
||||
"confidence": 0.85,
|
||||
"evidence": ["证据1"],
|
||||
"knowledge_gaps": []
|
||||
|
||||
@@ -18,7 +18,6 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, Optional
|
||||
|
||||
import httpx
|
||||
from export_manager import ExportEntity, ExportRelation, ExportTranscript
|
||||
from fastapi import (
|
||||
Body,
|
||||
Depends,
|
||||
@@ -36,6 +35,13 @@ from fastapi.responses import JSONResponse, PlainTextResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from export_manager import (
|
||||
ExportEntity,
|
||||
ExportRelation,
|
||||
ExportTranscript,
|
||||
get_export_manager,
|
||||
)
|
||||
|
||||
# Configure logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -140,7 +146,7 @@ except ImportError as e:
|
||||
|
||||
# Phase 7: Workflow Manager
|
||||
try:
|
||||
from workflow_manager import WebhookConfig, Workflow
|
||||
from workflow_manager import WebhookConfig, Workflow, WorkflowManager
|
||||
|
||||
WORKFLOW_AVAILABLE = True
|
||||
except ImportError as e:
|
||||
@@ -174,10 +180,13 @@ except ImportError as e:
|
||||
|
||||
# Phase 7 Task 7: Plugin Manager
|
||||
try:
|
||||
from plugin_manager import (
|
||||
BotHandler,
|
||||
Plugin,
|
||||
PluginManager,
|
||||
PluginStatus,
|
||||
PluginType,
|
||||
WebDAVSyncHandler,
|
||||
WebhookIntegration,
|
||||
get_plugin_manager,
|
||||
)
|
||||
@@ -299,10 +308,12 @@ except ImportError as e:
|
||||
|
||||
# Phase 8 Task 8: Operations & Monitoring Manager
|
||||
try:
|
||||
from ops_manager import (
|
||||
AlertChannelType,
|
||||
AlertRuleType,
|
||||
AlertSeverity,
|
||||
AlertStatus,
|
||||
OpsManager,
|
||||
ResourceType,
|
||||
get_ops_manager,
|
||||
)
|
||||
@@ -1933,7 +1944,10 @@ async def agent_command(project_id: str, command: AgentCommand, _=Depends(verify
|
||||
else:
|
||||
result["action"] = "none"
|
||||
result["message"] = (
|
||||
"无法理解的指令,请尝试:\n- 合并实体:把所有'客户端'合并到'App'\n- 提问:张总对项目的态度如何?\n- 编辑:修改'K8s'的定义为..."
|
||||
"无法理解的指令,请尝试:\n"
|
||||
"- 合并实体:把所有'客户端'合并到'App'\n"
|
||||
"- 提问:张总对项目的态度如何?\n"
|
||||
"- 编辑:修改'K8s'的定义为..."
|
||||
)
|
||||
|
||||
return result
|
||||
@@ -4176,12 +4190,18 @@ async def test_webhook_endpoint(webhook_id: str, _=Depends(verify_api_key)):
|
||||
|
||||
# 构建测试消息
|
||||
test_message = {
|
||||
"content": "🔔 这是来自 InsightFlow 的 Webhook 测试消息\n\n如果您收到这条消息,说明 Webhook 配置正确!",
|
||||
"content": (
|
||||
"🔔 这是来自 InsightFlow 的 Webhook 测试消息\n\n"
|
||||
"如果您收到这条消息,说明 Webhook 配置正确!"
|
||||
),
|
||||
}
|
||||
|
||||
if webhook.webhook_type == "slack":
|
||||
test_message = {
|
||||
"text": "🔔 这是来自 InsightFlow 的 Webhook 测试消息\n\n如果您收到这条消息,说明 Webhook 配置正确!",
|
||||
"text": (
|
||||
"🔔 这是来自 InsightFlow 的 Webhook 测试消息\n\n"
|
||||
"如果您收到这条消息,说明 Webhook 配置正确!"
|
||||
),
|
||||
}
|
||||
|
||||
success = await manager.notifier.send(webhook, test_message)
|
||||
|
||||
@@ -1739,7 +1739,10 @@ class OpsManager:
|
||||
elif current_utilization < policy.scale_down_threshold:
|
||||
if current_instances > policy.min_instances:
|
||||
action = ScalingAction.SCALE_DOWN
|
||||
reason = f"利用率 {current_utilization:.1%} 低于缩容阈值 {policy.scale_down_threshold:.1%}"
|
||||
reason = (
|
||||
f"利用率 {current_utilization:.1%} 低于缩容阈值 "
|
||||
f"{policy.scale_down_threshold:.1%}"
|
||||
)
|
||||
|
||||
if action:
|
||||
if action == ScalingAction.SCALE_UP:
|
||||
|
||||
@@ -9,6 +9,7 @@ from datetime import datetime
|
||||
|
||||
import oss2
|
||||
|
||||
|
||||
class OSSUploader:
|
||||
def __init__(self) -> None:
|
||||
self.access_key = os.getenv("ALI_ACCESS_KEY")
|
||||
|
||||
@@ -11,9 +11,10 @@ import json
|
||||
import os
|
||||
import sqlite3
|
||||
import time
|
||||
import urllib.parse
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from functools import wraps
|
||||
|
||||
|
||||
@dataclass
|
||||
class RateLimitConfig:
|
||||
"""限流配置"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class SearchOperator(Enum):
|
||||
"""搜索操作符"""
|
||||
|
||||
@@ -1779,10 +1780,16 @@ class KnowledgeGapDetection:
|
||||
gap_type="missing_attribute",
|
||||
entity_id=entity_id,
|
||||
entity_name=entity["name"],
|
||||
description=f"实体 '{entity['name']}' 缺少必需属性: {', '.join(missing_names)}",
|
||||
description=(
|
||||
f"实体 '{entity['name']}' 缺少必需属性: "
|
||||
f"{', '.join(missing_names)}"
|
||||
),
|
||||
severity="medium",
|
||||
suggestions=[
|
||||
f"为实体 '{entity['name']}' 补充以下属性: {', '.join(missing_names)}",
|
||||
(
|
||||
f"为实体 '{entity['name']}' 补充以下属性: "
|
||||
f"{', '.join(missing_names)}"
|
||||
),
|
||||
"检查属性模板定义是否合理",
|
||||
],
|
||||
related_entities=[],
|
||||
@@ -1842,7 +1849,10 @@ class KnowledgeGapDetection:
|
||||
gap_type="sparse_relation",
|
||||
entity_id=entity_id,
|
||||
entity_name=entity["name"],
|
||||
description=f"实体 '{entity['name']}' 关系稀疏(仅有 {relation_count} 个关系)",
|
||||
description=(
|
||||
f"实体 '{entity['name']}' 关系稀疏"
|
||||
f"(仅有 {relation_count} 个关系)"
|
||||
),
|
||||
severity="medium" if relation_count == 0 else "low",
|
||||
suggestions=[
|
||||
f"检查转录文本中提及 '{entity['name']}' 的其他实体",
|
||||
|
||||
@@ -800,8 +800,14 @@ class TenantManager:
|
||||
"content": token,
|
||||
},
|
||||
"instructions": [
|
||||
f"DNS 验证: 添加 TXT 记录 _insightflow.{domain},值为 insightflow-verify = {token}",
|
||||
f"文件验证: 在网站根目录创建 .well-known/insightflow-verify.txt,内容为 {token}",
|
||||
(
|
||||
f"DNS 验证: 添加 TXT 记录 _insightflow.{domain},"
|
||||
f"值为 insightflow-verify = {token}"
|
||||
),
|
||||
(
|
||||
f"文件验证: 在网站根目录创建 "
|
||||
f".well-known/insightflow-verify.txt,内容为 {token}"
|
||||
),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -532,7 +532,10 @@ client = Client(api_key = "your_api_key")
|
||||
project = client.projects.create(name = "My Project")
|
||||
print(f"Created project: {project.id}")
|
||||
""",
|
||||
explanation="首先导入 Client 类,然后使用 API Key 初始化客户端,最后调用 create 方法创建项目。",
|
||||
explanation=(
|
||||
"首先导入 Client 类,然后使用 API Key 初始化客户端,"
|
||||
"最后调用 create 方法创建项目。"
|
||||
),
|
||||
tags=["python", "quickstart", "projects"],
|
||||
author_id="dev_001",
|
||||
author_name="InsightFlow Team",
|
||||
|
||||
@@ -17,6 +17,7 @@ import sys
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from ops_manager import (
|
||||
Alert,
|
||||
AlertChannelType,
|
||||
AlertRuleType,
|
||||
AlertSeverity,
|
||||
|
||||
@@ -8,6 +8,7 @@ import time
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
|
||||
class TingwuClient:
|
||||
def __init__(self) -> None:
|
||||
self.access_key = os.getenv("ALI_ACCESS_KEY", "")
|
||||
|
||||
@@ -15,6 +15,7 @@ import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import logging
|
||||
import urllib.parse
|
||||
import uuid
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
Reference in New Issue
Block a user