109 | Dify2OpenAI 是一个将 Dify 应用程序转换为 OpenAI API 接口的网关服务,使您可以使用 OpenAI API 兼容的方式与 Dify 应用进行交互。 110 |
111 |参数 | 134 |说明 | 135 |示例 | 136 |
---|---|---|
DIFY_API_URL | 141 |Dify 服务的 API 基础 URL | 142 |143 | https://cloud.dify.ai/v1 144 | | 145 |
API_KEY | 148 |Dify 应用的 API 密钥 | 149 |150 | app-xxxx 151 | | 152 |
BOT_TYPE | 155 |应用类型(Chat、Completion、Workflow) | 156 |157 | Chat 158 | | 159 |
INPUT_VARIABLE | 162 |输入变量名称(仅 Workflow 类型需要) | 163 |164 | input 165 | | 166 |
OUTPUT_VARIABLE | 169 |输出变量名称(仅 Workflow 类型需要) | 170 |171 | output 172 | | 173 |
✔️ Authorization Header 格式:
192 |✔️ 示例:
198 |model
参数设置为 dify
curl http://localhost:3099/v1/chat/completions \ 216 | -H "Content-Type: application/json" \ 217 | -H "Authorization: Bearer https://cloud.dify.ai/v1|app-xxxx|Chat" \ 218 | -X POST \ 219 | -d '{ 220 | "model": "dify", 221 | "stream": true, 222 | "messages": [ 223 | { 224 | "role": "system", 225 | "content": "You are a helpful assistant." 226 | }, 227 | { 228 | "role": "user", 229 | "content": "你好" 230 | } 231 | ] 232 | }'233 |
curl http://localhost:3099/v1/chat/completions \ 244 | -H "Content-Type: application/json" \ 245 | -H "Authorization: Bearer https://cloud.dify.ai/v1|app-xxxx|Chat" \ 246 | -X POST \ 247 | -d '{ 248 | "model": "dify", 249 | "stream": true, 250 | "messages": [ 251 | { 252 | "role": "user", 253 | "content": [ 254 | "请分析这张图片。", 255 | { 256 | "type": "image_url", 257 | "image_url": { 258 | "url": "https://example.com/image.jpg" 259 | } 260 | } 261 | ] 262 | } 263 | ] 264 | }'265 |
✔️ Authorization Header 格式:
275 |✔️ model 参数格式:
281 |curl http://localhost:3099/v1/chat/completions \ 295 | -H "Content-Type: application/json" \ 296 | -H "Authorization: Bearer app-xxxx" \ 297 | -X POST \ 298 | -d '{ 299 | "model": "dify|Chat|https://cloud.dify.ai/v1", 300 | "stream": true, 301 | "messages": [ 302 | { 303 | "role": "system", 304 | "content": "You are a helpful assistant." 305 | }, 306 | { 307 | "role": "user", 308 | "content": "你好" 309 | } 310 | ] 311 | }'312 |
curl http://localhost:3099/v1/chat/completions \ 323 | -H "Content-Type: application/json" \ 324 | -H "Authorization: Bearer app-xxxx" \ 325 | -X POST \ 326 | -d '{ 327 | "model": "dify|Chat|https://cloud.dify.ai/v1", 328 | "stream": true, 329 | "messages": [ 330 | { 331 | "role": "user", 332 | "content": [ 333 | "请分析这张图片。", 334 | { 335 | "type": "image_url", 336 | "image_url": { 337 | "url": "https://example.com/image.jpg" 338 | } 339 | } 340 | ] 341 | } 342 | ] 343 | }'344 |
✔️ Authorization Header 格式:
354 |✔️ model 参数格式:
360 |curl http://localhost:3099/v1/chat/completions \ 374 | -H "Content-Type: application/json" \ 375 | -H "Authorization: Bearer https://cloud.dify.ai/v1" \ 376 | -X POST \ 377 | -d '{ 378 | "model": "dify|app-xxxx|Chat", 379 | "stream": true, 380 | "messages": [ 381 | { 382 | "role": "system", 383 | "content": "You are a helpful assistant." 384 | }, 385 | { 386 | "role": "user", 387 | "content": "你好" 388 | } 389 | ] 390 | }'391 |
curl http://localhost:3099/v1/chat/completions \ 402 | -H "Content-Type: application/json" \ 403 | -H "Authorization: Bearer https://cloud.dify.ai/v1" \ 404 | -X POST \ 405 | -d '{ 406 | "model": "dify|app-xxxx|Chat", 407 | "stream": true, 408 | "messages": [ 409 | { 410 | "role": "user", 411 | "content": [ 412 | "请分析这张图片。", 413 | { 414 | "type": "image_url", 415 | "image_url": { 416 | "url": "https://example.com/image.jpg" 417 | } 418 | } 419 | ] 420 | } 421 | ] 422 | }'423 |
将 Dify API 无缝转换为 OpenAI API,兼容各种 OpenAI 客户端
436 |支持图像、文档、音频和视频等多种类型文件处理
443 |支持 Chat、Completion、Workflow 等不同类型的 Dify 应用
450 |