2023年6月13日,针对开发者调用的API进行了重大更新,包括更易于操控的API模型、函数调用功能、更长的上下文和内部的价格。
在今年早些时候发布的 gpt-3.5-turbo,gpt-4 在短短几个月内,已经看到开发人员在这些模型之上构建了极其严重的应用程序。
今天,我们将收集一些令人兴奋的更新:
所有这些模型都与我们在3月1日推出的相同的数据隐私和安全保证——客户拥有根据他们的请求生成的所有输出,他们的API数据不会用于训练。
模型更新相关GPT-4GPT-3.5 Turbo模型废弃用
今天,我们将开始对我们三月份宣布的gpt-4和gpt-3.5-turbo的初始版本进行升级和废弃。使用稳定模型名称(gpt-3.5-turbo、gpt-4和gpt-4-32k)的应用将在6月27日自动升级到上述新模型。为了版本之间模型性能的比较,我们的Evals库支持公开和评估,以显示模型变化对您的一些影响。
需要更多时间进行过渡的开发者可以通过 API 请求的“模型”参数中指定gpt-3.5-turbo-0301、gpt-4-0314或gpt-4-32k-0314,继续使用旧模型。这些旧模型将一直使用到9月13日,指定这些模型名称的请求将会失败。您可以通过我们的模型弃用页面来跟踪模型弃用的最新信息。因此,对于这些模型的第一次更新,我们非常欢迎开发者提供反馈,以帮助我们确保平稳过渡。
gpt-4-0613跟gpt-3.5-turbo-0613模型支持函数调用,让模型智能地选择输出包含参数的JSON对象来调用这些函数。这是一种更可靠的GPT功能与外部工具和API连接的新方法。
这些模型已经超过允许,可以检测何时需要调用函数(根据用户的输入)并使用符合函数签名的 JSON 进行响应。函数调用开发人员更可靠地从模型中获取格式化数据。例如,开发人员可以:
创建通过调用外部工具(例如插件)来回答问题的聊天机器人从文本中提取格式化数据
定义一个名为 的函数(: {name: , : , : }),以提取维基百科文章中提到的所有权。
函数调用示例调用的API时,需要增加参数,该参数为json格式字符串。
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"]
}
}
]
}'
复制
返回会一个Json字符串:
{
"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" }
复制
将响应结果发送给进行总结
这个时候我们看到中的吞吐量元素变多了,增加了上下文,并且其中有role=的对象,在中带上上一步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"]
}
}
]
}'
复制
将响应发送回模型进行汇总,返回完整内容: 波士顿目前晴朗天气,预计为 22 小时。
{
"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"
}]
}
复制
调用相关开发文档:
函数如何调用
https://platform.openai.com/docs/guides/gpt/function-calling
复制
了解如何在简单和高级示例中通过API使用函数调用
https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb
复制
总结
自插件的 alpha 版本发布以来,我们学到了很多关于如何让工具和语言模型安全地和谐工作的知识。然而,仍然开放的研究问题。例如,概念验证利用说明了来自工具输出的不受信任的数据如何指示模型执行意外操作。我们正在努力克服这些和其他风险。开发人员可以通过仅使用可信工具的信息并在执行具有现实世界影响的操作(例如发送电子邮件、在线发布或进行购买)包括用户确认步骤来保护他们的应用程序。
函数调用其实跟网页版的插件功能差不多,就是让api调用有更多的扩展性,但是目前感觉调用还是比较麻烦的,查询一个天气功能要请求三次。
更低的价格
我们将继续提高我们的系统效率,把节省下来的资金转嫁给开发人员,即日起生效。
嵌入
text–ada-002 是我们最受欢迎的嵌入模型。今天,我们将成本降低 75% 至每 1K 代币 0.0001 美元。
GPT-3.5 Turbo
开发人员的反馈是我们平台发展的基石,我们将继续根据我们听到的建议进行改进。我们很高兴看到开发人员如何在他们的应用程序中使用这些最新的模型和新功能。
总结
以上就是2023年6月13日发布的更新内容,大家也可以去看原文:
https://openai.com/blog/function-calling-and-other-api-updates?ref=upstract.com