|
|
@@ -191,12 +191,13 @@ class RulesEngineMetricCalculationAgent:
|
|
|
print(f"⚠️ 未找到知识 {knowledge_id} 的输入字段,使用默认值: transactions")
|
|
|
return "transactions" # 默认值
|
|
|
|
|
|
- async def calculate_metrics(self, intent_result: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
+ async def calculate_metrics(self, intent_result: Dict[str, Any], classified_data: List[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
|
"""
|
|
|
根据意图识别结果进行规则引擎指标计算
|
|
|
|
|
|
Args:
|
|
|
intent_result: 意图识别结果
|
|
|
+ classified_data: 分类后的数据,如果提供则优先使用,否则从intent_result或文件加载
|
|
|
|
|
|
Returns:
|
|
|
指标计算结果
|
|
|
@@ -223,7 +224,7 @@ class RulesEngineMetricCalculationAgent:
|
|
|
})
|
|
|
elif config_name.startswith("metric-"):
|
|
|
# 直接使用知识ID调用API,无需配置文件
|
|
|
- result = await self._call_rules_engine_api_by_knowledge_id(config_name, intent_result)
|
|
|
+ result = await self._call_rules_engine_api_by_knowledge_id(config_name, intent_result, classified_data)
|
|
|
results.append({
|
|
|
"config_name": config_name,
|
|
|
"result": result
|
|
|
@@ -551,13 +552,14 @@ class RulesEngineMetricCalculationAgent:
|
|
|
|
|
|
return {"json": request_data}
|
|
|
|
|
|
- async def _call_rules_engine_api_by_knowledge_id(self, knowledge_id: str, intent_result: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
+ async def _call_rules_engine_api_by_knowledge_id(self, knowledge_id: str, intent_result: Dict[str, Any], classified_data: List[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
|
"""
|
|
|
直接通过知识ID调用规则引擎API
|
|
|
|
|
|
Args:
|
|
|
knowledge_id: 知识ID,如 "metric-分析账户数量"
|
|
|
intent_result: 意图识别结果(用于获取数据文件信息)
|
|
|
+ classified_data: 分类后的数据,如果提供则优先使用,否则从intent_result或文件加载
|
|
|
|
|
|
Returns:
|
|
|
API调用结果
|
|
|
@@ -581,21 +583,28 @@ class RulesEngineMetricCalculationAgent:
|
|
|
# 根据知识ID获取正确的输入字段名
|
|
|
input_field_name = self._get_input_field_for_knowledge(knowledge_id)
|
|
|
|
|
|
- # 构造请求数据 - 直接使用默认数据文件
|
|
|
- # 从intent_result中获取数据文件名,如果没有则使用默认的农业数据
|
|
|
- input_filename = intent_result.get("data_file", "加工数据-流水分析-农业打标.json")
|
|
|
-
|
|
|
- # 加载对应的数据文件
|
|
|
+ # 构造请求数据 - 优先使用传入的分类后数据
|
|
|
input_data = {}
|
|
|
- if input_filename:
|
|
|
- data_file_path = self._select_data_file(input_filename)
|
|
|
- if data_file_path:
|
|
|
- raw_data = self._load_table_data(data_file_path)
|
|
|
- # 使用正确的字段名包装数据
|
|
|
- input_data = {input_field_name: raw_data}
|
|
|
- else:
|
|
|
- print(f"警告:找不到数据文件: {input_filename}")
|
|
|
- input_data = {input_field_name: []}
|
|
|
+
|
|
|
+ # 检查是否有传入的分类后数据
|
|
|
+ if classified_data and len(classified_data) > 0:
|
|
|
+ # 使用传入的分类后数据
|
|
|
+ print(f" 使用传入的分类后数据,记录数: {len(classified_data)}")
|
|
|
+ input_data = {input_field_name: classified_data}
|
|
|
+ else:
|
|
|
+ # 回退到文件加载方式(向后兼容)
|
|
|
+ input_filename = intent_result.get("data_file", "加工数据-流水分析-农业打标.json")
|
|
|
+ print(f" 未找到分类后数据,回退到文件加载: {input_filename}")
|
|
|
+
|
|
|
+ if input_filename:
|
|
|
+ data_file_path = self._select_data_file(input_filename)
|
|
|
+ if data_file_path:
|
|
|
+ raw_data = self._load_table_data(data_file_path)
|
|
|
+ # 使用正确的字段名包装数据
|
|
|
+ input_data = {input_field_name: raw_data}
|
|
|
+ else:
|
|
|
+ print(f"警告:找不到数据文件: {input_filename}")
|
|
|
+ input_data = {input_field_name: []}
|
|
|
|
|
|
# 构造API请求体
|
|
|
request_data = {
|