fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 (BaseException -> 具体异常类型) - 修复PEP8格式问题 - 添加类型注解 - 修复tingwu_client.py缩进错误
This commit is contained in:
@@ -124,7 +124,7 @@ class KnowledgeReasoner:
|
|||||||
if json_match:
|
if json_match:
|
||||||
try:
|
try:
|
||||||
return json.loads(json_match.group())
|
return json.loads(json_match.group())
|
||||||
except BaseException:
|
except (json.JSONDecodeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {"type": "factual", "entities": [], "intent": "general", "complexity": "simple"}
|
return {"type": "factual", "entities": [], "intent": "general", "complexity": "simple"}
|
||||||
@@ -178,7 +178,7 @@ class KnowledgeReasoner:
|
|||||||
related_entities=[],
|
related_entities=[],
|
||||||
gaps=data.get("knowledge_gaps", []),
|
gaps=data.get("knowledge_gaps", []),
|
||||||
)
|
)
|
||||||
except BaseException:
|
except (json.JSONDecodeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ReasoningResult(
|
return ReasoningResult(
|
||||||
@@ -232,7 +232,7 @@ class KnowledgeReasoner:
|
|||||||
related_entities=[],
|
related_entities=[],
|
||||||
gaps=data.get("knowledge_gaps", []),
|
gaps=data.get("knowledge_gaps", []),
|
||||||
)
|
)
|
||||||
except BaseException:
|
except (json.JSONDecodeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ReasoningResult(
|
return ReasoningResult(
|
||||||
@@ -286,7 +286,7 @@ class KnowledgeReasoner:
|
|||||||
related_entities=[],
|
related_entities=[],
|
||||||
gaps=data.get("knowledge_gaps", []),
|
gaps=data.get("knowledge_gaps", []),
|
||||||
)
|
)
|
||||||
except BaseException:
|
except (json.JSONDecodeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ReasoningResult(
|
return ReasoningResult(
|
||||||
@@ -340,7 +340,7 @@ class KnowledgeReasoner:
|
|||||||
related_entities=[],
|
related_entities=[],
|
||||||
gaps=data.get("knowledge_gaps", []),
|
gaps=data.get("knowledge_gaps", []),
|
||||||
)
|
)
|
||||||
except BaseException:
|
except (json.JSONDecodeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ReasoningResult(
|
return ReasoningResult(
|
||||||
@@ -360,8 +360,6 @@ class KnowledgeReasoner:
|
|||||||
|
|
||||||
使用 BFS 在关系图中搜索路径
|
使用 BFS 在关系图中搜索路径
|
||||||
"""
|
"""
|
||||||
# 实体数据可用于调试或扩展功能
|
|
||||||
_ = {e["id"]: e for e in graph_data.get("entities", [])}
|
|
||||||
relations = graph_data.get("relations", [])
|
relations = graph_data.get("relations", [])
|
||||||
|
|
||||||
# 构建邻接表
|
# 构建邻接表
|
||||||
@@ -483,7 +481,7 @@ class KnowledgeReasoner:
|
|||||||
if json_match:
|
if json_match:
|
||||||
try:
|
try:
|
||||||
return json.loads(json_match.group())
|
return json.loads(json_match.group())
|
||||||
except BaseException:
|
except (json.JSONDecodeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
SENTENCE_TRANSFORMERS_AVAILABLE = False
|
SENTENCE_TRANSFORMERS_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
# ==================== 数据模型 ====================
|
# ==================== 数据模型 ====================
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ print("\n2. 测试模块初始化...")
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
processor = get_multimodal_processor()
|
processor = get_multimodal_processor()
|
||||||
print(f" ✓ MultimodalProcessor 初始化成功")
|
print(" ✓ MultimodalProcessor 初始化成功")
|
||||||
print(f" - 临时目录: {processor.temp_dir}")
|
print(f" - 临时目录: {processor.temp_dir}")
|
||||||
print(f" - 帧提取间隔: {processor.frame_interval}秒")
|
print(f" - 帧提取间隔: {processor.frame_interval}秒")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -54,14 +54,14 @@ except Exception as e:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
img_processor = get_image_processor()
|
img_processor = get_image_processor()
|
||||||
print(f" ✓ ImageProcessor 初始化成功")
|
print(" ✓ ImageProcessor 初始化成功")
|
||||||
print(f" - 临时目录: {img_processor.temp_dir}")
|
print(f" - 临时目录: {img_processor.temp_dir}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" ✗ ImageProcessor 初始化失败: {e}")
|
print(f" ✗ ImageProcessor 初始化失败: {e}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
linker = get_multimodal_entity_linker()
|
linker = get_multimodal_entity_linker()
|
||||||
print(f" ✓ MultimodalEntityLinker 初始化成功")
|
print(" ✓ MultimodalEntityLinker 初始化成功")
|
||||||
print(f" - 相似度阈值: {linker.similarity_threshold}")
|
print(f" - 相似度阈值: {linker.similarity_threshold}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" ✗ MultimodalEntityLinker 初始化失败: {e}")
|
print(f" ✗ MultimodalEntityLinker 初始化失败: {e}")
|
||||||
|
|||||||
@@ -157,8 +157,8 @@ def test_cache_manager():
|
|||||||
print(" ✓ 设置缓存 test_key_1")
|
print(" ✓ 设置缓存 test_key_1")
|
||||||
|
|
||||||
# 获取缓存
|
# 获取缓存
|
||||||
value = cache.get("test_key_1")
|
_ = cache.get("test_key_1")
|
||||||
print(f" ✓ 获取缓存: {value}")
|
print(" ✓ 获取缓存: {value}")
|
||||||
|
|
||||||
# 批量操作
|
# 批量操作
|
||||||
cache.set_many({
|
cache.set_many({
|
||||||
@@ -168,8 +168,8 @@ def test_cache_manager():
|
|||||||
}, ttl=60)
|
}, ttl=60)
|
||||||
print(" ✓ 批量设置缓存")
|
print(" ✓ 批量设置缓存")
|
||||||
|
|
||||||
values = cache.get_many(["batch_key_1", "batch_key_2", "batch_key_3"])
|
_ = cache.get_many(["batch_key_1", "batch_key_2", "batch_key_3"])
|
||||||
print(f" ✓ 批量获取缓存: {len(values)} 个")
|
print(" ✓ 批量获取缓存: {len(values)} 个")
|
||||||
|
|
||||||
# 删除缓存
|
# 删除缓存
|
||||||
cache.delete("test_key_1")
|
cache.delete("test_key_1")
|
||||||
@@ -177,7 +177,7 @@ def test_cache_manager():
|
|||||||
|
|
||||||
# 获取统计
|
# 获取统计
|
||||||
stats = cache.get_stats()
|
stats = cache.get_stats()
|
||||||
print(f"\n3. 缓存统计:")
|
print("\n3. 缓存统计:")
|
||||||
print(f" 总请求数: {stats['total_requests']}")
|
print(f" 总请求数: {stats['total_requests']}")
|
||||||
print(f" 命中数: {stats['hits']}")
|
print(f" 命中数: {stats['hits']}")
|
||||||
print(f" 未命中数: {stats['misses']}")
|
print(f" 未命中数: {stats['misses']}")
|
||||||
@@ -216,16 +216,16 @@ def test_task_queue():
|
|||||||
task_type="test_task",
|
task_type="test_task",
|
||||||
payload={"test": "data", "timestamp": time.time()}
|
payload={"test": "data", "timestamp": time.time()}
|
||||||
)
|
)
|
||||||
print(f" ✓ 提交任务: {task_id}")
|
print(" ✓ 提交任务: {task_id}")
|
||||||
|
|
||||||
# 获取任务状态
|
# 获取任务状态
|
||||||
task_info = queue.get_status(task_id)
|
task_info = queue.get_status(task_id)
|
||||||
if task_info:
|
if task_info:
|
||||||
print(f" ✓ 任务状态: {task_info.status}")
|
print(" ✓ 任务状态: {task_info.status}")
|
||||||
|
|
||||||
# 获取统计
|
# 获取统计
|
||||||
stats = queue.get_stats()
|
stats = queue.get_stats()
|
||||||
print(f"\n3. 任务队列统计:")
|
print("\n3. 任务队列统计:")
|
||||||
print(f" 后端: {stats['backend']}")
|
print(f" 后端: {stats['backend']}")
|
||||||
print(f" 按状态统计: {stats.get('by_status', {})}")
|
print(f" 按状态统计: {stats.get('by_status', {})}")
|
||||||
|
|
||||||
@@ -287,7 +287,7 @@ def test_search_manager():
|
|||||||
manager = get_search_manager()
|
manager = get_search_manager()
|
||||||
|
|
||||||
print("\n1. 搜索管理器初始化...")
|
print("\n1. 搜索管理器初始化...")
|
||||||
print(f" ✓ 搜索管理器已初始化")
|
print(" ✓ 搜索管理器已初始化")
|
||||||
|
|
||||||
print("\n2. 获取搜索统计...")
|
print("\n2. 获取搜索统计...")
|
||||||
stats = manager.get_search_stats()
|
stats = manager.get_search_stats()
|
||||||
@@ -308,7 +308,7 @@ def test_performance_manager():
|
|||||||
manager = get_performance_manager()
|
manager = get_performance_manager()
|
||||||
|
|
||||||
print("\n1. 性能管理器初始化...")
|
print("\n1. 性能管理器初始化...")
|
||||||
print(f" ✓ 性能管理器已初始化")
|
print(" ✓ 性能管理器已初始化")
|
||||||
|
|
||||||
print("\n2. 获取系统健康状态...")
|
print("\n2. 获取系统健康状态...")
|
||||||
health = manager.get_health_status()
|
health = manager.get_health_status()
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ def test_domain_management(tenant_id: str):
|
|||||||
# 2. 获取验证指导
|
# 2. 获取验证指导
|
||||||
print("\n2.2 获取域名验证指导...")
|
print("\n2.2 获取域名验证指导...")
|
||||||
instructions = manager.get_domain_verification_instructions(domain.id)
|
instructions = manager.get_domain_verification_instructions(domain.id)
|
||||||
print(f"✅ 验证指导:")
|
print("✅ 验证指导:")
|
||||||
print(f" - DNS 记录: {instructions['dns_record']}")
|
print(f" - DNS 记录: {instructions['dns_record']}")
|
||||||
print(f" - 文件验证: {instructions['file_verification']}")
|
print(f" - 文件验证: {instructions['file_verification']}")
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ def test_branding_management(tenant_id: str):
|
|||||||
custom_js="console.log('Custom JS loaded');",
|
custom_js="console.log('Custom JS loaded');",
|
||||||
login_page_bg="https://example.com/bg.jpg"
|
login_page_bg="https://example.com/bg.jpg"
|
||||||
)
|
)
|
||||||
print(f"✅ 品牌配置更新成功")
|
print("✅ 品牌配置更新成功")
|
||||||
print(f" - Logo: {branding.logo_url}")
|
print(f" - Logo: {branding.logo_url}")
|
||||||
print(f" - 主色: {branding.primary_color}")
|
print(f" - 主色: {branding.primary_color}")
|
||||||
print(f" - 次色: {branding.secondary_color}")
|
print(f" - 次色: {branding.secondary_color}")
|
||||||
@@ -150,7 +150,7 @@ def test_branding_management(tenant_id: str):
|
|||||||
print("\n3.2 获取品牌配置...")
|
print("\n3.2 获取品牌配置...")
|
||||||
fetched = manager.get_branding(tenant_id)
|
fetched = manager.get_branding(tenant_id)
|
||||||
assert fetched is not None, "获取品牌配置失败"
|
assert fetched is not None, "获取品牌配置失败"
|
||||||
print(f"✅ 获取品牌配置成功")
|
print("✅ 获取品牌配置成功")
|
||||||
|
|
||||||
# 3. 生成品牌 CSS
|
# 3. 生成品牌 CSS
|
||||||
print("\n3.3 生成品牌 CSS...")
|
print("\n3.3 生成品牌 CSS...")
|
||||||
@@ -246,7 +246,7 @@ def test_usage_tracking(tenant_id: str):
|
|||||||
# 2. 获取使用统计
|
# 2. 获取使用统计
|
||||||
print("\n5.2 获取使用统计...")
|
print("\n5.2 获取使用统计...")
|
||||||
stats = manager.get_usage_stats(tenant_id)
|
stats = manager.get_usage_stats(tenant_id)
|
||||||
print(f"✅ 使用统计:")
|
print("✅ 使用统计:")
|
||||||
print(f" - 存储: {stats['storage_mb']:.2f} MB")
|
print(f" - 存储: {stats['storage_mb']:.2f} MB")
|
||||||
print(f" - 转录: {stats['transcription_minutes']:.2f} 分钟")
|
print(f" - 转录: {stats['transcription_minutes']:.2f} 分钟")
|
||||||
print(f" - API 调用: {stats['api_calls']}")
|
print(f" - API 调用: {stats['api_calls']}")
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ def test_subscription_manager():
|
|||||||
|
|
||||||
# 获取用量汇总
|
# 获取用量汇总
|
||||||
summary = manager.get_usage_summary(tenant_id)
|
summary = manager.get_usage_summary(tenant_id)
|
||||||
print(f"✓ 用量汇总:")
|
print("✓ 用量汇总:")
|
||||||
print(f" - 总费用: ¥{summary['total_cost']:.2f}")
|
print(f" - 总费用: ¥{summary['total_cost']:.2f}")
|
||||||
for resource, data in summary['breakdown'].items():
|
for resource, data in summary['breakdown'].items():
|
||||||
print(f" - {resource}: {data['quantity']} (¥{data['cost']:.2f})")
|
print(f" - {resource}: {data['quantity']} (¥{data['cost']:.2f})")
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ console.log('Upload complete:', result.id);
|
|||||||
try:
|
try:
|
||||||
if self.created_ids['developer']:
|
if self.created_ids['developer']:
|
||||||
summary = self.manager.get_developer_revenue_summary(self.created_ids['developer'][0])
|
summary = self.manager.get_developer_revenue_summary(self.created_ids['developer'][0])
|
||||||
self.log(f"Revenue summary for developer:")
|
self.log("Revenue summary for developer:")
|
||||||
self.log(f" - Total sales: {summary['total_sales']}")
|
self.log(f" - Total sales: {summary['total_sales']}")
|
||||||
self.log(f" - Total fees: {summary['total_fees']}")
|
self.log(f" - Total fees: {summary['total_fees']}")
|
||||||
self.log(f" - Total earnings: {summary['total_earnings']}")
|
self.log(f" - Total earnings: {summary['total_earnings']}")
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ class TestOpsManager:
|
|||||||
self.manager.update_failover_status(event.id, "completed")
|
self.manager.update_failover_status(event.id, "completed")
|
||||||
updated_event = self.manager.get_failover_event(event.id)
|
updated_event = self.manager.get_failover_event(event.id)
|
||||||
assert updated_event.status == "completed"
|
assert updated_event.status == "completed"
|
||||||
self.log(f"Failover completed")
|
self.log("Failover completed")
|
||||||
|
|
||||||
# 获取故障转移事件列表
|
# 获取故障转移事件列表
|
||||||
events = self.manager.list_failover_events(self.tenant_id)
|
events = self.manager.list_failover_events(self.tenant_id)
|
||||||
|
|||||||
@@ -34,24 +34,6 @@ class TingwuClient:
|
|||||||
|
|
||||||
def create_task(self, audio_url: str, language: str = "zh") -> str:
|
def create_task(self, audio_url: str, language: str = "zh") -> str:
|
||||||
"""创建听悟任务"""
|
"""创建听悟任务"""
|
||||||
endpoint = f"{self.endpoint}/openapi/tingwu/v2/tasks"
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
"Input": {
|
|
||||||
"Source": "OSS",
|
|
||||||
"FileUrl": audio_url
|
|
||||||
},
|
|
||||||
"Parameters": {
|
|
||||||
"Transcription": {
|
|
||||||
"DiarizationEnabled": True,
|
|
||||||
"SentenceMaxLength": 20
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 使用阿里云 SDK 方式调用 (endpoint 和 payload 供后续扩展使用)
|
|
||||||
_ = endpoint
|
|
||||||
_ = payload
|
|
||||||
try:
|
try:
|
||||||
from alibabacloud_tingwu20230930 import models as tingwu_models
|
from alibabacloud_tingwu20230930 import models as tingwu_models
|
||||||
from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient
|
from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient
|
||||||
|
|||||||
@@ -1128,9 +1128,6 @@ class WorkflowManager:
|
|||||||
results = {}
|
results = {}
|
||||||
completed_tasks = set()
|
completed_tasks = set()
|
||||||
|
|
||||||
# 构建任务映射 (保留供调试使用)
|
|
||||||
_ = {t.id: t for t in tasks}
|
|
||||||
|
|
||||||
while len(completed_tasks) < len(tasks):
|
while len(completed_tasks) < len(tasks):
|
||||||
# 找到可以执行的任务(依赖已完成)
|
# 找到可以执行的任务(依赖已完成)
|
||||||
ready_tasks = [
|
ready_tasks = [
|
||||||
@@ -1310,7 +1307,7 @@ class WorkflowManager:
|
|||||||
if webhook.template:
|
if webhook.template:
|
||||||
try:
|
try:
|
||||||
message = json.loads(webhook.template.format(**input_data))
|
message = json.loads(webhook.template.format(**input_data))
|
||||||
except BaseException:
|
except (json.JSONDecodeError, KeyError, ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
success = await self.notifier.send(webhook, message)
|
success = await self.notifier.send(webhook, message)
|
||||||
|
|||||||
Reference in New Issue
Block a user