AI大模型教程
一起来学习

dify + ollama + deepseek-r1+ stable-diffusion 构建绘画智能体

故事背景

stable-diffusion 集成进 dify 后,我们搭建一个小智能体,验证下文生图功能

业务流程

#mermaid-svg-6nSwwp69eMizP6bt {font-family:”trebuchet ms”,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-6nSwwp69eMizP6bt .error-icon{fill:#552222;}#mermaid-svg-6nSwwp69eMizP6bt .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-6nSwwp69eMizP6bt .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-6nSwwp69eMizP6bt .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-6nSwwp69eMizP6bt .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-6nSwwp69eMizP6bt .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-6nSwwp69eMizP6bt .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-6nSwwp69eMizP6bt .marker{fill:#333333;stroke:#333333;}#mermaid-svg-6nSwwp69eMizP6bt .marker.cross{stroke:#333333;}#mermaid-svg-6nSwwp69eMizP6bt svg{font-family:”trebuchet ms”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-6nSwwp69eMizP6bt .label{font-family:”trebuchet ms”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-6nSwwp69eMizP6bt .cluster-label text{fill:#333;}#mermaid-svg-6nSwwp69eMizP6bt .cluster-label span{color:#333;}#mermaid-svg-6nSwwp69eMizP6bt .label text,#mermaid-svg-6nSwwp69eMizP6bt span{fill:#333;color:#333;}#mermaid-svg-6nSwwp69eMizP6bt .node rect,#mermaid-svg-6nSwwp69eMizP6bt .node circle,#mermaid-svg-6nSwwp69eMizP6bt .node ellipse,#mermaid-svg-6nSwwp69eMizP6bt .node polygon,#mermaid-svg-6nSwwp69eMizP6bt .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-6nSwwp69eMizP6bt .node .label{text-align:center;}#mermaid-svg-6nSwwp69eMizP6bt .node.clickable{cursor:pointer;}#mermaid-svg-6nSwwp69eMizP6bt .arrowheadPath{fill:#333333;}#mermaid-svg-6nSwwp69eMizP6bt .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-6nSwwp69eMizP6bt .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-6nSwwp69eMizP6bt .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-6nSwwp69eMizP6bt .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-6nSwwp69eMizP6bt .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-6nSwwp69eMizP6bt .cluster text{fill:#333;}#mermaid-svg-6nSwwp69eMizP6bt .cluster span{color:#333;}#mermaid-svg-6nSwwp69eMizP6bt div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:”trebuchet ms”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-6nSwwp69eMizP6bt :root{–mermaid-font-family:”trebuchet ms”,verdana,arial,sans-serif;}
用户输入文本
LLM根据用户诉求,
生成文生图英文prompt
根据文生图prompt调用
stable-diffusion 生成图片
输出图片和英文prompt

节点图

节点说明

LLM

LLM 节点采用 deepseek-r1 模型,提示词为:根据用户输入的文本,理解并转换成文生图提示词,且提示词必须是英文,输出​内容不带思考过程,以文本输出

代码执行

由于大模型生成的文本中,还存在思考过程,这里由于是demo,直接字符串截取,获取英文prompt

验证效果


LLM节点输出的数据为

{
  "text": "
Thinking... n好的,我现在需要处理用户的查询。用户提供了一段中文文本:“《红楼梦》中的林黛玉”,然后要求我将其转换为用于文生图的提示词,并且这个提示词必须是英文,同时不带任何思考过程,直接输出结果。nn首先,我要理解用户的需求。他们希望将中文描述转换成英文的提示词,用于生成图像。这可能是因为他们正在使用一个支持英文提示词的绘图工具或API,比如DALL·E、MidJourney或者Stable Diffusion等。这些工具通常需要明确且详细的英文提示词来生成高质量的图像。nn接下来,我分析用户提供的文本:“《红楼梦》中的林黛玉”。这句话提到了两个关键元素:一是作品名称《红楼梦》,二是人物林黛玉。因此,提示词需要包含这两个信息点,并且可能还需要一些额外的描述来帮助生成更准确的画面。nn考虑到绘图模型通常对细节和氛围比较敏感,我应该在提示词中添加一些环境或风格的描述。例如,“古典中国文学作品”可以传达出《红楼梦》的文化背景;“忧郁而优雅”则能描绘林黛玉的性格特点;再加上“传统服饰”来具体化人物的形象。nn然后,我会把这些元素组合成一个连贯的英文句子。确保用词准确且自然流畅,避免过于生硬或直译。例如,“A melancholic and elegant character from the classic Chinese literary work 'Dream of the Red Chamber'”能够很好地表达林黛玉的角色特质和作品背景;“dressed in traditional Chinese attire”则进一步细化了人物的外貌特征。nn最后,检查整个提示词是否完整,是否有遗漏的关键信息。确保没有语法错误,并且每个部分都清晰传达给绘图模型,以便生成符合预期的画面。n
nnA melancholic and elegant character from the classic Chinese literary work "Dream of the Red Chamber", dressed in traditional Chinese attire"
, "usage": { "prompt_tokens": 45, "prompt_unit_price": "0", "prompt_price_unit": "0", "prompt_price": "0E-7", "completion_tokens": 402, "completion_unit_price": "0", "completion_price_unit": "0", "completion_price": "0E-7", "total_tokens": 447, "total_price": "0E-7", "currency": "USD", "latency": 42.33978042751551 }, "finish_reason": "stop" }

文章来源于互联网:dify + ollama + deepseek-r1+ stable-diffusion 构建绘画智能体

相关推荐: Aibiye:AI写作神器,让论文写作轻松又高效!

在学术道路上,论文写作无疑是每位学者和学生都必须面对的挑战。无论是本科毕业论文、硕士论文,还是日常的课程作业,论文写作都是一项耗时且复杂的任务。然而,随着人工智能技术的飞速发展,我们终于可以从这些繁琐的任务中解脱了,这都要归功于论文写作神器——Aibiye! …

赞(0)
未经允许不得转载:5bei.cn大模型教程网 » dify + ollama + deepseek-r1+ stable-diffusion 构建绘画智能体
分享到: 更多 (0)

AI大模型,我们的未来

小欢软考联系我们