Dify.ai自定义工具 - pdf转图片
功能清单
- PDF转多张图片
使用场景:
- 进行文档展示分享:当需要在网页、PPT 等场景中展示 PDF 内容时,将其转换为图片能更方便地进行嵌入和展示。
- 便于编辑处理:把 PDF 文件变为图片后,可利用图像处理软件对图片进行裁剪、标注、添加文字等操作。
注意事项
- 注意事项:单个文件最大 30M,如需更大文件限制,请联系我们。
- 请确保文件在外网可远程下载,不支持内网访问。如果贵司的服务器设置了防火墙,请添加如下IP白名单 116.62.188.183,118.31.43.105
Dify.ai自定义工具步骤
1. 打开Coze平台,点击“工具” -> “自定义”。
2. 点击“创建自定义工具”,输入工具名称和 OpenAPI-Swagger Schema。
- 入工具名称: PDF转图片
- OpenAPI-Swagger ,复制如下代码,或者下载后复制
openapi: 3.1.0
info:
title: PDF转图片API
version: 1.0.0
description: PDF转图片API,官网支持:https://www.pdfai.cn/docs/api/dify.ai.html
servers:
- url: https://pdf-api.pdfai.cn
paths:
/v1/pdf/pdf_to_image:
post:
tags:
- PDF转图片
summary: PDF转图片
operationId: pdfToImage
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PdfToImageRequest'
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 状态码
example: 200
data:
type: object
properties:
file_url:
type: array
description: 转换后的图片URL列表
items:
type: string
example: "https://static.pdfai.cn/static/example/out/splitImage_1.png"
code_msg:
type: string
description: 状态信息
example: "成功"
required:
- code
- data
- code_msg
'500':
description: 失败
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 状态码
example: 500
data:
type: object
description: 空对象
example: {}
code_msg:
type: string
description: 错误信息
example: "处理失败: 文件下载失败"
required:
- code
- data
- code_msg
components:
schemas:
PdfToImageRequest:
type: object
required:
- app_key
- input
properties:
app_key:
type: string
description: 应用密钥,默认 app_key_dify
default: app_key_dify # 声明默认值
example: app_key_dify # 示例值保持同步
input:
type: string
format: uri
description: 远程文件地址,支撑格式PDF,需要远程访问权限,内网不支持。
example: "https://static.pdfai.cn/static/example/files/four_pages.pdf"
3. 点击“保存”,即可完成创建
如图所示:
4. 点击“测试”,测试自定义工具。
app_key 输入 app_key_dify
input 输入 https://static.pdfai.cn/static/example/files/four_pages.pdf
如图所示:
总结
- 自定义工具是 Dify.ai 平台的一个重要功能,它允许用户根据自己的需求创建和使用自定义工具。
- 自定义工具可以通过 OpenAPI-Swagger Schema 来定义,包括请求参数、响应参数等信息。
- 自定义工具可以被其他用户调用,实现自动化的任务处理。
- 可以借助 pdfai.cn 平台的 API 来实现其他自定义工具的功能。