# comfyui-output-dify **Repository Path**: MingGyGy/comfyui-output-dify ## Basic Information - **Project Name**: comfyui-output-dify - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-30 - **Last Updated**: 2025-07-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ComfyUI Dify Integration - 文本输出节点 专门为 Dify 平台集成设计的 ComfyUI 自定义节点包,解决 Dify 无法获取 ComfyUI 文本输出的问题。 ## 🎯 主要功能 - **Dify Text Output 节点**: 专门格式化文本输出以符合 Dify 期望的 JSON 格式 - **Text Display 节点**: 在 ComfyUI 界面中显示文本内容 - **Text Combine 节点**: 组合多个文本输入 - **API 处理器**: 自动处理 ComfyUI 与 Dify 之间的数据格式转换 ## 🚀 快速开始 ### 安装方法 #### 方法1: 直接复制文件(推荐) 1. 将所有文件复制到 ComfyUI 的 `custom_nodes` 目录下的新文件夹: ```bash # 创建目录 mkdir ComfyUI/custom_nodes/comfyui-dify-integration # 复制文件 cp text_output_node.py ComfyUI/custom_nodes/comfyui-dify-integration/ cp __init__.py ComfyUI/custom_nodes/comfyui-dify-integration/ cp api_handler.py ComfyUI/custom_nodes/comfyui-dify-integration/ ``` 2. 重启 ComfyUI #### 方法2: Git 克隆 ```bash cd ComfyUI/custom_nodes/ git clone comfyui-dify-integration ``` ### 验证安装 启动 ComfyUI 后,在控制台中应该看到: ``` [Dify Integration] 成功加载 3 个节点: - DifyTextOutputNode - TextDisplayNode - TextCombineNode [Dify Integration] 插件初始化完成 - 版本 1.0.0 ``` ## 📋 节点说明 ### 1. Dify Text Output 节点 **位置**: `Dify Integration` 类别 **功能**: 将文本格式化为 Dify 期望的输出格式 **输入参数**: - `text` (必需): 要输出到 Dify 的文本内容 - `format_for_dify` (Boolean): 是否格式化为 Dify JSON 格式 (默认: True) - `include_metadata` (Boolean): 是否包含元数据信息 (默认: False) - `additional_data` (可选): 附加的 JSON 数据 **输出**: - `formatted_output`: 格式化后的文本输出 - `json_output`: JSON 格式的输出对象 **输出格式**: ```json { "text": "您的文本内容", "files": [], "json": [ { "data": [] } ] } ``` ### 2. Text Display 节点 **功能**: 在 ComfyUI 界面中显示文本内容,用于调试和验证 ### 3. Text Combine 节点 **功能**: 组合多个文本输入,支持自定义分隔符 ## 🔧 在 Dify 中使用 ### 第一步: 在 ComfyUI 工作流中添加节点 1. 在 ComfyUI 中创建您的工作流 2. 添加 `Dify Text Output` 节点 3. 将您的文本生成节点连接到 `Dify Text Output` 节点的 `text` 输入 4. 确保 `format_for_dify` 设置为 `True` ### 第二步: 导出工作流 1. 在 ComfyUI 中点击 "Save (API Format)" 导出 API 格式的工作流 2. 这将生成一个 JSON 文件,用于 Dify 集成 ### 第三步: 在 Dify 中配置 1. 在 Dify 工作流中添加 ComfyUI 节点 2. 上传您的工作流 JSON 文件 3. 配置输入和输出映射 ## 📝 示例工作流 ### 基础文本输出示例 ```json { "1": { "inputs": { "text": "Hello, this is a test message from ComfyUI to Dify!" }, "class_type": "DifyTextOutputNode" } } ``` ### 带元数据的输出示例 ```json { "1": { "inputs": { "text": "Generated text content", "format_for_dify": true, "include_metadata": true, "additional_data": "[{\"model\": \"gpt-4\", \"temperature\": 0.7}]" }, "class_type": "DifyTextOutputNode" } } ``` ## 🐛 故障排除 ### 问题1: Dify 无法获取文本输出 **解决方案**: 1. 确保使用了 `DifyTextOutputNode` 而不是普通的文本输出节点 2. 检查 `format_for_dify` 参数是否设置为 `True` 3. 验证工作流中是否正确连接了文本输出节点 ### 问题2: 节点未加载 **解决方案**: 1. 确认文件已正确复制到 `custom_nodes` 目录 2. 检查 ComfyUI 控制台是否有错误信息 3. 重启 ComfyUI ### 问题3: JSON 格式错误 **解决方案**: 1. 检查 `additional_data` 字段是否为有效的 JSON 格式 2. 查看 ComfyUI 控制台的错误日志 3. 使用 `include_metadata` 选项获取更多调试信息 ## 🔍 调试技巧 ### 启用详细日志 在 ComfyUI 启动参数中添加: ```bash --verbose ``` ### 检查输出格式 使用 `Text Display` 节点查看格式化前后的文本内容: ``` [文本生成节点] → [Dify Text Output] → [Text Display] ↓ [输出到 Dify] ``` ### 验证 JSON 格式 可以使用在线 JSON 验证器检查输出格式是否正确。 ## 📈 高级配置 ### 自定义输出格式 如果需要自定义输出格式,可以修改 `text_output_node.py` 中的 `process_text_output` 方法: ```python def process_text_output(self, text: str = "", ...): # 自定义您的输出格式 custom_output = { "text": text, "files": [], "json": [{"data": your_custom_data}], "custom_field": "your_value" # 添加自定义字段 } return (json.dumps(custom_output), custom_output) ``` ### 处理特殊字符 节点会自动处理中文和特殊字符,使用 `ensure_ascii=False` 参数。 ## 🤝 贡献 欢迎提交 Issue 和 Pull Request! ### 开发环境设置 1. 克隆仓库 2. 安装开发依赖 3. 运行测试 ## 📜 许可证 MIT License ## 🔗 相关链接 - [ComfyUI 官方文档](https://github.com/comfyanonymous/ComfyUI) - [Dify 官方文档](https://docs.dify.ai/) - [自定义节点开发指南](https://github.com/comfyanonymous/ComfyUI/wiki) ## ❓ 常见问题 **Q: 为什么需要这个插件?** A: 标准的 ComfyUI 文本输出节点无法提供 Dify 期望的 JSON 格式,这个插件专门解决了这个集成问题。 **Q: 是否支持图片输出?** A: 当前版本主要专注于文本输出,图片和文件输出功能在开发中。 **Q: 如何更新插件?** A: 直接替换文件或使用 `git pull` 更新,然后重启 ComfyUI。 **Q: 插件是否兼容所有 ComfyUI 版本?** A: 插件基于标准的 ComfyUI 节点 API,应该兼容大多数版本。如遇问题请提交 Issue。 --- 如果您觉得这个插件有用,请给我们一个 ⭐ Star!