自定义GPT的OpenAI Actions:修改OpenAPI Schema实现文件与字符串同传
修改OpenAPI Schema实现图片与字符串同时传输
原Schema的问题在于将字符串放在URL查询参数中,而图片放在请求体的multipart表单里,ChatGPT工具调用时无法同时处理这两种参数形式。需要把字符串也整合到multipart/form-data的请求体中,让整个请求统一为表单提交格式。
修改后的完整Schema
{ "openapi": "3.1.0", "info": { "title": "Send an image and a string", "description": "接收字符串与图片文件的接口", "version": "v1.0.0" }, "servers": [ { "url": "https://myawesomeserver.loca.lt" } ], "paths": { "/api/gpt/create": { "post": { "description": "同时接收字符串和图片并处理", "operationId": "CreateImageandString", "requestBody": { "description": "包含字符串和图片的表单数据", "required": true, "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "an_awesome_string": { "type": "string", "description": "需要传递的字符串内容" }, "image": { "type": "string", "format": "binary", "description": "需要上传的图片文件" } }, "required": ["an_awesome_string", "image"] } } } }, "deprecated": false } } }, "components": { "schemas": {} } }
关键修改点
- 移除原有的
parameters数组,不再通过URL查询参数传递字符串 - 将
an_awesome_string字段移到multipart/form-data的schema属性中,和image一起作为表单字段 - 在schema的
required数组中同时声明两个字段为必填,确保请求同时包含两者 - 调整接口和请求体的描述,明确说明功能
这样修改后,ChatGPT工具调用时会将字符串和图片打包成一个multipart表单请求发送到你的服务器,就能同时接收两种数据了。
内容的提问来源于stack exchange,提问作者Philip7899
相关产品推荐
相关产品推荐

