03.01.02.ComfyUI Ubuntu:环境搭建篇(集成 AnythingLLM调用ComfyUI的API 使用Custom Skills方式) 总操作流程1、写代码2、配置3、测试写代码获取ComfyUI的API工作流导出DKLi1717.jsoncd/root/.config/anythingllm-desktop/storage/plugins/agent-skillsmkdir-pcomfyui-triggercatcomfyui-trigger/DKLi1717.jsonEOF { 3: { class_type: KSampler, inputs: { cfg: 8, denoise: 1, latent_image: [ 5, 0 ], model: [ 4, 0 ], negative: [ 7, 0 ], positive: [ 6, 0 ], sampler_name: euler, scheduler: normal, seed: 8566257, steps: 20 } }, 4: { class_type: CheckpointLoaderSimple, inputs: { ckpt_name: stabilityai/stable-diffusion-3-medium/sd3_medium_incl_clips_t5xxlfp16.safetensors } }, 5: { class_type: EmptyLatentImage, inputs: { batch_size: 1, height: 512, width: 512 } }, 6: { class_type: CLIPTextEncode, inputs: { clip: [ 4, 1 ], text: masterpiece best quality man } }, 7: { class_type: CLIPTextEncode, inputs: { clip: [ 4, 1 ], text: bad hands } }, 8: { class_type: VAEDecode, inputs: { samples: [ 3, 0 ], vae: [ 4, 2 ] } }, 9: { class_type: SaveImage, inputs: { filename_prefix: ComfyUI, images: [ 8, 0 ] } } } EOF写代码cd/root/.config/anythingllm-desktop/storage/plugins/agent-skillsmkdir-pcomfyui-trigger# 技能的元数据名称、描述、入参等catcomfyui-trigger/plugin.jsonEOF { id: comfyui-trigger, hubId: comfyui-trigger, active: true, imported: true, name: ComfyUI API Trigger, schema:skill-1.0.0, version: 1.0.0, description: 调用 ComfyUI API 根据提示词生成图片。, author: DKLi1717, license: MIT, type: custom_skill, entrypoint: handler.js, setup_args: { prompt_text: { type: string, required: true, input: { type: text, default: 帮我生成一张太空宇航员的图片, placeholder: 帮我生成一张太空宇航员的图片, hint: 告诉大模型您需要生成什么画 } } } } EOF# 具体的 NodeJS 执行逻辑catcomfyui-trigger/handler.jsEOF /** * AnythingLLM ComfyUI API Handler */ async function handler({comfyui_url,prompt_text}) { try { const workflow require(/root/.config/anythingllm-desktop/storage/plugins/agent-skills/comfyui-trigger/DKLi1717.json); workflow[6].inputs.text String(prompt_text); const COMFYUI_HOST http://10.3.11.173:8188; const response await fetch(${COMFYUI_HOST}/prompt, { method: POST, headers: { Content-Type: application/json }, body: JSON.stringify({ prompt: workflow }) }); if (!response.ok) { throw new Error(ComfyUI API error! status: ${response.status}); return 执行 response 失败: ${response.status}; } const result await response.json(); const imageUrl await waitForImage(result.prompt_id); return ComfyUI 工作流已成功触发任务ID: ${result.prompt_id}。请前往 ComfyUI 查看输出结果。; } catch (error) { return 执行 ComfyUI 技能失败: ${error.message}; } } /** * 等待 ComfyUI 渲染完成并获取图像 */ async function waitForImage(promptId) { const WS_HOST ws://10.3.11.173:8188; return new Promise((resolve, reject) { const ws new WebSocket(${WS_HOST}/ws?clientIdcustom_skill_client); ws.on(message, (data) { // 解析 WebSocket 事件 // 当出现 executing 和任务完成的信号时处理 const message JSON.parse(data); if (message.type executing message.data.node null message.data.prompt_id promptId) { ws.close(); // 渲染完成调用接口获取图片列表 resolve(getImageUrl(promptId)); } }); ws.on(error, (err) reject(err)); }); } /** * 根据 prompt_id 获取生成的图片 URL */ async function getImageUrl(promptId) { const COMFYUI_HOST http://10.3.11.173:8188; const historyResponse await fetch(${COMFYUI_HOST}/history/${promptId}); const historyData await historyResponse.json(); // 从历史记录中提取生成图片的 output 节点和文件名 const outputs historyData[promptId].outputs; // 假设最终输出节点为 9 const imageOutput outputs[9].images[0]; const imageUrl ${COMFYUI_HOST}/view?filename${imageOutput.filename}subfolder${imageOutput.subfolder}type${imageOutput.type}; return imageUrl; } module.exports { runtime: { handler} }; EOFchmod0777-R/root/.config/anythingllm-desktop/storage/plugins/agent-skills/comfyui-triggerchown$USER:$USER-R/root/.config/anythingllm-desktop/storage/plugins/agent-skills/comfyui-trigger测试# 重启服务器sudo-upostgres /usr/local/software/postgresql/data/pgsql/bin/pg_ctl restart-D/usr/local/software/postgresql/data/pgdata-l/usr/local/software/postgresql/data/pglog/logfile-mf# 启动ComfyUIpython /usr/local/software/ComfyUI/main.py--listen0.0.0.0--port8188# 启动AnythingLLMDesktop/usr/local/software/AnythingLLMDesktop/anythingllm-desktop --no-sandbox# 提问agent 使用comfyui-trigger生成一张三色小猫图白色、灰色和橙色系的可爱猫咪。# 查看是否生成了图片ls/usr/local/software/ComfyUI/output

相关新闻

最新新闻

建筑供配电与照明课程设计实操指南:从负荷计算到施工图核心要点

建筑供配电与照明课程设计实操指南:从负荷计算到施工图核心要点

简介:涵盖低压配电、照明、插座与防雷接地系统的建筑供配电及照明课程设计文档,以某小区六层综合住宅楼为完整案例,面向建筑电气、暖通及相关专业学生和初入行的电气设计人员。文档从建筑电气概况切入,明确设计原则与内容&#xf…

2026/9/6 19:42:13
IGBT升压斩波电路设计:从参数计算到调试实战

IGBT升压斩波电路设计:从参数计算到调试实战

简介:这是一份面向电力电子技术课程设计或工程应用的绝缘栅双极晶体管(IGBT)升压斩波电路设计文档,系统讲解从Boost变换器原理到SG3525控制、驱动与保护的完整设计实现路径。文档以绝缘栅双极晶体管为核心器件,围绕升压…

2026/9/6 19:42:13
卡尔曼滤波+LSTM时间序列预测:MATLAB实现与GUI封装全攻略

卡尔曼滤波+LSTM时间序列预测:MATLAB实现与GUI封装全攻略

简介:这是一份基于MATLAB平台、融合卡尔曼滤波(KF)与长短期记忆网络(LSTM)的时间序列预测项目文档,适合具备一定编程基础和深度学习背景的研究人员、工程师,以及金融、气象、工业控制等预测领域…

2026/9/6 19:42:13
newsnow 完全指南:三分钟搭一个自己的实时热点新闻聚合站

newsnow 完全指南:三分钟搭一个自己的实时热点新闻聚合站

newsnow 完全指南:三分钟搭一个自己的实时热点新闻聚合站 【免费下载链接】newsnow Elegant reading of real-time and hottest news 项目地址: https://gitcode.com/GitHub_Trending/ne/newsnow 早高峰地铁上,你还在热搜、科技资讯、GitHub 趋势…

2026/9/6 19:42:13
本地免费解锁 Wand(WeMod)高级功能:3 步跑通 Wand-Enhancer 完整指南

本地免费解锁 Wand(WeMod)高级功能:3 步跑通 Wand-Enhancer 完整指南

本地免费解锁 Wand(WeMod)高级功能:3 步跑通 Wand-Enhancer 完整指南 【免费下载链接】Wand-Enhancer Advanced UX and interoperability extension for Wand (WeMod) app 项目地址: https://gitcode.com/GitHub_Trending/we/Wand-Enhancer Wand-Enhancer 是…

2026/9/6 19:42:12
Bulletproof React Next.js App 应用本地运行指南:环境配置、Mock Server 与开发工作流

Bulletproof React Next.js App 应用本地运行指南:环境配置、Mock Server 与开发工作流

Bulletproof React Next.js App 应用本地运行指南:环境配置、Mock Server 与开发工作流 【免费下载链接】bulletproof-react 🛡️ ⚛️ A simple, scalable, and powerful architecture for building production ready React applications. 项目地址:…

2026/9/6 19:37:12