【AI】如何编写GPTs的Actions

573 阅读1分钟

这篇文章和上篇 利用GPTs的Actions 获取第三方数据有点类似, actions 都是基于三方接口去完成自己想要的功能,不同的是,上篇是在基于有 swagger json 或者 yaml 文档的情况下, 但是如果仅仅是一个 cURL 示例呢

curl -X GET  \
  'https://eolink.o.apispace.com/456456/weather/v001/now?areacode=101010100&lonlat=116.407526,39.904030' \
  -H 'X-APISpace-Token:your key'

创建Actions

而在 GPTs Actions 创建的时候,Schema 要求的格式模板如下,json或者yaml文件都可以

{
  "openapi": "3.1.0",
  "info": {
    "title": "Get weather data",
    "description": "Retrieves current weather data for a location.",
    "version": "v1.0.0"
  },
  "servers": [
    {
      "url": "https://weather.example.com"
    }
  ],
  "paths": {
    "/location": {
      "get": {
        "description": "Get temperature for a specific location",
        "operationId": "GetCurrentWeather",
        "parameters": [
          {
            "name": "location",
            "in": "query",
            "description": "The city and state to retrieve the weather for",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "deprecated": false
      }
    }
  },
  "components": {
    "schemas": {}
  }
}

我们需要将 cURL示例转换成Schmea要求的格式, 这个可以让gpt帮我们完成,当然也可以自己写代码去转换,

下面提供几个GPTs, 试了下,第二个效果最好,

OpenAPI Schmea GPTs

GPT Customizer,File Finder JSON Action Creator

ActionsGPT

请求的时候把请求响应体带上,保证schema的完整,我这里用的是第二个GPT Customizer,File Finder JSON Action Creator

image.png

在用其它的两个GPTs 转换的时候,发现碰到这个问题,个别单词转换错误, 对应是schemas,或者去掉 components

image.png

image.png

测试

image.png

小技巧

voxscript.awt.icu/swagger/v1/…

json后缀名改成yaml就可以直接改成yaml文件