ChatGPT新APIが本日より使用可能に

ChatGPT

ChatGPTの新APIが本日より公開

OpenAIよりメールが届きました。

Starting today, you can build apps and products with our new ChatGPT and Whisper APIs. You can read more about the APIs and early partners’ use cases here.
ChatGPT API
The new Chat API calls gpt-3.5-turbo, the same model used in the ChatGPT product. It’s also our best model for many non-chat use cases; we’ve seen early testers migrate from text-davinci-003 to gpt-3.5-turbo with only a small amount of adjustment needed to their prompts. Learn more about the Chat API in our documentation.

Pricing
It’s priced at $0.002 per 1K tokens, which is 10x cheaper than the existing GPT-3.5 models.

日本語ですとトークンの計算が複雑すぎるのですが、どれくらい使えば、月額定額で$20のChatGPT Plusのメリットが出るのでしょうか?

単純計算だと、
1,000トークン x 10,000 x $0.002 = $20

なので、短い会話だと1会話1,000トークンで1万回。

ChatGPT 3.5 turbo API

今までと異なる点

Endpoint:

Model Endpoint
gpt-3.5-turbo /vi/chat/completions
gpt-3.5-turbo /vi/chat/completions
text-davinci-003 /v1/completions

Post Parametes:

一番の違いは、これまではプロンプトを送ると、回答(completion)が返って来ましたが、gpt-3.5-turboからは、一連のメッセージ(メッセージオブジェクトの配列)を送ると、今までの会話の続きとして対応するようです。

そのため送るメッセージはクライアント側が管理しておかなければなりません。

また、messagesパラメータはメッセージオブジェクトの配列でなければならず、各オブジェクトはロール(「システム」、「ユーザー」、「アシスタント」のいずれか)とコンテンツ(メッセージの内容)を持っています。

{“role”: “system” | “user” | “assistant”, “content”: “文章” }

text-davinci-003

{
  "model": "text-davinci-003",
  "prompt": "Say this is a test",
  "max_tokens": 7,
  "temperature": 0,
  "top_p": 1,
  "n": 1,
  "stream": false,
  "logprobs": null,
  "stop": "\n"
}

gpt-3.5-turbo

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

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?"}
    ]
)
Response

レスポンスも、テキストのみからメッセージオブジェクトに変わっています。

text-davinci-003

{
  "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
  "object": "text_completion",
  "created": 1589478378,
  "model": "text-davinci-003",
  "choices": [
    {
      "text": "\n\nThis is indeed a test",
      "index": 0,
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 7,
    "total_tokens": 12
  }
}

gpt-3.5-turbo

{
 'id': 'chatcmpl-6p9XYPYSTTRi0xEviKjjilqrWU2Ve',
 'object': 'chat.completion',
 'created': 1677649420,
 'model': 'gpt-3.5-turbo',
 'usage': {'prompt_tokens': 56, 'completion_tokens': 31, 'total_tokens': 87},
 'choices': [
   {
    'message': {
      'role': 'assistant',
      'content': 'The 2020 World Series was played in Arlington, Texas at the Globe Life Field, which was the new home stadium for the Texas Rangers.'},
    'finish_reason': 'stop',
    'index': 0
   }
  ]
}

まとめ

アシスタントの存在が、どのように作用するのか公式のプロンプトデザインを読んでもアシスタントに言及している部分がありません。
いままでのプロンプトエンジニアリングを最初から見直しが必要かもしれません。

タイトルとURLをコピーしました