OpenWebUI通过pipeline对接dify的workflow

1、安装pipeline

docker run -d -p 9099:9099 --add-host=host.docker.internal:host-gateway -v pipelines:/app/pipelines --name pipelines --restart always ghcr.io/open-webui/pipelines:main 

2、对接OpenWebUI(密码:0p3n-w3bu!)

3、进入pipeline容器配置

只需几个简单的步骤即可开始使用 Pipelines: 1、确保已安装 Python 3.11。它是唯一官方支持的 Python 版本 2、克隆管道存储库 git clone https://github.com/open-webui/pipelines.git cd pipelines 3、安装所需的依赖项 pip install -r requirements.txt 4、启动 Pipelines 服务器 sh ./start.sh 服务器运行后,将客户端上的 OpenAI URL 设置为 Pipelines URL。这解锁了 Pipelines 的全部功能,集成了任何 Python 库并创建了适合您需求的自定义工作流程。

4、上传dify的python脚本(url,key,输入输出变量名都需要更改)

#####块输出 from typing import List, Union, Generator, Iterator, Optional from pprint import pprint import requests, json, warnings # Uncomment to disable SSL verification warnings if needed. # warnings.filterwarnings('ignore', message='Unverified HTTPS request') class Pipeline: def __init__(self): self.name = "IT_AI智能知识平台" # 平台名称 self.api_url = "http://10.160.8.210/v1/workflows/run" # Dify API 地址 self.api_key = "app-raqQgGRuLSCKxatmFy8S0JmD" # Dify API Key self.api_request_stream = True # 启用流式响应(但仅取最终结果) self.verify_ssl = True # 自部署 Dify 可设为 False self.debug = True # 开启调试日志(必须保留!) async def on_startup(self): print(f"on_startup: {self.name} 初始化完成") async def on_shutdown(self): print(f"on_shutdown: {self.name} 已停止") async def inlet(self, body: dict, user: Optional[dict] = None) -> dict: if self.debug: print(f"inlet: body={body}, user={user}") return body async def outlet(self, body: dict, user: Optional[dict] = None) -> dict: if self.debug: print(f"outlet: body={body}, user={user}") return body def pipe(self, user_message: str, model_id: str, messages: List[dict], body: dict) -> Union[str, Generator, Iterator]: print(f"pipe: {self.name} - 开始处理用户消息") if self.debug: print(f"pipe: 用户输入: {user_message}") print(f"pipe: body内容: {body}") # 1. 构建请求参数 response_mode = "streaming" if self.api_request_stream else "blocking" headers = { 'Authorization': f'Bearer {self.api_key}', 'Content-Type': 'application/json' } data = { "inputs": {"user_message_text": user_message}, # Dify 输入变量名(与工作流定义一致) "response_mode": response_mode, "user": body.get("user", {}).get("email", "default_user") } # 2. 发送请求到 Dify try: response = requests.post( self.api_url, headers=headers, json=data, stream=self.api_request_stream, verify=self.verify_ssl ) # 3. 处理响应(核心修正:仅返回最终完整文本) if response.status_code == 200: final_output = False # 标记是否已获取最终结果 for line in response.iter_lines(): if not line or final_output: continue # 空行或已获取最终结果,跳过 line = line.decode('utf-8').strip() if self.debug: print(f"pipe: Dify 原始响应行: {line}") # 解析流式响应(仅处理 workflow_finished 事件) if line.startswith("data: "): json_str = line[len("data: "):] try: json_data = json.loads(json_str) # 关键:仅处理最终完成事件(event: workflow_finished) if json_data.get("event") == "workflow_finished": outputs = json_data.get("data", {}).get("outputs", {}) full_text = outputs.get("summary", "") # Dify 输出变量名(summary) if full_text: final_output = True # 标记已获取最终结果 yield full_text # 仅返回一次完整文本 break # 退出循环,避免重复处理 except json.JSONDecodeError: error_msg = f"[JSON解析错误] {json_str[:100]}" print(f"pipe: {error_msg}") yield error_msg # 容错:若未触发 workflow_finished,但有累积文本(极端情况) if not final_output and full_text: yield full_text else: error_details = response.text[:500] yield f"请求失败: 状态码 {response.status_code},详情: {error_details}" except Exception as e: yield f"执行错误: {str(e)}"
#####流式输出 from typing import List, Union, Generator, Iterator, Optional from pprint import pprint import requests, json, warnings # Uncomment to disable SSL verification warnings if needed. # warnings.filterwarnings('ignore', message='Unverified HTTPS request') class Pipeline: def __init__(self): self.name = "IT_AI智能知识平台" # 平台名称 self.api_url = "http://10.160.8.210/v1/workflows/run" # Dify API 地址 self.api_key = "app-N5aBftQwzEvbdla0KhAljB5E" # Dify API Key self.api_request_stream = True # 启用流式响应 self.verify_ssl = True # 自部署 Dify 可设为 False self.debug = True # 开启调试日志(必须保留!) async def on_startup(self): print(f"on_startup: {self.name} 初始化完成") async def on_shutdown(self): print(f"on_shutdown: {self.name} 已停止") async def inlet(self, body: dict, user: Optional[dict] = None) -> dict: if self.debug: print(f"inlet: body={body}, user={user}") return body async def outlet(self, body: dict, user: Optional[dict] = None) -> dict: if self.debug: print(f"outlet: body={body}, user={user}") return body def pipe(self, user_message: str, model_id: str, messages: List[dict], body: dict) -> Union[str, Generator, Iterator]: print(f"pipe: {self.name} - 开始处理用户消息") if self.debug: print(f"pipe: 用户输入: {user_message}") print(f"pipe: body内容: {body}") # 1. 构建请求参数 response_mode = "streaming" if self.api_request_stream else "blocking" headers = { 'Authorization': f'Bearer {self.api_key}', 'Content-Type': 'application/json' } data = { "inputs": {"user_message_text": user_message}, # Dify 输入变量名(与工作流定义一致) "response_mode": response_mode, "user": body.get("user", {}).get("email", "default_user") } # 2. 发送请求到 Dify try: response = requests.post( self.api_url, headers=headers, json=data, stream=self.api_request_stream, verify=self.verify_ssl ) # 3. 处理流式响应 if response.status_code == 200: for line in response.iter_lines(): if not line: # 跳过空行 continue line = line.decode('utf-8').strip() if self.debug: print(f"pipe: Dify 原始响应行: {line}") # 只处理包含"data: "的行 if line.startswith("data: "): json_str = line[len("data: "):] try: json_data = json.loads(json_str) # 处理text_chunk事件 if json_data.get("event") == "text_chunk": chunk = json_data.get("data", {}).get("text", "") if chunk: yield chunk # 实时输出每个文本块 # 可选:处理workflow_finished事件作为结束标志 elif json_data.get("event") == "workflow_finished" and self.debug: print("pipe: 工作流已完成") except json.JSONDecodeError: error_msg = f"[JSON解析错误] {json_str[:100]}" print(f"pipe: {error_msg}") yield error_msg else: error_details = response.text[:500] yield f"请求失败: 状态码 {response.status_code},详情: {error_details}" except requests.exceptions.RequestException as e: yield f"请求异常: {str(e)}" except Exception as e: yield f"执行错误: {str(e)}"

5、将上述脚本上传到下图所在位置

另:

这些示例展示了如何集成不同的功能,为构建您自己的自定义管道奠定基础。https://github.com/open-webui/pipelines/blob/main/examples

参考链接:⚡ 管道 |打开 WebUI

Read more

2026 Git 安装流程和基础使用步骤(保姆级教程)

2026 Git 安装流程和基础使用步骤(保姆级教程)

文章目录 * 前言 * 一、 Git 下载与保姆级安装步骤 * 二、 环境配置 * 配置 Notepad++ 为默认编辑器 * 三、 从零开始:Git 基础工作流 * 四、 新手必看:高频“翻车”坑点与解决方案 前言 Git 工具大家应该挺熟悉的,Git 是管理代码的工具,无论是在搭建前后端分离的复杂架构,还是在调试庞大的深度学习模型,一个清晰、规范的版本控制系统能帮你避开无数次“代码重构”带来的崩溃。Git 工具在大学期间实训时和工作中都会用到,那么今天在新电脑上手把手安装 Git 工具。 一、 Git 下载与保姆级安装步骤 前往 Git 官方网站(https://git-scm.com/),如下图点击 下载最新的 64-bit Git for Windows

Dify(Agent + RAG)指南:从安装到实战的开源 LLM 应用开发平台

Dify 完全指南:从安装到实战的开源 LLM 应用开发平台 摘要:本文详细介绍开源 LLM 应用开发平台 Dify 的完整使用流程,包括本地部署、API 配置、工作流编排、知识库管理,以及跨境电商客服和 Text2SQL 两个实战案例。 目录 1. Dify 简介 2. 本地部署指南 3. API 配置与集成 4. 自定义工具开发 5. 工作流类型详解 6. 知识库管理 7. 实战案例:跨境电商客服 8. 实战案例:Text2SQL 数据库查询 9. 网页集成方案 10. 总结与建议 1. Dify 简介 1.1

OpenClaw(龙虾)开源AI智能体科普解析:核心原理、功能特性与本地部署教程

近期开源AI领域,OpenClaw(俗称“龙虾”)凭借其本地优先、可定制的特性,受到开发者社区的广泛关注,其项目保活程度与社区活跃度可通过GitHub数据直观体现:目前该项目已获得222k stars、1.2k watching、42.3k forks,各项数据均处于开源AI智能体领域前列,足以证明其社区认可度与持续更新能力。作为一款开源AI智能体工具,它在办公自动化、系统辅助等场景具有实用价值,适合开发者了解和落地实践。 OpenClaw是一款开源的个人AI助手编排平台,采用TypeScript开发,目前在GitHub上拥有较高的关注度,其核心价值在于将大模型的推理能力与本地系统操作相结合,打破了传统AI助手“仅能交互、无法执行”的局限。本文将从技术科普角度,围绕OpenClaw的核心定义、功能特性、技术细节及本地部署步骤展开,帮助开发者全面了解这款工具的原理与使用方法。 对于ZEEKLOG的开发者群体而言,了解OpenClaw的技术架构与应用场景,既能拓展AI智能体的认知边界,也能将其应用于日常开发、办公场景,提升工作效率。 本文将从「核心定义、功能特性、技术细节、本地部署」

Chaterm — 开源SRE副驾驶,让你与服务器直接对话!

Chaterm — 开源SRE副驾驶,让你与服务器直接对话!

Chaterm 是一款开源AI智能终端和SSH客户端。Chaterm旨在解决大规模云环境下服务器批量化操作、故障排查复杂和安全管控困难等痛点。它将 AI Agent能力嵌入终端,通过打造“对话式终端管理工具”,帮助服务端开发者、DEVOPS工程师、云计算从业人士实现云资源的智能化和规模化管理。 图说:Chaterm的核心能力包括:命令语法高亮,关键词高亮,智能命令补全,零信任安全连接,Agent智能智能代理,移动端语音输入控制,MCP功能,Agent Skills等 AI 智能助手:让运维更简单:Chaterm不仅提供 AI 对话和终端命令执行功能,更具备基于 Agent 的 AI 自动化能力,可以通过自然语言设定目标,由 AI 自动规划,并一步一步执行,最终达成需要完成的任务。 1. 智能命令生成:说出你的需求,AI 自动生成对应的 Shell 命令 2. 上下文理解:AI

阿里云全品类 8 折券限时领,建站 / AI / 存储通用 立即领取