見出し画像

GPT CustomizerやActionsGPTで外部APIを利用したGPTsを簡単に作成

外部APIを利用したGPTsがなかなか上手く作れなくて悩んでいたのですが、とても便利なGPTを見つけたので紹介します。

そのGPTは「GPT Customizer, File Finder & JSON Action Creator」という名前で、通称GPT Customizerと呼んでいます。



1.APIの探し方

GPTsで利用するAPIを探すには、APIのまとめサイトを利用するのが便利です。今回は参考までに、まとめサイトを2つ紹介します。

今回は、「一風変わったWeb APIをまとめてみた」で紹介されていたDog APIを利用します。Dog APIは、ランダムに犬の画像を返してくれるAPIです。
API: https://dog.ceo/api/breeds/image/random


2.GPT Customizerでコードを作成

それでは、早速、GPT Customizerに、Dog APIから情報(犬の画像)を取得するためのコードを作成してもらいます。

まず、以下のバナーをクリックして、GPT Customizerを立ち上げます。

そして、入力欄に「https://dog.ceo/api/breeds/image/random」と入力すると、GPT Customizerが以下のようなJSONコードを作成します。

{
  "openapi": "3.1.0",
  "info": {
    "title": "Random Dog Image Fetcher",
    "version": "1.0.0",
    "description": "This API fetches a random dog image from Dog CEO's Dog API."
  },
  "servers": [
    {
      "url": "https://dog.ceo/api"
    }
  ],
  "paths": {
    "/breeds/image/random": {
      "get": {
        "summary": "Get a Random Dog Image",
        "operationId": "getRandomDogImage",
        "responses": {
          "200": {
            "description": "A random dog image URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "format": "url",
                      "description": "URL of the dog image"
                    },
                    "status": {
                      "type": "string",
                      "description": "Status of the API request"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

後で、GPT BuilderのSchemaの欄にこのコードを貼り付けます。


3.「犬の写真」GPTの作成

まず、ChatGPTのメニューから「探索する」を選び、「Create a GPT」をクリックして、GPT Builderを立ち上げます。
次に、Configureモードにして、以下のように入力します。

Name:犬の写真
Description:ランダムに犬の写真を表示します
Instructions:
外部APIから犬の画像を取得して表示します。
Conversation starters:
犬の写真をください。
Capabilities:チェックをすべて外す。

次に、「新しいアクションを作成」をクリックして、Add actionsのページに移ります。
そこで、GPT Customizerが作成したJSONコードをSchemaの欄に貼り付けます。
最後に、Privacy policyの欄に「https://dog.ceo/dog-api/about」と入力します。

これで完成です!

このGPTの実行例は以下のとおりです。


4.ActionsGPTでコードを作成

GPT Builderに付属するActionsGPTでも、外部APIを利用するためのコードを書くことができます。

「新しいアクションを作成」をクリックして、Add actionsのページに行くと、Schemaの欄の右下に「Get help from ActionsGPT」という表示が現れます。

これをクリックすると、ActionsGPTが立ち上がります。ここで、入力欄に「https://dog.ceo/api/breeds/image/random」と入力すると、ActionsGPTが以下のようなコードを作成します。

openapi: 3.0.0
info:
  title: Dog CEO API
  description: API for retrieving random images of dogs.
  version: 1.0.0
servers:
  - url: https://dog.ceo/api
    description: Main API server
paths:
  /breeds/image/random:
    get:
      operationId: getRandomDogImage
      summary: Returns a random dog image
      description: Retrieves a single random image from the all dogs collection.
      responses:
        '200':
          description: A random dog image URL in JSON format
          content:
            application/json:
              schema: 
                type: object
                properties:
                  message:
                    type: string
                    description: The URL of the random dog image
                  status:
                    type: string
                    description: Response status

なお、OpenAPIのバージョンは、GPT Customizerでは3.1.0でしたが、ActionsGPTでは3.0.0になっています。

このコードをSchemaの欄に貼り付けて使用しても、GPT Customizerの場合と同じように正常に動作します。


5.「アメリカンジョーク・ジェネレーター」の作成

ActionsGPTを利用して、もう一つGPTを作成しました。
使用したAPIは、Official Joke APIです。

API: https://official-joke-api.appspot.com/jokes/random

Official Joke APIから情報を取得するためにActionsGPTが作成したコードは以下のとおりです。

openapi: 3.0.0
info:
  title: Joke API
  description: API for fetching random jokes.
  version: 1.0.0
servers:
  - url: https://official-joke-api.appspot.com
    description: Official Joke API server
paths:
  /jokes/random:
    get:
      operationId: getRandomJoke
      summary: Returns a random joke.
      description: Fetches a random joke from the Joke API.
      responses:
        '200':
          description: A JSON object containing a random joke
          content:
            application/json:
              schema: 
                type: object
                properties:
                  id:
                    type: integer
                  type:
                    type: string
                  setup:
                    type: string
                  punchline:
                    type: string

そして、GPT Builderでの設定は以下のとおりです。

アメリカンジョーク・ジェネレーターの実行例は以下のとおりです。

この記事が気に入ったらサポートをしてみませんか?