common.title

Docs
Quantum Circuit
TYTAN CLOUD

QUANTUM GAMING


Overview
Contact
Event
Project
Research

Terms of service (Web service)

Terms of service (Quantum and ML Cloud service)

Privacy policy


Sign in
Sign up
common.title

blueqat cloudでChatGPTのAPIを利用する

Yuichiro Minato

2023/03/08 00:34

普通はローカルのjupyter環境やGoogle Colabなどを利用するのでしょうが、自分は使い勝手が良いので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

© 2025, blueqat Inc. All rights reserved