シュッと GPTs の Action について書いてみた
ちゃっす(/・ω・)/
お久しブリーフ(/・ω・)/
GPTs ストアがでるということでエンジニア以外の方が分かりやすい GPTs の Action 機能についてまとめているといいかもかも~( ・ω・)?
と思ったので筆をとってみたでござる(/・ω・)/
(エンジニアの方は特に得るものないと思うでござんす)
OpenAI の公式ページの内容を翻訳しながらまずはふわっと
What is a GPT?
要するに ChatGPT の戦闘力を上げるための機能っちゅーことですな(/・ω・)/
What is an action?
ちょっと入り組んでまいりましたな(/・ω・)/
まぁ、ChatGPT だけではなく、質問の内容に応じて別のプログラムを利用してよりいい感じのことができるような機能を GPT の Action というわけですな(/・ω・)/
Create an Action
Action の使い方ですな(/・ω・)/
まぁ、文章で見てもわかりにくいので実際に作ってみるのだ(/・ω・)/
スクリーンショットを載せてわかりやすくするぞ☆
(ChatGPT の有料版を契約している必要があるぞよ☆)
とりあえず YouTube の検索でもしてみましょうかね( ・ω・)
一個ずつみていきますわよ(/・ω・)/
Authentication
認証のことでございますわ(/・ω・)/
この Action ではいわゆる API というものを利用するでござんす
API というのはまぁ、とある機能をプログラムから呼び出すためのものですな(/・ω・)/
今回の例でいうと YouTube の動画を取得する、、、という API を利用するでござんす
で、この API の種類によっては誰でも使えるもの、特定の認証情報を必要とするものなど種類があるのでございます。
None は誰でも自由に使えるよ~んってやつ
API Key は Key を持っていれば使えるよ~んってやつ
OAuth っていうのはまぁ、本人確認いるよ~んくらいに思っておけばよいでござんす(何かログインする時に Google アカウントとか選択するやつ)
今回お試しする YouTube の API は API Key を選ぶのであ~る(/・ω・)/
Basic, Bearer, Custom というのは認証の種類ですな(/・ω・)/
Basic ってのは名前とパスワードでシュッと認証するやつ
Bearer ってのは一般的なやつ
Custom ってのは独自の形式
今回は Bearer ってのを選択するぞ☆
Schema
スキーマってなんじゃらほい( ・ω・)?
API というのは特定の機能を呼び出すわけでございますが、その呼び出し方にお作法というのがございますの(/・ω・)/
で、スキーマはそのお作法と思っておけばよいですの(/・ω・)/
で、スキーマというのは利用する API ごとに異なるので利用する内容によって変わってきますわよ(/・ω・)/
とりあえず今回は YouTube の API を使うのでお作法を公式ページに確認しにいきますわよ~(/・ω・)/
はい、まぁ見てもらって( ・ω・)???
となるかもしれませんな(/・ω・)/
しかし恐れることはないのであ~る(/・ω・)/
必要な情報は
どういう URL を使うの?
必要な機能を使う場合に利用する URL はどうなるの?
どういった情報を渡す必要があるの?
どういう結果が返ってくるの?
くらいである(/・ω・)/
そしてスキーマの作成を手伝ってくれる GPTs が公開されているのであ~る(/・ω・)/
雑に聞いてみる
openapi: 3.0.0
info:
title: YouTube Video Search API
description: This API retrieves a list of YouTube videos based on search parameters.
version: 1.0.0
servers:
- url: https://www.googleapis.com/youtube/v3
paths:
/search:
get:
operationId: searchVideos
summary: Search for YouTube videos
parameters:
- name: part
in: query
required: true
description: Comma-separated list of properties that the API response will include.
schema:
type: string
example: snippet
- name: maxResults
in: query
description: Maximum number of items that should be returned in the result set.
schema:
type: integer
example: 10
- name: pageToken
in: query
description: Page token to retrieve a specific page in the result set.
schema:
type: string
- name: q
in: query
description: Textual search terms to match.
schema:
type: string
responses:
'200':
description: Successful response containing a list of search results.
content:
application/json:
schema:
type: object
properties:
items:
type: array
items:
type: object
properties:
id:
type: object
properties:
videoId:
type: string
snippet:
type: object
properties:
title:
type: string
description:
type: string
thumbnails:
type: object
properties:
default:
type: object
properties:
url:
type: string
教えてくれた(/・ω・)/
細かく見ていきましょ~
# API の形式(気にしなくてよい)
openapi: 3.0.0
# API の情報
info:
title: YouTube Video Search API
description: This API retrieves a list of YouTube videos based on search parameters.
version: 1.0.0
# 利用する API の URL
servers:
- url: https://www.googleapis.com/youtube/v3
# API で利用する具体的なパス(URL)
paths:
# https://www.googleapis.com/youtube/v3/search を使うという意味
/search:
# API を呼び出す形式を表す大体 get or post
# get は URL の後ろに ?query=value みたいに情報を付与することで取得する情報を細かく指定できるやつと思っておくとよい
# post は URL で取得する情報を指定できない感じ
get:
operationId: searchVideos
summary: Search for YouTube videos
# API search に渡す情報
parameters:
- name: part # part という情報
in: query # クエリ(URL の後ろ)につけますよ
required: true # 必須かどうか true or false
description: Comma-separated list of properties that the API response will include.
schema:
type: string # この情報はどういった型を持つか?(今回は文字列)
example: snippet # サンプル
# API から返ってくる期待する情報の形式
responses:
'200': # 200 (正常にデータを取得できた場合)
description: Successful response containing a list of search results.
content:
application/json: # どういう形式で情報が返ってくるか?(今回は JSON という形式)
schema:
type: object
properties:
items: # items という項目で
type: array # 複数の情報が返ってきますよ
items:
type: object
properties:
id: # item には id があります
type: object
properties:
videoId: # id には videoId があります
type: string
snippet: # item には snippet があります
type: object
properties:
title: # snippet には title があります
type: string
description: # snippet には description があります
type: string
thumbnails: # snippet には thumbnails があります
type: object
properties:
default:
type: object
properties:
url: # thumbnails には url があります
type: string
みたいな感じ(/・ω・)/
で、この設定をコピペするーの
するとこういうのが出てくるのでテストしてみまひょ(/・ω・)/
結果、、、失敗☆
ちょっと細かい話なので割愛しますがこの YouTube API を GPT で利用する倍に API Key の設定がうまくいかんようである( ・ω・)
というわけで、OAuth 認証に変更してみるぞ☆
ので、
これに合わせてスキーマに情報を足すのだ☆
- 略 -
servers:
- url: https://www.googleapis.com/youtube/v3
security:
- OAuth2:
- https://www.googleapis.com/auth/youtube.readonly
- https://www.googleapis.com/auth/youtube.force-ssl
securitySchemes:
OAuth2:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://accounts.google.com/o/oauth2/auth
tokenUrl: https://oauth2.googleapis.com/token
scopes:
https://www.googleapis.com/auth/youtube.readonly: Read-only access to YouTube data
https://www.googleapis.com/auth/youtube.force-ssl: force ssl
paths:
- 略 -
ほいで再度テスト
はい、失敗☆
YouTube の API は認証周りでちょいとうまくいかないですが、他の API を利用する場合は同じようにやったらいいと思いんす(/・ω・)/
Actions の設定の下にある Additional Settings のチェックを外しておかないと GPT でのやり取りを OpenAI が学習に使っちゃうので注意だぞ☆
というわけでシュッと書いたのでおしまい。
この記事が気に入ったらサポートをしてみませんか?