blueqat cloudでChatGPTのAPIを利用する

blueqat cloudでChatGPTのAPIを利用する by Yuichiro Minato | blueqat

使い勝手の良いblueqat cloudを利用紹介。

有料版、無料版を問わず、ChatGPTのAPIを呼び出して利用することができます。

手順は、

1、APIトークンを手に入れる

2、blueqat cloudにログインしてPythonでAPIを呼び出す

3、結果を確認

と大変簡単となっています。

APIキー

自分のマイアカウントからAPIキーを確認できます。

https://platform.openai.com/account/api-keys

blueqat cloudにログイン

トップページからログインをしてCloudボタンを押します。

ツールをインストールして、コードを記述

openaiのライブラリのインストールは簡単でした。

!pip install openai

APIトークンの登録は様々ありますが、ざっくりダイレクトに設定しました。

openai.api_key = "ここにコピーしたAPIトークン"

あとは、ベースのチュートリアル通りに書いてみました。

# Note: you need to be using OpenAI Python v0.27.0 for the code below to work
import openai

result = openai.ChatCompletion.create(
 model="gpt-3.5-turbo",
 messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)

今回は純粋にAPIを叩いただけなので、なんでもいいのですが、

print(result.choices[0].message.content)
#print(result["choices"][0]["message"]["content"])

こんな感じで結果が取り出せます。

The World Series was played in a neutral site at Globe Life Field in Arlington, Texas in 2020 due to the COVID-19 pandemic.

他の詳しい仕組みに関してはChatGPTのサイトを参照してください。

https://openai.com/blog/introducing-chatgpt-and-whisper-apis 

出典:https://blueqat.com/yuichiro_minato2/67513d7a-7c0a-4cf0-b02d-4d78503d21e6