fix:llm测试修复给大模型提供的字段

This commit is contained in:
gongwenxin
2025-06-20 11:24:03 +08:00
parent 742079d6a4
commit ff71f2aed6
10 changed files with 13938 additions and 11003 deletions
+22 -11
View File
@@ -21,19 +21,30 @@ class LLMComplianceCheckTestCase(BaseAPITestCase):
def validate_response(self, response_context: APIResponseContext, request_context: APIRequestContext) -> List[ValidationResult]:
results = []
# 收集API所有关键信息
# 收集API所有关键信息,包括实例数据和Schema定义
api_info = {
# API元数据
"path_template": self.endpoint_spec.get("path"),
"method": request_context.method,
"url": request_context.url,
"path": self.endpoint_spec.get("path"),
"operationId": self.endpoint_spec.get("operationId"),
"headers": dict(request_context.headers) if hasattr(request_context, "headers") else {},
"query_params": getattr(request_context, "query_params", {}),
"path_params": getattr(request_context, "path_params", {}),
"body": getattr(request_context, "body", None),
"response_status": response_context.status_code,
"response_headers": dict(response_context.headers) if hasattr(response_context, "headers") else {},
"response_body": response_context.text_content if hasattr(response_context, "text_content") else None
# "operationId": self.endpoint_spec.get("operationId"),
"title": self.endpoint_spec.get("summary") or self.endpoint_spec.get("title"),
"description": self.endpoint_spec.get("description") or self.endpoint_spec.get("desc"),
"tags": self.endpoint_spec.get("tags"),
# API Schema 定义 (从 endpoint_spec 获取)
"schema_parameters": self.endpoint_spec.get("parameters"),
"schema_request_body": self.endpoint_spec.get("requestBody"),
"schema_responses": self.endpoint_spec.get("responses"),
# API 调用实例数据 (从 request_context 和 response_context 获取)
"instance_url": request_context.url,
"instance_request_headers": dict(request_context.headers) if hasattr(request_context, "headers") else {},
"instance_query_params": getattr(request_context, "query_params", {}),
"instance_path_params": getattr(request_context, "path_params", {}),
"instance_request_body": getattr(request_context, "body", None),
"instance_response_status": response_context.status_code,
"instance_response_headers": dict(response_context.headers) if hasattr(response_context, "headers") else {},
"instance_response_body": response_context.text_content if hasattr(response_context, "text_content") else None
}
# 日志打印所有API信息
self.logger.info("LLM合规性检查-API信息收集: " + json.dumps(api_info, ensure_ascii=False, indent=2))