1.排程管理功能更新,支持数据源配置以及自定义查询条件测试
2.应用管理增加Dify应用类型,支持不同类型下的连通性测试
This commit is contained in:
1 parent
72642b981e
commit
6ada6810c5
18 files changed
+2185
-535
No files matched your search
+64
-22
@@ -380,7 +380,7 @@ def delete_agent(id):
|
||||
@require_admin
|
||||
def test_agent(id):
|
||||
"""
|
||||
测试应用连通性与基础响应质量。
|
||||
测试应用连通性。
|
||||
返回:请求地址、输出信息、结果分析。
|
||||
若测试通过,则自动将应用状态置为启用。
|
||||
"""
|
||||
@@ -446,14 +446,29 @@ def test_agent(id):
|
||||
'tested_at': tested_at
|
||||
}), 400
|
||||
|
||||
request_url = DifyService._build_chat_messages_url(base_url)
|
||||
payload = {
|
||||
'inputs': {},
|
||||
'query': '系统连通性测试,请简短回复OK。',
|
||||
'response_mode': 'blocking',
|
||||
'conversation_id': '',
|
||||
'user': 'admin_test'
|
||||
}
|
||||
extra_config = agent.extra_config or {}
|
||||
dify_app_type = str(extra_config.get('dify_app_type') or 'chatflow').strip().lower()
|
||||
if dify_app_type not in ('chatflow', 'workflow'):
|
||||
dify_app_type = 'chatflow'
|
||||
|
||||
if dify_app_type == 'workflow':
|
||||
request_url = DifyService._build_workflow_url(base_url)
|
||||
payload = {
|
||||
'inputs': {
|
||||
'query': '系统连通性测试,请简短回复OK。'
|
||||
},
|
||||
'response_mode': 'blocking',
|
||||
'user': 'admin_test'
|
||||
}
|
||||
else:
|
||||
request_url = DifyService._build_chat_messages_url(base_url)
|
||||
payload = {
|
||||
'inputs': {},
|
||||
'query': '系统连通性测试,请简短回复OK。',
|
||||
'response_mode': 'blocking',
|
||||
'conversation_id': '',
|
||||
'user': 'admin_test'
|
||||
}
|
||||
headers = {
|
||||
'Authorization': f'Bearer {agent.dify_api_key}',
|
||||
'Content-Type': 'application/json'
|
||||
@@ -466,24 +481,49 @@ def test_agent(id):
|
||||
success = False
|
||||
analysis = f'测试失败:HTTP {resp.status_code}。'
|
||||
|
||||
# 连通性测试:仅 workflow 按“接口可达+认证通过(2xx)”判定通过
|
||||
if dify_app_type == 'workflow' and 200 <= resp.status_code < 300:
|
||||
success = True
|
||||
analysis = '测试通过:Workflow 接口可访问且认证通过。'
|
||||
|
||||
try:
|
||||
data = resp.json()
|
||||
answer = data.get('answer') if isinstance(data, dict) else None
|
||||
if answer:
|
||||
output_info = str(answer)[:4000]
|
||||
if resp.ok and isinstance(answer, str) and answer.strip():
|
||||
success = True
|
||||
analysis = '测试通过:接口连通正常,已成功返回回答。'
|
||||
elif resp.ok:
|
||||
analysis = '测试未通过:接口可访问,但未返回有效回答。'
|
||||
else:
|
||||
if dify_app_type == 'workflow':
|
||||
workflow_data = data.get('data') if isinstance(data, dict) else None
|
||||
outputs = workflow_data.get('outputs') if isinstance(workflow_data, dict) else None
|
||||
status = workflow_data.get('status') if isinstance(workflow_data, dict) else None
|
||||
message = data.get('message') if isinstance(data, dict) else None
|
||||
if message:
|
||||
output_info = str(message)[:4000]
|
||||
if isinstance(outputs, dict) and outputs:
|
||||
output_info = str(outputs)[:4000]
|
||||
elif isinstance(message, str) and message.strip():
|
||||
output_info = message[:4000]
|
||||
elif isinstance(data, dict):
|
||||
output_info = str(data)[:4000]
|
||||
if resp.ok and status in ('succeeded', 'success'):
|
||||
analysis = '测试通过:Workflow 接口可访问且业务返回成功。'
|
||||
elif resp.ok:
|
||||
analysis = '测试通过:Workflow 接口可访问且认证通过(本次未返回业务成功状态)。'
|
||||
else:
|
||||
answer = data.get('answer') if isinstance(data, dict) else None
|
||||
if answer:
|
||||
output_info = str(answer)[:4000]
|
||||
if resp.ok and isinstance(answer, str) and answer.strip():
|
||||
success = True
|
||||
analysis = '测试通过:Chatflow 接口可访问且已返回回答。'
|
||||
elif resp.ok:
|
||||
analysis = '测试未通过:Chatflow 接口可访问,但未返回有效回答。'
|
||||
else:
|
||||
message = data.get('message') if isinstance(data, dict) else None
|
||||
if message:
|
||||
output_info = str(message)[:4000]
|
||||
except ValueError:
|
||||
if resp.ok and raw_text.strip():
|
||||
success = True
|
||||
analysis = '测试通过:接口连通正常,返回了文本内容。'
|
||||
if dify_app_type == 'workflow':
|
||||
success = True
|
||||
analysis = '测试通过:Workflow 接口可访问并返回了文本内容。'
|
||||
else:
|
||||
success = True
|
||||
analysis = '测试通过:Chatflow 接口可访问并返回了文本内容。'
|
||||
|
||||
if success and not agent.is_active:
|
||||
agent.is_active = True
|
||||
@@ -491,6 +531,7 @@ def test_agent(id):
|
||||
|
||||
return jsonify({
|
||||
'success': success,
|
||||
'dify_app_type': dify_app_type,
|
||||
'request_url': request_url,
|
||||
'output_info': output_info,
|
||||
'analysis': analysis,
|
||||
@@ -500,6 +541,7 @@ def test_agent(id):
|
||||
except requests.RequestException as e:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'dify_app_type': dify_app_type,
|
||||
'request_url': request_url,
|
||||
'output_info': str(e),
|
||||
'analysis': '测试失败:请求异常(网络、超时或认证问题)。',
|
||||
|
||||
Reference in new issue
Block a user