GPT+时代来临:OpenAI开放GPT3.5模型,1000token仅1毛钱

GPT3.5 Model API 使用指南

今天OpenAI公司开放了最新的GPT3.5模型:gpt-3.5-turbo,也就是目前网页版的ChatGPT使用的模型。而此前OpenAI开放的最新的模型text-davinci-003则是基于GPT3模型构建的。并且价格十分便宜:1000 token/0.002美元,换算成RMB约1分钱。

请求示例

Curl

curl https://api.openai.com/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello!"}]
}'

Python

import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")

completion = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message)

Node.js

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const completion = await openai.createChatCompletion({
  model: "gpt-3.5-turbo",
  messages: [{role: "user", content: "Hello world"}],
});
console.log(completion.data.choices[0].message);

接口信息

URLhttps://api.openai.com/v1/chat/completions
MethodPOST
Header KeyAuthorization
Header ValueBearer YOUR_API_KEY

你也可以创建自己的应用程序进行请求。

Response

API 响应示例如下所示:

{
 'id': 'chatcmpl-6p9XYPYSTTRi0xEviKjjilqrWU2Ve',
 'object': 'chat.completion',
 'created': 1677649420,
 'model': 'gpt-3.5-turbo',
 'usage': {'prompt_tokens': 56, 'completion_tokens': 31, 'total_tokens': 87},
 'choices': [
   {
    'message': {
      'role': 'assistant',
      'content': 'The 2020 World Series was played in Arlington, Texas at the Globe Life Field, which was the new home stadium for the Texas Rangers.'},
    'finish_reason': 'stop',
    'index': 0
   }
  ]
}

在 Python 中,可以使用 提取助手的回复response[‘choices’][0][‘message’][‘content’]

Token

模型用到了token的概念,什么是token呢?我们输入的文本经过模型编译后被标记为token。

这个token可以是一个字符,也可以是一个单词。例如a或者apple

例如,字符串“ChatGPT is great!”被编码为六个token:[“Chat”, “G”, “PT”, “ is”, “ great”, “!”].

令牌总数必须是低于模型的最大限制,以gpt-3.5-turbo模型为例,token最大为4096

在这里插入图片描述

要查看 API 调用使用了多少令牌,请检查usageAPI 响应中的字段(例如,response[‘usage’][‘total_tokens’])。

另请注意,很长的对话更有可能收到不完整的回复。例如,一段gpt-3.5-turbo长度为 4090 个令牌的对话将在仅 6 个令牌后被截断。

输入和输出令牌都计入这些数量。例如,如果API 调用在消息输入中使用了 10 个令牌,而您在消息输出中收到了 20 个令牌,则需要支付 30 个令牌的费用。

而gpt-3.5-turbo模型,它的价格为每1000 token需要支付0.002美元,换算成RMB是 1000 token/1分钱。比目前的GPT-3.5模型便宜10倍。

另外自 2023 年 3 月 1 日起,只能微调基础 GPT-3 模型。不能对gpt-3.5-turbo模型进行微调。


Reference

[1] https://platform.openai.com/docs/api-reference/chat/create

[2] https://platform.openai.com/docs/models/gpt-3-5

[3] https://platform.openai.com/docs/guides/chat

[4] https://platform.openai.com/docs/guides/fine-tuning

[5] https://openai.com/blog/introducing-chatgpt-and-whisper-apis

  • 5
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Liu_Shihao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值