背景
OpenAI官网在2023.06.13公布了API层面的重磅降级,次要变动如下:
- 在Chat Completions这个API里反对了开发者自定义的函数调用。
- 更新了
gpt-4
和gpt-3.5-turbo
模型。 gpt-3.5-turbo
反对的上下文长度扩容到16K,之前只反对4K个token。- embedding model的应用老本升高75%。
gpt-3.5-turbo
模型的input token的老本升高25%,从原来的0.002美金 / 1K token升高为0.0015美金 / 1K token。- 2023.09.13会下线
gpt-3.5-turbo-0301
、gpt-4-0314
和gpt-4-32k-0314
模型,过了这个工夫点调用这些模型会申请失败。
下面提到的这些模型都严格遵循2023.03.01公布的隐衷和平安规定,用户通过API发送的数据和API返回的数据不会用于OpenAI大模型的训练。
函数调用示例
场景:咱们心愿ChatGPT通知当初Boston的天气状况。
如果只靠ChatGPT是无奈实现这个性能的,因为ChatGPT的训练数据只截止到2021年9月,无奈晓得当初的天气。这也是GPT目前最大的一个问题,不能很好地反对信息的及时更新。
那应该怎么应用ChatGPT来实现这个性能呢?
咱们能够本人定义一个函数来获取当天某个城市的天气状况,ChatGPT只须要依据用户的发问生成咱们自定义的函数的参数值(也叫实参),那咱们就能够调用自定义函数拿到咱们想要的后果,而后把自定义函数生成的后果和对话记录作为Prompt送给ChatGPT,由ChatGPT做一个汇总,最初把汇总的论断返回给用户即可。
用户发问 -> ChatGPT生成函数的实参 -> 开发者调用自定义函数 -> 把函数执行后果+上下文对话记录发送给ChatGPT做汇总 -> 返回汇总论断给用户
上面咱们来看一个具体的实现案例:
- 第一步:发问
What’s the weather like in Boston right now?
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"] } } ]}'
拿到ChatGPT返回的后果,返回后果里content为null,function_call有值,示意须要调用自定义函数get_current_weather
,并且返回了自定义函数的参数值。
{ "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" }]}
- 第二步:调用自定义函数。
curl https://weatherapi.com/...
拿到自定义函数返回后果
{ "temperature": 22, "unit": "celsius", "description": "Sunny" }
- 第三步:把自定义函数执行后果和上下文对话记录发送给ChatGPT做汇总。
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"] } } ]}'
最初ChatGPT返回如下后果:
{ "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能够智能地依据用户的输出来判断什么时候应该要调用开发者的自定义函数,并且把自定义函数的参数值给返回。开发者就能够间接本人去调用自定义函数拿到想要的后果,最初再把对话记录和自定义函数执行后果发送给大模型去做汇总。
目前这个性能能够在 gpt-4-0613
和 gpt-3.5-turbo-0613
这2个模型里应用。
等OpenAI在2023.06.27实现模型降级后,gpt-4
、gpt-4-32k
和gpt-3.5-turbo
模型也能够应用这个性能。
新API的应用详情能够参考:developer documentation。
新模型
GPT-4模型
gpt-4-0613
绝对于gpt-4
,新增了函数调用的反对。
gpt-4-32k-0613
绝对于gpt-4-32k
,同样是新增了函数调用的反对。
在接下来的几周里,OpenAI会把GPT-4 API waiting list上的申请都尽量审批通过,让开发者能够享受到GPT-4的弱小能力。还没申请的连忙去申请吧。
GPT-3.5 Turbo模型
gpt-3.5-turbo-0613
绝对于gpt-3.5-turbo
,新增了函数调用的反对。
gpt-3.5-turbo-16k
反对的上下文长度扩容到了16K,是gpt-3.5-turbo
的4倍,费用是gpt-3.5-turbo
的2倍。具体费用是每1K input token须要0.003美金, 每1K output token须要0.004美金。
旧模型下线工夫
从2023.06.13开始,OpenAI会开始降级生产环境的gpt-4
、gpt-4-32k
和gpt-3.5-turbo
模型到最新版本,预计2023.06.27开始就能够应用到降级后的模型了。
如果开发者不想降级,能够持续应用旧版本的模型,不过须要在model参数里指定用gpt-3.5-turbo-0301
,gpt-4-0314
或 gpt-4-32k-0314
。
这些旧版本的模型在2023.09.13会下线,后续持续调用会申请失败。
更低价格
Embedding模型
text-embedding-ada-002
目前是OpenAI所有embedding模型里最受欢迎的。
当初应用这个embedding模型的老本升高为0.0001美金/1K token,老本降落75%。
GPT-3.5 Turbo模型
gpt-3.5-turbo
模型在免费的时候,既对用户发送的问题(input token)免费,也对API返回的后果(output token)免费。
当初该模型的input token老本升高25%,每1K input token的费用为0.0015美金。
output token的费用放弃不变,还是0.002美金/1K token。
gpt-3.5-turbo-16k
模型的input token免费是0.003美金/1K token,output token免费是0.004美金/1K token。
总结
文章和示例代码开源在GitHub: GPT实战教程,能够看到所有支流的开源LLM。
公众号:coding进阶。关注公众号能够获取最新GPT实战内容。
集体网站:Jincheng's Blog。
知乎:无忌。
References
- https://openai.com/blog/function-calling-and-other-api-updates