LoginSignup
3
6

More than 1 year has passed since last update.

【Python】ChatGPT 3.5 APIを使ってみた

Last updated at Posted at 2023-01-08

ChatGPTとは

OpenAIが開発した自然言語生成モデル

ChatGPTをブラウザで使ってみる

OpenAIにログインして、下記のサイトを開くとすぐに利用できる。
英語も日本語も対応しているのすごすぎ!

API

APIキーの取得は非常に簡単で、OpenAIのホームページの右上の自分のアイコンをクリックして、View API keysを押す。
そのページでCreate new secret keyのボタンを押すとAPIキーが取得できる。

Pythonモジュールは以下のコマンドでインストールする。

pip install openai
sample.py
import os
import openai

openai.api_key = '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'

start_sequence = "\nAI:"
restart_sequence = "\nHuman: "

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="Human: おはよう",
  temperature=0.9,
  max_tokens=150,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0.6,
  stop=[" Human:", " AI:"]
)

print(response['choices'][0]['text'].replace('\n', ''))

まとめ

OpenAIが提供するChatGPT APIを使ってみた。ここまですごい大規模言語モデルのAIが無料で試用できるのはすごい。

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6