OpenAI APIリファレンス
テストテスト
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'
プロキシインタフェース
CloudFlareの使用
Base URLの設定
https://api.openai.com/v1
置き換えられた。
https://gateway.ai.cloudflare.com/v1/[xxx]/[yyy]/openai
例えば
curl https://gateway.ai.cloudflare.com/v1/45a93dd9034ce3d27b263a074d05f09a/ververv/openai/chat/completions \
Chatインタフェース定義
応答の形式を設定する
response_format
Must be one of text
or json_
.
Setting to {“type”“json_object”}
enables JSON mode which guarantees the message the model generates is valid JSON.
**Important ** when using JSON mode you must also instrthe to JSON yourself via a system or user. Without this the model may generate an unending stream of whitespace until the generation reaches the token limit resulting in a long-running and seemingly "stuck" request. Also note that the content may be parally cut off if finish_reason=""
which indicates the genexceeded max_tokens
or the sation exceeded the max context.
関数呼び出し/ツール
ツール:ツールの一覧
すべてのツールはオブジェクトであり、すべてのオブジェクトは
type:ly,only function
is ported.
関数:名前、説明、パラメータ
各パラメータの定義:
名前、パラメータの型、説明、オプション、パラメータが必要です。
例の例
** リクエスト **
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'
** 回答 **
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1699896916,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_current_weather",
"arguments": "{\n\"location\": \"Boston, MA\"\n}"
}
}
]
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 82,
"completion_tokens": 17,
"total_tokens": 99
}
}
大規模な枠組み
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston?"
}
],
"tools": [ // tool列表,与model同级
{ // 具体某个tool
"type": "function", // 类型:暂时只支持function
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
// 更具体定义
}
}
}
],
"tool_choice": "auto" // 选择哪个tool,与model同级
}
パラメータは
{
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": ["location"],
}