微信扫码
与创始人交个朋友
我要投稿
“ 最近flux又更新了,推出了fluxpro1.1版本。今天手把手教你接入fal平台的fluxpro1.1模型到dify中。”
本次教程附演示工作流和dify自定义工具swagger源码,已测试通过。
dify测试版本:0.7.x 以上
作者实测dify版本:0.8.3
特别说明:
有小伙伴看我之前公众号发的flux接入到dify,最近大家反应用不了了。
【附工具源码】手把手教你把flux pro模型接入到dify工具中
【Dify工作流实操案例】根据用户输入的一段文本自动调用fluxpro绘制成多张配图
我仔细看了fal平台的接口文档,发现官方改了接口逻辑和api域名。从原来的阻塞请求获取图片url,改成了异步请求获取。这就造成很多小伙伴一下子用不了了,特此解释一下,也请大家理解,不是作者之前瞎写,而是fal平台技术方案的更新造成的。今天带来的是适配fal平台最新接口方案的教程。
01
—
先创建dify自定义工具
fluxpro1.1模型是新模版,目前属于不开源的,所以fal平台咱们还得用。
本次咱们创建的自定义工具跟之前的有所不同,有三个工具可用:
发起任务请求
查询任务状态
获取任务结果
先放出swagger源码,如下所示:
{"openapi": "3.1.0","info": {"title": "fluxpro1.1","description": "API,用于提交任务并从FLUX服务检索结果。微信公众号:提示日记","version": "1.0.0"},"tags": [],"paths": {"/v1.1": {"post": {"summary": "提交任务","operationId": "提交任务","deprecated": false,"description": "提交你的提示词到fluxpro中","tags": [],"parameters": [{"name": "Authorization","in": "header","description": "别忘了输入Key。参考示例:“Key 016b1acf-09f8-47f8-b405-ede28fa62053:fa3ca05df7d4b8d99a9af9e44ea61234”","required": true,"example": "Key 016b1acf-09f8-47f8-b405-ede28fa62053:fa3ca05df7d4b8d99a9af9e44ea61234","schema": {"type": "string"}}],"requestBody": {"content": {"application/json": {"schema": {"type": "object","properties": {"prompt": {"type": "string","title": "提示词","description": "图片提示词"},"image_size": {"type": "string","title": "图片宽高比","description": "生成图像的宽高比。可选项为:square_hd, square, portrait_4_3, portrait_16_9, landscape_4_3, landscape_16_9。默认值:landscape_4_3。","default": "landscape_4_3","enum": ["square_hd","square","portrait_4_3","portrait_16_9","landscape_4_3","landscape_16_9"],"examples": ["landscape_4_3"]},"seed": {"type": "integer","description": "对同一版本的模型使用相同的种子和相同的提示,每次都会输出相同的图像。","title": "种子"},"sync_mode": {"type": "boolean","title": "请求方式","description": "如果设置为true,函数将等待图像生成和上传,然后返回响应。","default": true},"enable_safety_checker": {"type": "boolean","title": "启用安全检查器","description": "是否启用内容安全检查。","default": true},"safety_tolerance": {"type": "integer","title": "安全公差","description": "指的是生成图像的安全容差级别。最小值1,最大值5。默认值:2。","default": 2,"examples": [2]}},"required": ["prompt"]}}}},"responses": {"200": {"description": "成功,返回任务信息","content": {"application/json": {"schema": {"type": "object","properties": {"status": {"type": "string","example": "IN_QUEUE"},"request_id": {"type": "string","example": "995785bf-515b-46a2-b70d-ed65bb57a0d8"},"response_url": {"type": "string","example": "https://queue.fal.run/fal-ai/flux-pro/requests/995785bf-515b-46a2-b70d-ed65bb57a0d8"},"status_url": {"type": "string","example":"https://queue.fal.run/fal-ai/flux-pro/requests/995785bf-515b-46a2-b70d-ed65bb57a0d8/status"},"cancel_url": {"type":"string","example":"https://queue.fal.run/fal-ai/flux-pro/requests/995785bf-515b-46a2-b70d-ed65bb57a0d8/cancel" }, "logs":{"type":"null" }, "metrics":{"type":"object","properties":{"inference_time":{"type":"number","format":"float","example":"12.625"}} }}}}}}},"security": []}},"/requests/{requestId}/status": {"get": {"summary": "获取任务执行状态","operationId": "获取任务执行状态","deprecated": false,"description": "获取任务执行状态","tags": [],"parameters": [{"name": "requestId","in": "path","description": "任务请求 ID","required": true,"schema": {"type": "string"}}],"responses": {"200": {"description": "返回任务状态信息","content": {"application/json": {"schema": {type: object,properties: {status: {type: string,example: COMPLETED},request_id: {type: string,example: 995785bf-515b-46a2-b70d-ed65bb57a0d8},response_url: {type: string,example: https://queue.fal.run/fal-ai/flux-pro/requests/995785bf-515b-46a2-b70d-ed65bb57a0d8},status_url: {type: string,example: https://queue.fal.run/fal-ai/flux-pro/requests/995785bf-515b-46a2-b70d-ed65bb57a0d8/status},cancel_url: {type: string,example: https://queue.fal.run/fal-ai/flux-pro/requests/995785bf-515b-46a2-b70d-ed65bb57a0d8/cancel},logs: {type: null},metrics: {type: object,properties: {inference_time: {type: number,format: float,example: 12.625}}}}}}}}},security: []}},"/requests/{requestId}": {get: {summary: "获取任务结果",operationId: "获取任务结果",parameters: [{name: requestId,in: path,required: true,description: 任务请求 ID,schema: {type: string}}],responses: {200: {description: 返回任务结果信息,content: {application/json: {schema: {type: object,properties: {images: {type: array,items: {type: object,properties: {url: {type: string,format: uri,example: https://fal.media/files/lion/TwKB1DsgbgqSPj8eemWyd_dc775490b2d849fda048c952d5901ad5.jpg},width: {type: integer,example: 1024},height: {type: integer,example: 768},content_type: {type: string,example: image/jpeg}}}},timings: {type: object,additionalProperties: {}},seed: {type: integer,example: 3332993853},has_nsfw_concepts: {type: array,items: { type: boolean }},prompt: {type: string,example: Extreme close-up of a single tiger eye, direct frontal view. Detailed iris and pupil. Sharp focus on eye texture and color. Natural lighting to capture authentic eye shine and depth. The word \"FLUX\" is painted over it in big, white brush strokes with visible texture.}}}}}}}}}},components: {schemas: {},securitySchemes: {}},servers: [{url: https://queue.fal.run/fal-ai/flux-pro}]}
如果你直接使用上文的源码,你的dify工具详情应该是如上图所示一样。
02
—
配套示例工作流
如果你用过我之前写的工作流,你会发现,现在用fluxpro1.1模型变得复杂了,因为接口改动的原因,工具从原来的一个,变成了异步的三个,并且这三个在工作流中是环环相扣的。
大家在用的过程中有个细节要特别注意:
目前dify对于这种异步任务处理起来非常的麻烦,我这个示例工作流,无奈之下,用代码节点写了一个暂停15秒的脚本内容,因为fal平台获取到一个任务之后,我们并不知道它到底要多长时间才能把图片生成出来,所以要根据查询任务状态的工具进行判断,如果状态工具返回的结果内容不是COMPLETED,就要执行暂停脚本,如果是COMPLETED,就执行获取图片结果的工具,最终获得图片的url。
如果大家运行工作流的时候,发现没有输出图片的url,说明暂停的15秒不够,你就手动修改一下对应代码节点,把数值调大一些。目前我能想到的解决办法只有这一个,我曾尝试用迭代节点实现循环查询,发现行不通,如果有知道如何处理的小伙伴,欢迎给我留言。
如何获取DSL工作流源文件?
请在公众号对话页面输入:fluxpro1.1
如果觉得不错,就点个关注吧!
53AI,企业落地应用大模型首选服务商
产品:大模型应用平台+智能体定制开发+落地咨询服务
承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2024-11-15
dify案例分享-基于jina和http实现36氪新闻热榜文章
2024-11-10
安装 Dify 并集成 Ollama 和 Xinference
2024-11-05
【附案例源码】把阿里云验证码短信接入到dify中
2024-11-05
Dify 中的 Bearer Token 与 API-Key 鉴权方式
2024-11-01
Gitee AI 入驻 Dify,成倍加速 AI 应用开发落地
2024-10-27
免费使用 Mistral AI 并将其添加到 Dify 中使用
2024-10-26
一文带你了解Make、Coze、Dify 三大自动化平台的优缺点
2024-10-25
看一看 48Kstar 的Dify,是如何将 AI 研发的难度从天花板拉到地板之下的
2024-04-25
2024-04-24
2024-07-20
2024-05-08
2024-05-07
2024-07-16
2024-05-09
2024-04-25
2024-06-21
2024-07-08