|
|
@@ -290,37 +290,22 @@ class RulesEngineMetricCalculationAgent:
|
|
|
try:
|
|
|
response_data = response.json()
|
|
|
|
|
|
- # 记录API调用结果
|
|
|
+ # 记录API调用结果 - 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{config_name}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": config_name,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
- "response": {
|
|
|
- "status_code": response.status_code,
|
|
|
- "data": response_data,
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": True
|
|
|
+ "response": response_data
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
- api_results_dir = "api_results"
|
|
|
+ # 保存API结果到文件 - 成功状态
|
|
|
+ # 使用运行ID创建独立的文件夹
|
|
|
+ run_id = os.environ.get('FLOW_RUN_ID', 'default')
|
|
|
+ api_results_dir = f"api_results_{run_id}"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
- filename = f"{timestamp}_{call_id}.json"
|
|
|
+ filename = f"{timestamp}_{call_id}_success.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -336,38 +321,26 @@ class RulesEngineMetricCalculationAgent:
|
|
|
"status_code": response.status_code
|
|
|
}
|
|
|
except json.JSONDecodeError:
|
|
|
- # 记录API调用结果(JSON解析失败)
|
|
|
+ # 记录API调用结果(JSON解析失败)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{config_name}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": config_name,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
"status_code": response.status_code,
|
|
|
"data": response.text,
|
|
|
- "error": "JSON解析失败",
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": "JSON解析失败"
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
- api_results_dir = "api_results"
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
+ # 使用运行ID创建独立的文件夹
|
|
|
+ run_id = os.environ.get('FLOW_RUN_ID', 'default')
|
|
|
+ api_results_dir = f"api_results_{run_id}"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
- filename = f"{timestamp}_{call_id}.json"
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -383,36 +356,25 @@ class RulesEngineMetricCalculationAgent:
|
|
|
"status_code": response.status_code
|
|
|
}
|
|
|
else:
|
|
|
- # 记录API调用结果(HTTP错误)
|
|
|
+ # 记录API调用结果(HTTP错误)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{config_name}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": config_name,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
"status_code": response.status_code,
|
|
|
- "error": response.text,
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": response.text
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
- api_results_dir = "api_results"
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
+ # 使用运行ID创建独立的文件夹
|
|
|
+ run_id = os.environ.get('FLOW_RUN_ID', 'default')
|
|
|
+ api_results_dir = f"api_results_{run_id}"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
- filename = f"{call_id}.json"
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -429,91 +391,91 @@ class RulesEngineMetricCalculationAgent:
|
|
|
}
|
|
|
|
|
|
except requests.exceptions.Timeout:
|
|
|
- # 记录API调用结果(超时)
|
|
|
+ # 记录API调用结果(超时)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{config_name}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": config_name,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data if 'json_data' in locals() else None,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
- "error": "API调用超时",
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": "API调用超时"
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
+ api_results_dir = "api_results"
|
|
|
+ os.makedirs(api_results_dir, exist_ok=True)
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
+ filepath = os.path.join(api_results_dir, filename)
|
|
|
+
|
|
|
+ try:
|
|
|
+ with open(filepath, 'w', encoding='utf-8') as f:
|
|
|
+ json.dump(api_call_info, f, ensure_ascii=False, indent=2)
|
|
|
+ print(f"[RULES_API_RESULT] 保存规则引擎API结果文件: {filepath}")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"[ERROR] 保存规则引擎API结果文件失败: {filepath}, 错误: {str(e)}")
|
|
|
+
|
|
|
return {
|
|
|
"success": False,
|
|
|
"message": "规则引擎API调用超时"
|
|
|
}
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
- # 记录API调用结果(请求异常)
|
|
|
+ # 记录API调用结果(请求异常)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{config_name}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": config_name,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data if 'json_data' in locals() else None,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
- "error": str(e),
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": str(e)
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
+ api_results_dir = "api_results"
|
|
|
+ os.makedirs(api_results_dir, exist_ok=True)
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
+ filepath = os.path.join(api_results_dir, filename)
|
|
|
+
|
|
|
+ try:
|
|
|
+ with open(filepath, 'w', encoding='utf-8') as f:
|
|
|
+ json.dump(api_call_info, f, ensure_ascii=False, indent=2)
|
|
|
+ print(f"[RULES_API_RESULT] 保存规则引擎API结果文件: {filepath}")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"[ERROR] 保存规则引擎API结果文件失败: {filepath}, 错误: {str(e)}")
|
|
|
+
|
|
|
return {
|
|
|
"success": False,
|
|
|
"message": f"规则引擎API调用异常: {str(e)}"
|
|
|
}
|
|
|
except Exception as e:
|
|
|
- # 记录API调用结果(其他异常)
|
|
|
+ # 记录API调用结果(其他异常)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{config_name}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": config_name,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data if 'json_data' in locals() else None,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
- "error": str(e),
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": str(e)
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
+ api_results_dir = "api_results"
|
|
|
+ os.makedirs(api_results_dir, exist_ok=True)
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
+ filepath = os.path.join(api_results_dir, filename)
|
|
|
+
|
|
|
+ try:
|
|
|
+ with open(filepath, 'w', encoding='utf-8') as f:
|
|
|
+ json.dump(api_call_info, f, ensure_ascii=False, indent=2)
|
|
|
+ print(f"[RULES_API_RESULT] 保存规则引擎API结果文件: {filepath}")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"[ERROR] 保存规则引擎API结果文件失败: {filepath}, 错误: {str(e)}")
|
|
|
+
|
|
|
return {
|
|
|
"success": False,
|
|
|
"message": f"处理规则引擎API调用时发生错误: {str(e)}"
|
|
|
@@ -621,37 +583,22 @@ class RulesEngineMetricCalculationAgent:
|
|
|
try:
|
|
|
response_data = response.json()
|
|
|
|
|
|
- # 记录API调用结果
|
|
|
+ # 记录API调用结果 - 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{knowledge_id}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": knowledge_id,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
- "response": {
|
|
|
- "status_code": response.status_code,
|
|
|
- "data": response_data,
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": True
|
|
|
+ "response": response_data
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
- api_results_dir = "api_results"
|
|
|
+ # 保存API结果到文件 - 成功状态
|
|
|
+ # 使用运行ID创建独立的文件夹
|
|
|
+ run_id = os.environ.get('FLOW_RUN_ID', 'default')
|
|
|
+ api_results_dir = f"api_results_{run_id}"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
- filename = f"{timestamp}_{call_id}.json"
|
|
|
+ filename = f"{timestamp}_{call_id}_success.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -667,38 +614,26 @@ class RulesEngineMetricCalculationAgent:
|
|
|
"status_code": response.status_code
|
|
|
}
|
|
|
except json.JSONDecodeError:
|
|
|
- # 记录JSON解析失败的API调用
|
|
|
+ # 记录JSON解析失败的API调用 - 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{knowledge_id}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": knowledge_id,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
"status_code": response.status_code,
|
|
|
"data": response.text,
|
|
|
- "error": "JSON解析失败",
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": "JSON解析失败"
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
- api_results_dir = "api_results"
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
+ # 使用运行ID创建独立的文件夹
|
|
|
+ run_id = os.environ.get('FLOW_RUN_ID', 'default')
|
|
|
+ api_results_dir = f"api_results_{run_id}"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
- filename = f"{timestamp}_{call_id}.json"
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -714,36 +649,25 @@ class RulesEngineMetricCalculationAgent:
|
|
|
"status_code": response.status_code
|
|
|
}
|
|
|
else:
|
|
|
- # 记录失败的API调用
|
|
|
+ # 记录失败的API调用 - 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{knowledge_id}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": knowledge_id,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
"status_code": response.status_code,
|
|
|
- "error": response.text,
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": response.text
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
- api_results_dir = "api_results"
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
+ # 使用运行ID创建独立的文件夹
|
|
|
+ run_id = os.environ.get('FLOW_RUN_ID', 'default')
|
|
|
+ api_results_dir = f"api_results_{run_id}"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
- filename = f"{call_id}.json"
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -760,35 +684,22 @@ class RulesEngineMetricCalculationAgent:
|
|
|
}
|
|
|
|
|
|
except requests.exceptions.Timeout:
|
|
|
- # 记录API调用结果(超时)
|
|
|
+ # 记录API调用结果(超时)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{knowledge_id}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": knowledge_id,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data if 'json_data' in locals() else None,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
- "error": "API调用超时",
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": "API调用超时"
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
api_results_dir = "api_results"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
- filename = f"{call_id}.json"
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -803,35 +714,22 @@ class RulesEngineMetricCalculationAgent:
|
|
|
"message": "规则引擎API调用超时"
|
|
|
}
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
- # 记录API调用结果(请求异常)
|
|
|
+ # 记录API调用结果(请求异常)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{knowledge_id}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": knowledge_id,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data if 'json_data' in locals() else None,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
- "error": str(e),
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": str(e)
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
api_results_dir = "api_results"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
- filename = f"{call_id}.json"
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|
|
|
@@ -846,35 +744,22 @@ class RulesEngineMetricCalculationAgent:
|
|
|
"message": f"规则引擎API调用异常: {str(e)}"
|
|
|
}
|
|
|
except Exception as e:
|
|
|
- # 记录API调用结果(其他异常)
|
|
|
+ # 记录API调用结果(其他异常)- 简化版
|
|
|
end_time = datetime.now()
|
|
|
call_id = f"rules_api_{knowledge_id}_{'{:.2f}'.format((end_time - start_time).total_seconds())}"
|
|
|
api_call_info = {
|
|
|
"call_id": call_id,
|
|
|
- "timestamp": end_time.isoformat(),
|
|
|
- "agent": "RulesEngineMetricCalculationAgent",
|
|
|
- "api_endpoint": url,
|
|
|
- "config_name": knowledge_id,
|
|
|
- "request": {
|
|
|
- "method": method,
|
|
|
- "url": url,
|
|
|
- "headers": headers,
|
|
|
- "json_data": json_data if 'json_data' in locals() else None,
|
|
|
- "start_time": start_time.isoformat()
|
|
|
- },
|
|
|
"response": {
|
|
|
- "error": str(e),
|
|
|
- "end_time": end_time.isoformat(),
|
|
|
- "duration": (end_time - start_time).total_seconds()
|
|
|
- },
|
|
|
- "success": False
|
|
|
+ "error": str(e)
|
|
|
+ }
|
|
|
}
|
|
|
self.api_calls.append(api_call_info)
|
|
|
|
|
|
- # 保存API结果到文件
|
|
|
+ # 保存API结果到文件 - 失败状态
|
|
|
api_results_dir = "api_results"
|
|
|
os.makedirs(api_results_dir, exist_ok=True)
|
|
|
- filename = f"{call_id}.json"
|
|
|
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
+ filename = f"{timestamp}_{call_id}_fail.json"
|
|
|
filepath = os.path.join(api_results_dir, filename)
|
|
|
|
|
|
try:
|