- 入口
选择工具duckduckgo
发送消息后,后台的接口:
1.chat-messages:https://cloud.dify.ai/console/api/apps/a21e7956-378f-47ea-9ce6-3d390d4674b4/chat-messages
载荷
{"response_mode":"streaming","conversation_id":"","query":"hello","inputs":{},"model_config":{"pre_prompt":"","prompt_type":"simple","chat_prompt_config":{},"completion_prompt_config":{},"user_input_form":[],"dataset_query_variable":"","opening_statement":null,"more_like_this":{"enabled":false},"suggested_questions":[],"suggested_questions_after_answer":{"enabled":false},"text_to_speech":{"enabled":false},"speech_to_text":{"enabled":false},"retriever_resource":{"enabled":true},"sensitive_word_avoidance":{"enabled":false,"type":"","configs":[]},"agent_mode":{"max_iteration":5,"enabled":true,"strategy":"function_call","tools":[{"provider_id":"duckduckgo","provider_type":"builtin","provider_name":"duckduckgo","tool_name":"ddgo_ai","tool_label":"DuckDuckGo AI聊天","tool_parameters":{"query":"","model":""},"enabled":true}],"prompt":null},"dataset_configs":{"retrieval_model":"multiple","datasets":{"datasets":[]}},"file_upload":{"image":{"enabled":false,"number_limits":3,"detail":"high","transfer_methods":["remote_url","local_file"]}},"annotation_reply":{"enabled":false},"supportAnnotation":true,"appId":"a21e7956-378f-47ea-9ce6-3d390d4674b4","supportCitationHitInfo":true,"model":{"provider":"openai","name":"gpt-4o-mini","mode":"chat","completion_params":{}}}}
响应结果
data: {"event": "agent_thought", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "7409b3c5-8952-498e-bd9d-e36a168a53e6", "position": 1, "thought": "", "observation": "", "tool": "", "tool_labels": {}, "tool_input": "", "message_files": []}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": "Hello"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": "!"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": " How"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": " can"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": " I"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": " assist"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": " you"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": " today"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": "?"}
data: {"event": "agent_message", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "answer": ""}
data: {"event": "agent_thought", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "7409b3c5-8952-498e-bd9d-e36a168a53e6", "position": 1, "thought": "Hello! How can I assist you today?", "observation": "", "tool": "", "tool_labels": {}, "tool_input": "", "message_files": []}
data: {"event": "message_end", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "metadata": {"usage": {"prompt_tokens": 8, "prompt_unit_price": "0.15", "prompt_price_unit": "0.000001", "prompt_price": "0.0000012", "completion_tokens": 9, "completion_unit_price": "0.60", "completion_price_unit": "0.000001", "completion_price": "0.0000054", "total_tokens": 17, "total_price": "0.0000066", "currency": "USD", "latency": 0.5811177659779787}}}
data: {"event": "tts_message_end", "conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610", "message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3", "created_at": 1726822243, "task_id": "397553c1-805d-45f7-b64e-4976b808c961", "audio": ""}
conversation_id:79d01e67-3b26-4d83-b138-8cce734d7610
响应结果
{
"limit": 20,
"has_more": false,
"data": [
{
"id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3",
"conversation_id": "79d01e67-3b26-4d83-b138-8cce734d7610",
"inputs": {},
"query": "hello",
"message": [
{
"role": "user",
"text": "hello",
"files": []
}
],
"message_tokens": 8,
"answer": "Hello! How can I assist you today?",
"answer_tokens": 9,
"provider_response_latency": 0.6008692521136254,
"from_source": "console",
"from_end_user_id": null,
"from_account_id": "b010bb9b-9098-4f07-a10e-39a6b6686d03",
"feedbacks": [],
"workflow_run_id": null,
"annotation": null,
"annotation_hit_history": null,
"created_at": 1726822243,
"agent_thoughts": [
{
"id": "7409b3c5-8952-498e-bd9d-e36a168a53e6",
"chain_id": null,
"message_id": "4692090d-09a4-4cdd-b768-2dc6d13e45f3",
"position": 1,
"thought": "Hello! How can I assist you today?",
"tool": "",
"tool_labels": {},
"tool_input": "",
"created_at": 1726822242,
"observation": "",
"files": []
}
],
"message_files": [],
"metadata": {},
"status": "normal",
"error": null
}
]
}
后端源码 console/app/completion
api.add_resource(ChatMessageApi, "/apps/<uuid:app_id>/chat-messages")
class ChatMessageApi(Resource):
@setup_required
@login_required
@account_initialization_required
@get_app_model(mode=[AppMode.CHAT, AppMode.AGENT_CHAT])
def post(self, app_model):
parser = reqparse.RequestParser()
parser.add_argument("inputs", type=dict, required=True, location="json")
parser.add_argument("query", type=str, required=True, location="json")
parser.add_argument("files", type=list, required=False, location="json")
parser.add_argument("model_config", type=dict, required=True, location="json")
parser.add_argument("conversation_id", type=uuid_value, location="json")
parser.add_argument("response_mode", type=str, choices=["blocking", "streaming"], location="json")
parser.add_argument("retriever_from", type=str, required=False, default="dev", location="json")
args = parser.parse_args()
streaming = args["response_mode"] != "blocking"
args["auto_generate_name"] = False
account = flask_login.current_user
try:
response = AppGenerateService.generate(
app_model=app_model, user=account, args=args, invoke_from=InvokeFrom.DEBUGGER, streaming=streaming
)
问题
- app_model是怎么来的
- tenant_id到底是什么?
AppGenerateService.generate
if app_model.mode == AppMode.COMPLETION.value:
return rate_limit.generate(
CompletionAppGenerator().generate(
app_model=app_model, user=user, args=args, invoke_from=invoke_from, stream=streaming
),
request_id,
)
elif app_model.mode == AppMode.AGENT_CHAT.value or app_model.is_agent:
return rate_limit.generate(
AgentChatAppGenerator().generate(
app_model=app_model, user=user, args=args, invoke_from=invoke_from, stream=streaming
),
request_id,
)
elif app_model.mode == AppMode.CHAT.value:
return rate_limit.generate(
ChatAppGenerator().generate(
app_model=app_model, user=user, args=args, invoke_from=invoke_from, stream=streaming
),
request_id,
)
ChatAppGenerator
runner = ChatAppRunner()
runner.run(
application_generate_entity=application_generate_entity,
queue_manager=queue_manager,
conversation=conversation,
message=message
)
标签:dify,2dc6d13e45f3,4cdd,笔记,id,b768,message,解析,4692090d
From: https://www.cnblogs.com/Gimm/p/18422804