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

简介: OpenAI 终于发力了,今天凌晨更新了一大波内容,让我们一起来看看:• Chat Completions API 中现在支持函数调用了,也就是说为 API 接口定义了一套标准的插件规范!• 新增了 gpt-4-0613 和 gpt-3.5-turbo-0613 模型• 新增了支持 16k 上下文的 gpt-3.5-turbo-16k 模型• 嵌入模型成本降低 75%• gpt-3.5-turbo 模型 tokens 成本降低 25%• gpt-3.5-turbo-0301 和 gpt-4-0314 模型即将被废弃

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-0613  和  gpt-3.5-turbo-0613 模型,其实就是支持插件了!应用场景:

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

函数调用举例

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"
  }]
}


新模型

GPT-4

GPT-4 新增了 2 个模型,gpt-4-0613  和 gpt-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 镜像网址 也在第一时间更新了上述模型,欢迎体验!函数调用功能即将更新,敬请期待~


相关文章
|
自然语言处理 搜索推荐 开发者
SmartArXiv——基于OpenSearch LLM智能问答版构建的智能学术论文助手正式发布
本文介绍智能学术论文助手SmartArxiv的架构、应用场景和产品功能。
2337 1
javaDataUtil将 Date 转为 LocalDateTime转Long转String转Date
javaDataUtil将 Date 转为 LocalDateTime转Long转String转Date
276 1
|
存储 算法 数据处理
数据结构从入门到精通——栈
栈,作为一种后进先出(LIFO)的数据结构,在计算机科学中扮演着重要的角色。它的特性使得它在处理函数调用、括号匹配、表达式求值等问题时具有得天独厚的优势。然而,如果我们跳出传统思维的束缚,会发现栈的用途远不止于此。
242 0
|
机器学习/深度学习 数据采集 人工智能
【AIGC】人工智能生成的漫画
【AIGC】人工智能生成的漫画
410 0
|
11月前
|
存储 应用服务中间件 云计算
深入解析:云计算中的容器化技术——Docker实战指南
【10月更文挑战第14天】深入解析:云计算中的容器化技术——Docker实战指南
315 1
|
11月前
LangChain-26 Custom Agent 自定义一个Agent并通过@tool绑定对应的工具 同时让大模型自己调用编写的@tools函数
LangChain-26 Custom Agent 自定义一个Agent并通过@tool绑定对应的工具 同时让大模型自己调用编写的@tools函数
341 3
LangChain-26 Custom Agent 自定义一个Agent并通过@tool绑定对应的工具 同时让大模型自己调用编写的@tools函数
|
存储 分布式计算 数据处理
面向业务增长的数据平台构建策略
【8月更文第13天】为了构建一个能够支持企业业务增长的数据平台,我们需要考虑几个关键的方面:数据的收集与整合(数据集成)、存储、处理和分析。本文将详细介绍这些步骤,并提供具体的代码示例来帮助理解。
328 1
|
算法 数据挖掘 索引
【数据挖掘】2022年2023届秋招Kanaries雾角科技算法岗 笔试题
本文介绍了2022年Kanaries雾角科技算法岗位的笔试题目,涵盖了LeetCode和牛客网的题目,包括字符串处理、几何问题、矩阵操作、数组搜索、二叉树遍历、幂运算及概率计算等多种算法题目,并提供了部分题目的Python代码实现。
168 1
|
消息中间件 大数据 Kafka
高效处理大数据:Kafka的13个核心概念详解
大家好,我是小米!今天我将为大家深入解析Kafka的核心概念,包括消息、批次、主题、分区、副本、生产者、消费者、消费组等内容。通过这篇文章,你将全面了解Kafka的工作机制和应用场景,为你的大数据处理提供有力支持。准备好了吗?让我们开始吧!
337 4