OpenAI API 0613更新:GPT-3.5-turbo-16k模型、函数调用解析和使用方案汇总

目录

函数调用

函数调用的官方示例(我测试过以后会再写一个自己的示例)

第一步:通过 OpenAI API 调用带有函数和用户输入的模型

第二步:根据模型返回的响应来调用第三方 API

第三步:将第三方 API 的返回结果发送给模型并进行总结

新模型

GPT-4

GPT-3.5-turbo

模型废弃

价格降低

Embeddings

GPT-3.5-turbo

参考


OpenAI 刚刚发布了 API 更新,看到后第一时间与大家做分享。

原文地址(本文基于原文进行简单的翻译汉化,补充少量内容):

Function calling and other API updates​openai.com/blog/function-calling-and-other-api-updates

主要更新内容:

  • 在 Chat Completions API 中提供函数调用能力
  • 更新更易控制的 gpt-4 和 gpt-3.5-turbo 版本
  • 新的 16k 上下文版本 gpt-3.5-turbo (与标准的4k版本相比)
  • embeddings 嵌入模型价格降低了75%
  • gpt-3.5-turbo输入 token 价格降低 25%
  • 宣布 gpt-3.5-turbo-0301 和 gpt-4-0314 型号的弃用计划

以上所有的模型都会遵循 0301 介绍的数据隐私规则——所有使用 API 的数据不会用于训练。

函数调用

开发者现在可以向gpt-4-0613gpt-3.5-turbo-0613描述函数,并让模型智能地选择输出一个JSON对象,其中包含调用这些函数的参数。这是一种更可靠地将GPT的能力与外部工具和API连接起来的新方法。

这些模型已经进行了微调,既可以检测到何时需要调用函数(根据用户的输入),又可以响应符合函数签名的JSON。函数调用使开发人员能够更可靠地从模型中获取结构化数据。例如,开发人员可以:

  • 创建聊天机器人,通过调用外部工具(例如ChatGPT插件)来回答问题。

将“Email Anya to see if she wants to get coffee next Friday”这样的查询转换为函数调用,例如send_email(to: string, body: string),或者将“What’s the weather like in Boston?”转换为get_current_weather(location: string, unit: 'celsius' | 'fahrenheit')

  • 将自然语言转换为API调用或数据库查询

将“Who are my top ten customers this month?”转换为内部API调用,例如get_customers_by_revenue(start_date: string, end_date: string, limit: int),或将“How many orders did Acme, Inc. place last month?”转换为使用sql_query(query: string)的SQL查询。

  • 从文本中提取结构化数据

定义一个名为extract_people_data(people: [{name: string, birthday: string, location: string}])的函数,以提取维基百科文章中提到的所有人物。

这些用例是通过/v1/chat/completions中的新参数functionsfunction_call实现的,允许开发人员通过JSON模式描述函数,并可选择要求其调用特定函数。请查看开发文档[1];如果发现函数调用可以优化的案例,可以提交到evals[2]中。

函数调用的官方示例(我测试过以后会再写一个自己的示例)

询问天气:What’s the weather like in Boston right now?

第一步:通过 OpenAI API 调用带有函数和用户输入的模型

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

第二步:根据模型返回的响应来调用第三方 API

例如,通过某个接口查询天气:

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

返回示例:

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

第三步:将第三方 API 的返回结果发送给模型并进行总结

请求示例:

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

从中可以提取出回复内容:

The weather in Boston is currently sunny with a temperature of 22 degrees Celsius.

自从ChatGPT插件的alpha版本发布以来,我们已经学到了很多关于如何安全地让工具和语言模型协同工作的知识。然而,仍然存在一些未解决的研究问题。例如,一个概念验证漏洞说明了来自工具输出的不受信任的数据如何指示模型执行意外的操作。OpenAI 正在努力减轻这些和其他风险。开发人员可以通过仅使用来自可信工具的信息并在执行具有现实影响的操作(例如发送电子邮件、在线发布或购买)之前包含用户确认步骤来保护其应用程序。

新模型

GPT-4

gpt-4-0613 包括一个带有函数调用的更新和改进模型。gpt-4-32k-0613 包含了与 gpt-4-0613 相同的改进,并能处理更长的文本。

通过这些更新,OpenAI 将在未来几周内邀请更多的等待名单[3]中的人尝试 GPT-4,并打算使用这个模型完全移除等待名单。感谢所有耐心等待的人,我们很期待看到你们使用 GPT-4 创造的东西!

GPT-3.5-turbo

gpt-3.5-turbo-0613提供与GPT-4相同的函数调用,以及通过系统消息更可靠的可操纵性,这两个特性使开发人员能够更有效地引导模型的响应。

gpt-3.5-turbo-16k的上下文长度是gpt-3.5-turbo的4倍,价格是gpt-3.5-turbo的两倍:每1K输入0.003美元,每1K输出0.004美元。16k的上下文长度意味着该模型现在可以在单个请求中支持约20页的文本。

模型废弃

今天,我们将开始升级和弃用gpt-4gpt-3.5-turbo的初始版本,这是我们在三月份宣布的。使用稳定模型名称(gpt-3.5-turbogpt-4gpt-4-32k)的应用程序将在6月27日自动升级到上述新模型。为了比较不同版本之间的模型性能,Evals库[4]支持公共和私有评估,以展示模型变化将如何影响用户的使用情况。

需要更多时间过渡的开发人员可以通过在API请求的“model”参数中指定gpt-3.5-turbo-0301gpt-4-0314gpt-4-32k-0314,继续使用旧模型。在9月13日之前,这些旧模型将仍然可用,之后指定这些模型名称的请求将失败。您可以通过我们的模型弃用页面[5]及时了解模型弃用情况。这是这些模型的第一个更新,因此我们热切期待开发人员的反馈[6],以帮助我们确保平稳过渡。

价格降低

我们将继续提高系统效率,并从今天开始将这些节省的成本传递给开发者。

Embeddings

text-embedding-ada-002是我们最受欢迎的嵌入模型。今天我们将成本降低75%,每1K个标记只需0.0001美元。

GPT-3.5-turbo

gpt-3.5-turbo是我们最受欢迎的聊天模型,为数百万用户提供ChatGPT服务。今天,我们将gpt-3.5-turbo’s输入 token 的成本降低25%。开发者现在可以以每1K输入 token 0.0015美元和每1K输出 token 0.002美元的价格使用该模型,这相当于每美元大约可以获得700页的服务。

gpt-3.5-turbo-16k的价格为每1K输入 token 0.003美元,每1K输出 token 0.004美元。

开发者反馈是我们平台发展的基石,我们将继续根据我们听到的建议进行改进。我们很高兴看到开发者如何在他们的应用程序中使用这些最新的模型和新功能。

参考

  1. ^https://platform.openai.com/docs/guides/gpt/function-calling
  2. ^GitHub - openai/evals: Evals is a framework for evaluating LLMs and LLM systems, and an open-source registry of benchmarks.
  3. ^GPT-4 API waitlist
  4. ^GitHub - openai/evals: Evals is a framework for evaluating LLMs and LLM systems, and an open-source registry of benchmarks.
  5. ^https://platform.openai.com/docs/deprecations/
  6. ^OpenAI Developer Forum

猜你喜欢

转载自blog.csdn.net/qqerrr/article/details/131254255