返回列表 发布新帖

[玩法教程] 使用Dify 实现简单聊天机器人工作流搭建

785 0
发表于 2025-12-11 01:05:40 | 查看全部 阅读模式 IP:–浙江–杭州

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Dify 的真正价值在于,无论想法多么复杂,你都可以轻松构建、部署和扩展。它专为快速原型设计、流畅迭代和任何规模的可靠部署而打造。
这里我们参照 Dify 官网教程搭建一个简单聊天机器人,分享简单聊天机器人实现的dsl工作流脚本。
先看效果:
点击预览后,直接问问题。
QQ20251211-005801.png

工作流程图:
Chat Robot-whole-workflow.png

工作流 dsl代码:
复制后存为一个yml文件,导入即可
  1. app:
  2.   description: 聊天机器人
  3.   icon: 🤖
  4.   icon_background: '#D3F8DF'
  5.   mode: advanced-chat
  6.   name: Chat Robot
  7.   use_icon_as_answer_icon: true
  8. dependencies:
  9. - current_identifier: null
  10.   type: marketplace
  11.   value:
  12.     marketplace_plugin_unique_identifier: langgenius/deepseek:0.0.7@c4e7b999ae67bfc059f6f51630bed36def5a835d12b0251694f5784b5ff1cd95
  13.     version: null
  14. kind: app
  15. version: 0.5.0
  16. workflow:
  17.   conversation_variables: []
  18.   environment_variables: []
  19.   features:
  20.     file_upload:
  21.       allowed_file_extensions:
  22.       - .JPG
  23.       - .JPEG
  24.       - .PNG
  25.       - .GIF
  26.       - .WEBP
  27.       - .SVG
  28.       allowed_file_types:
  29.       - image
  30.       allowed_file_upload_methods:
  31.       - local_file
  32.       - remote_url
  33.       enabled: false
  34.       fileUploadConfig:
  35.         audio_file_size_limit: 50
  36.         batch_count_limit: 5
  37.         file_size_limit: 15
  38.         image_file_batch_limit: 10
  39.         image_file_size_limit: 10
  40.         single_chunk_attachment_limit: 10
  41.         video_file_size_limit: 100
  42.         workflow_file_upload_limit: 10
  43.       image:
  44.         enabled: false
  45.         number_limits: 3
  46.         transfer_methods:
  47.         - local_file
  48.         - remote_url
  49.       number_limits: 3
  50.     opening_statement: ''
  51.     retriever_resource:
  52.       enabled: true
  53.     sensitive_word_avoidance:
  54.       enabled: false
  55.     speech_to_text:
  56.       enabled: false
  57.     suggested_questions: []
  58.     suggested_questions_after_answer:
  59.       enabled: false
  60.     text_to_speech:
  61.       autoPlay: enabled
  62.       enabled: true
  63.       language: zh-Hans
  64.       voice: ''
  65.   graph:
  66.     edges:
  67.     - data:
  68.         sourceType: start
  69.         targetType: llm
  70.       id: 1765383633223-llm
  71.       selected: false
  72.       source: '1765383633223'
  73.       sourceHandle: source
  74.       target: llm
  75.       targetHandle: target
  76.       type: custom
  77.     - data:
  78.         isInIteration: false
  79.         isInLoop: false
  80.         sourceType: llm
  81.         targetType: code
  82.       id: llm-source-1765383709762-target
  83.       selected: false
  84.       source: llm
  85.       sourceHandle: source
  86.       target: '1765383709762'
  87.       targetHandle: target
  88.       type: custom
  89.       zIndex: 0
  90.     - data:
  91.         isInIteration: false
  92.         isInLoop: false
  93.         sourceType: code
  94.         targetType: answer
  95.       id: 1765383709762-source-answer-target
  96.       selected: false
  97.       source: '1765383709762'
  98.       sourceHandle: source
  99.       target: answer
  100.       targetHandle: target
  101.       type: custom
  102.       zIndex: 0
  103.     nodes:
  104.     - data:
  105.         selected: false
  106.         title: 用户输入
  107.         type: start
  108.         variables: []
  109.       height: 56
  110.       id: '1765383633223'
  111.       position:
  112.         x: 715.1898291037949
  113.         y: -4461.576805650815
  114.       positionAbsolute:
  115.         x: 715.1898291037949
  116.         y: -4461.576805650815
  117.       selected: true
  118.       sourcePosition: right
  119.       targetPosition: left
  120.       type: custom
  121.       width: 242
  122.     - data:
  123.         context:
  124.           enabled: false
  125.           variable_selector: []
  126.         memory:
  127.           query_prompt_template: '{{#sys.query#}}


  128.             {{#sys.files#}}'
  129.           role_prefix:
  130.             assistant: ''
  131.             user: ''
  132.           window:
  133.             enabled: true
  134.             size: 10
  135.         model:
  136.           completion_params:
  137.             temperature: 0.7
  138.           mode: chat
  139.           name: deepseek-chat
  140.           provider: langgenius/deepseek/deepseek
  141.         prompt_template:
  142.         - id: 58490849-3551-4ba5-b67d-d23bf2d795a2
  143.           role: system
  144.           text: "用户将询问关于某个国家的问题。问题是 {{sys.query}}\n任务:\n1. 识别提到的国家。\n2. 清晰地重新表述问题。\n\
  145.             3. 使用常识知识回答问题。\n\n用以下 JSON 格式响应:\n{\n  "country": "<国家名称>",\n  "\
  146.             question": "<重新表述的问题>",\n  "answer": "<对问题的直接回答>"\n}"
  147.         selected: false
  148.         structured_output:
  149.           schema:
  150.             additionalProperties: false
  151.             properties:
  152.               answer:
  153.                 type: string
  154.               country:
  155.                 type: string
  156.               question:
  157.                 type: string
  158.             required:
  159.             - country
  160.             - question
  161.             - answer
  162.             type: object
  163.         structured_output_enabled: true
  164.         title: LLM
  165.         type: llm
  166.         vision:
  167.           enabled: false
  168.       height: 67
  169.       id: llm
  170.       position:
  171.         x: 1031.2589322890572
  172.         y: -4455.0564754254565
  173.       positionAbsolute:
  174.         x: 1031.2589322890572
  175.         y: -4455.0564754254565
  176.       selected: true
  177.       sourcePosition: right
  178.       targetPosition: left
  179.       type: custom
  180.       width: 242
  181.     - data:
  182.         answer: '{{#llm.text#}}'
  183.         selected: true
  184.         title: 直接回复
  185.         type: answer
  186.         variables: []
  187.       height: 87
  188.       id: answer
  189.       position:
  190.         x: 1615.1898291037949
  191.         y: -4461.576805650815
  192.       positionAbsolute:
  193.         x: 1615.1898291037949
  194.         y: -4461.576805650815
  195.       selected: true
  196.       sourcePosition: right
  197.       targetPosition: left
  198.       type: custom
  199.       width: 242
  200.     - data:
  201.         code: "\ndef main(arg1: str, arg2: str):\n    return {\n        "result"\
  202.           : arg1 + arg2,\n    }\ndef main(country: str) -> dict:\n  country_name =\
  203.           \ country.lower()\n  fun_facts = {\n    "japan": "日本有超过 500 万台自动售货机。"\
  204.           ,\n    "france": "法国是世界上访问量最大的国家。",\n    "italy": "意大利拥有的联合国教科文组织世界遗产地比任何其他国家都多。"\
  205.           \n  }\n  fun_fact = fun_facts.get(country_name, f"没有关于 {country.title()}\
  206.           \ 的趣事。")\n  return {"fun_fact": fun_fact}"
  207.         code_language: python3
  208.         desc: GET FUN FACT
  209.         outputs:
  210.           fun_fact:
  211.             children: null
  212.             type: string
  213.         selected: false
  214.         title: 代码执行
  215.         type: code
  216.         variables:
  217.         - value_selector:
  218.           - llm
  219.           - structured_output
  220.           - country
  221.           value_type: object
  222.           variable: country
  223.       height: 65
  224.       id: '1765383709762'
  225.       position:
  226.         x: 1315.1898291037949
  227.         y: -4440.576805650815
  228.       positionAbsolute:
  229.         x: 1315.1898291037949
  230.         y: -4440.576805650815
  231.       selected: true
  232.       sourcePosition: right
  233.       targetPosition: left
  234.       type: custom
  235.       width: 242
  236.     viewport:
  237.       x: -235.78970962962944
  238.       y: 3170.696457676142
  239.       zoom: 0.62208
  240.   rag_pipeline_variables: []
复制代码



评论

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright © 2026 绿联NAS私有云社区 版权所有 All Rights Reserved. 粤公网安备44030002002555号| 粤ICP备12028978号
关灯 在本版发帖
联系技术支持
返回顶部
快速回复 返回顶部 返回列表