Chat Completionsは、OpenAIの最新モデルで使用する標準APIです。使い始め方については、テキスト生成の開発者ガイドをご覧ください。
2025年3月11日現在、新しいAgentsプラットフォームの構成要素を公開しました。詳細は、Responses APIのAPIドキュメント、Web Search、File Search、Computer Useなどのツール、そしてAgents SDK(Tracing対応)をご覧ください。
PromptsからMessagesへ
モデルとよりインタラクティブで動的なやり取りをするには、Completionsで使われていた従来のプロンプト形式の代わりに、チャット形式のmessagesを使用できます。
仕組みは次のとおりです:
プロンプトとして単一の文字列を送る代わりに、入力としてメッセージのリストを送ります。
リスト内の各メッセージには、roleとcontentという2つのプロパティがあります。
「role」は、「system」「user」「assistant」のいずれかの値を取ります。
「content」には、そのroleからのメッセージ本文が入ります。
systemの指示で、会話全体に対する高レベルの指示を与えられます。
メッセージはリストに現れる順に処理され、アシスタントはそれに応じて応答します。
以下のとおり、基本的なCompletionsのリクエストでもChat Completionsで実行できます:
| 以前 | 現在 |
'prompt' : 'tell me a joke' | 'messages': [{'role':'user', 'content':'tell me a joke'}] |
会話内のmessagesリストを拡張することで、これまで以上にモデルと双方向のやり取りがしやすくなります。
'messages': [{'role':'user', 'content':'tell me a joke'},
{'role':'assistant', 'content':'why did the chicken cross the road'},
{'role':'user', 'content':'I don't know, why did the chicken cross the road'}]System Instructions
会話全体を通してモデルの振る舞いを導くために、systemレベルの指示も利用できます。たとえば、次のようなsystem指示とメッセージを使うと
'messages': [{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},
{'role':'user', 'content':'tell me a joke'}, 次のような結果になります
{...
'message': {'role':'assistant',
'content':'Why did the chicken cross the road? To get to the other side, but verily, the other side was full of peril and danger, so it quickly returned from whence it came, forsooth!'}
...}メッセージの会話履歴を自分で管理しなくて済む選択肢を検討したい場合は、Assistants APIをご覧ください。
