OpenAI 终于发力了,今天清晨更新了一大波内容,让我们一起来看看:

  • Chat Completions API 中现在支撑函数调用了,也就是说为 API 接口定义了一套标准的插件标准!

  • 新增了 gpt-4-0613gpt-3.5-turbo-0613 模型

  • 新增了支撑 16k 上下文gpt-3.5-turbo-16k 模型

  • 嵌入模型本钱下降 75%

  • gpt-3.5-turbo 模型 tokens 本钱下降 25%

  • gpt-3.5-turbo-0301gpt-4-0314 模型行将被抛弃

函数调用

OpenAI API 现在支撑函数调用了,但仅限于 gpt-4-0613gpt-3.5-turbo-0613 模型,其实就是支撑插件了!应用场景:

  • 创建聊天机器人,经过调用外部工具(例如 ChatGPT 插件)来回答问题
  • 将自然语言转换为 API 调用或数据库查询
  • 从文本中提取结构化数据

函数调用举例

OpenAI 重磅更新,支持自定义函数调用!

1、运用函数和用户的输入调用模型

恳求:

curl https://api.openai.com/v1/chat/completions -u :$OPENAI_API_KEY -H 'Content-Type: application/json' -d '{
  "model": "gpt-3.5-turbo-0613",
  "messages": [
    {"role": "user", "content": "What is the weather like in Boston?"}
  ],
  "functions": [
    {
      "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"]
      }
    }
  ]
}'

呼应:

{
  "id": "chatcmpl-123",
  ...
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": null,
      "function_call": {
        "name": "get_current_weather",
        "arguments": "{ "location": "Boston, MA"}"
      }
    },
    "finish_reason": "function_call"
  }]
}

2、调用第三方 API

恳求:

curl https://weatherapi.com/...

呼应:

{ "temperature": 22, "unit": "celsius", "description": "Sunny" }

3、将呼应发送回模型进行汇总

恳求:

curl https://api.openai.com/v1/chat/completions -u :$OPENAI_API_KEY -H 'Content-Type: application/json' -d '{
  "model": "gpt-3.5-turbo-0613",
  "messages": [
    {"role": "user", "content": "What is the weather like in Boston?"},
    {"role": "assistant", "content": null, "function_call": {"name": "get_current_weather", "arguments": "{ "location": "Boston, MA"}"}},
    {"role": "function", "name": "get_current_weather", "content": "{"temperature": "22", "unit": "celsius", "description": "Sunny"}"}
  ],
  "functions": [
    {
      "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"]
      }
    }
  ]
}'

呼应:

{
  "id": "chatcmpl-123",
  ...
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "The weather in Boston is currently sunny with a temperature of 22 degrees Celsius.",
    },
    "finish_reason": "stop"
  }]
}

OpenAI 重磅更新,支持自定义函数调用!

新模型

GPT-4

GPT-4 新增了 2 个模型,gpt-4-0613gpt-4-32k-0613 ,均支撑函数调用,而且支撑更长的上下文和更好的语义理解。

GPT-3.5 Turbo

GPT-3.5 新增了 2 个模型,gpt-3.5-turbo-0613gpt-3.5-turbo-16k

gpt-3.5-turbo-0613 支撑函数调用,而且对 system 类型的音讯具有更好的操控,呼应速度更快!

gpt-3.5-turbo-16k 支撑更长的上下文,单个恳求中支撑约 20 页文本输入。

抛弃模型

gpt-3.5-turbo-0301gpt-4-0314 以及 gpt-4-32k-0314 行将抛弃运用。

费用情况

嵌入模型

text-embedding-ada-002 本钱下降 75%,现在费用是 $0.0001/1K tokens

GPT-3.5 Turbo

gpt-3.5-turbo 本钱下降 25%,费用明细:

输入:$0.0015/1K input tokens

输出:$0.002/1K output tokens

gpt-3.5-turbo-16k 费用明细:

输入:$0.003/1K input tokens

输出:$0.004/1K output tokens

总的来说就是新增了函数调用功用,更长的上下文支撑,更低的本钱。

树先生开发的 ChatGPT 镜像网址也在第一时间更新了上述模型,欢迎体会!函数调用功用行将更新,敬请期待~

OpenAI 重磅更新,支持自定义函数调用!