GPT+时代来临:OpenAI开放GPT3.5模型,1000token仅1毛钱
创始人
2024-05-28 10:27:16
0

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

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...