首页 > 其他分享 >dify 解析笔记-工具篇

dify 解析笔记-工具篇

时间:2024-09-20 17:17:36浏览次数:1  
标签:dify 2dc6d13e45f3 4cdd 笔记 id b768 message 解析 4692090d

  1. 入口
    image
    选择工具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": ""}


2.https://cloud.dify.ai/console/api/apps/a21e7956-378f-47ea-9ce6-3d390d4674b4/chat-messages?conversation_id=79d01e67-3b26-4d83-b138-8cce734d7610
参数

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
            )

问题

  1. app_model是怎么来的
  2. 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

相关文章

  • 分块/莫队学习笔记(一)(2024.8.23)
    分块基本概念分块的基本思想是,通过对原数据的适当划分,并在划分后的每一个块上预处理部分信息,从而较一般的暴力算法取得更优的时间复杂度。分块的时间复杂度主要取决于分块的块长,一般可以通过均值不等式求出某个问题下的最优块长,以及相应的时间复杂度。LOJ小分块#6277.数列分......
  • 图论进阶学习笔记(三)(2024.8.12)
    二分图定义如果你能把一个图划分成两个集合,集合内部的点没有边相连接,那么这个图就是一个二分图,如图就是一个二分图:交错路:从一个没有被匹配的点出发,依次走非匹配边,匹配边,非匹配边……最后到达另外一部点当中某个没有被匹配的点的路径。增广路:从一个没有被匹配的点出发,依次走......
  • 图论进阶学习笔记(二)(2024.8.1)
    图的连通性强连通分量割点缩点例题一边双连通分量点双连通分量2-SAT例题二例题三欧拉回路例题四......
  • 多项式学习笔记(二)(2024.7.23)
    牛顿迭代快速多项式计算加法\(H(x)=F(x)+G(x)\),求\(H(x)\)解:都已经\(O(n)\)了,还怎么优化!!!乘法\(H(x)\equivF(x)G(x)(\text{mod}x^n)\),求\(H(x)\)解:参考多项式学习笔记(一)(2024.7.6)完整代码:P3803【模板】多项式乘法(FFT)#include<bits/stdc++.h>usingnamespacestd......
  • 线性代数学习笔记(一)(2024.7.24)
    向量定义从偏计算机的角度分析,这是排成一列的数。从偏物理的角度分析,这是一条有方向有长度的线段。可以通过数形结合的方式来理解向量。虽然向量的起点不固定,但画平面直角坐标系中的向量,我们一般将向量的起点放在\((0,0)\),用向量的终点表示这个向量,如图:这个向量可以表示......
  • 数论学习笔记(一)(2024.7.25)
    一、最大公约数定义不全为\(0\)的整数\(a,b\)的最大公约数是指能够同时整除\(a\)和\(b\)的最大整数。欧几里得算法(gcd)gcd是用来求解两个整数的最大公约数定理1.2.1对于整数\(a,b,m,n\),若\(c\mida,c\midb\),则\(c\mid(ma+nb)\)证:\(\becausec\mida......
  • 线段树进阶应用学习笔记(一)(2024.7.19)(2024.8.22)
    线段树优化建图算法流程复杂度分析例题一#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=5e5,M=5e6+9;structEdge{ intv,w,nex;}e[M];inthead[M],ecnt;voidAddEdge(intu,intv,intw){ e[++ecnt]=Edge{v,w,hea......
  • 平衡树学习笔记(一)(2024.7.20)
    二叉搜索树众所周知,一个区间可以有许多信息(最大值、\(k\)大值、区间和、区间平方和、区间立方和、区间异或和、区间\(\gcd\)、不同数字个数、颜色段数……),也有许多修改方式(插入、删除、区间加、区间乘、区间改、区间翻转……),我们发现其中一些用线段树不是很好维护,这时我们......
  • JavaWeb纯小白笔记02:Tomcat的使用:发布项目的三种方式、配置虚拟主机、配置用户名和密
    通过Tomcat进行发布项目的目的是为了提供项目的访问能力:Tomcat作为Web服务器,能够处理HTTP请求和响应,将项目的内容提供给用户进行访问和使用。一.Tomcat发布项目的三种方式:第一种:直接在Tomcat文件夹里的webapps目录创建一个文件夹new放进html文件。f在文件里可以写简单的网......
  • prometheus学习笔记之alertmanager告警配置
    一、安装alertmanager项目地址:https://github.com/prometheus/alertmanager帮助文档:https://prometheus.io/docs/alerting/latest/alertmanager/配置文档:https://prometheus.io/docs/alerting/latest/configuration/wgethttps://github.com/prometheus/alertmanager/release......