• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

OpenAI API 重磅升级支持函数调用,价格更亲民

武飞扬头像
lencx
帮助1

OpenAI 近期对其语言模型和 API 进行了一系列重要的更新和优化。所有这些模型都具有 OpenAI 在 3 月 1 日推出的相同的数据隐私和安全保证——客户拥有根据他们的请求生成的所有输出,他们的 API 数据不会用于训练。

API 与功能改进

  • 函数调用能力:为 Chat Completions API 引入了全新的函数调用功能。开发者现在可以描述函数给 gpt-4-0613gpt-3.5-turbo-0613,并使模型智能地选择输出一个包含调用这些函数的参数的 JSON 对象。这是一个更可靠地将 GPT 的功能与外部工具和 API 连接起来的新方法。
  • API 更新:发布了更新且更易驾驭的 gpt-4gpt-3.5-turbo 版本,为开发者提供了更高的可控性。
  • 扩展上下文版本:发布了新的 gpt-3.5-turbo 16k 上下文版本(相较于标准的 4k 版本)。16k 上下文意味着模型现在可以在单次请求中支持约 20 页的文本。

函数调用示例

What’s the weather like in Boston right now?
现在波士顿的天气如何?

Step 1: OpenAI API

Call the model with functions and the user’s input
用函数和用户的输入调用模型

Request

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

Response

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

Step 2: Third party API

Use the model response to call your API
使用模型的响应来调用你的API

Request

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

Response

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

Step 3: OpenAI API

Send the response back to the model to summarize
将响应返回给模型进行总结

Request

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

Response

{
  "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.
波士顿的天气目前是晴朗的,温度为 22 摄氏度。

新模型发布

  • GPT-4:发布了包括函数调用在内的更新和改进的 gpt-4-0613 模型,以及具有扩展上下文长度的 gpt-4-32k-0613 模型,以便更好地理解更大的文本。
  • GPT-3.5 Turbogpt-3.5-turbo-0613 模型包括与 GPT-4 相同的函数调用功能,以及通过系统消息更可靠地控制能力,这两个特性使开发者能够更有效地指导模型的响应。

模型退役

​OpenAI 将开始为在 3 月份发布的 gpt-4gpt-3.5-turbo 的初代版本进行升级和退役。在 6 月 27 日,使用稳定模型名称的应用程序(gpt-3.5-turbogpt-4gpt-4-32k)将自动升级为新版本。需要更多时间过渡的开发者可以通过在 API 请求中指定模型参数来继续使用旧模型,这些旧模型将一直可用到 9 月 13 日。

价格调整

  • 嵌入模型价格降低:将最受欢迎的嵌入模型 text-embedding-ada-002 的价格降低了 75%,至每 1K tokens $0.0001。
  • GPT-3.5 Turbo 价格调整gpt-3.5-turbo 的输入 tokens 的成本降低了 25%,现在,开发者可以仅以每 1K 输入tokens 0.0015和每1K输出tokens0.0015 和每 1K 输出 tokens 0.002 的价格使用该模型,约等于每美元 700 页。gpt-3.5-turbo-16k 将定价为每 1K 输入 tokens 0.003和每1K输出tokens0.003 和每 1K 输出 tokens 0.004。

总结

更强大的函数调用能力,更新且更易驾驭的模型版本,以及上下文长度的扩展,这些都进一步优化了开发者的用户体验。此外,还调整了模型的定价策略,降低了嵌入模型和 GPT-3.5 Turbo 的价格,进一步提高了其产品的性价比。

参考

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhcaijbk
系列文章
更多 icon
同类精品
更多 icon
继续加载