GPT输入和输出的长度都是有限制的,OPENAI的GPT4是8K,azure的是32K

这个长度限制要注意是指 输入的 prompt + 模型返回的。

调用接口的时候为了更准确的拆分长文本,需要计算token数量,但是不同版本的GPT用的编码方式不一样,所以计算token数量的方式也是不一样的。官方有python的库可以用,但其它语言的就需要找到合适的。

不同版本用的编码方式不一样:
cl100k_base:gpt-4, gpt-3.5-turbo, text-embedding-ada-002
p50k_base:Codex models, text-davinci-002, text-davinci-003
r50k_base (or gpt2):GPT-3 models like davinci

官方GPT-3的在线计算工具
https://platform.openai.com/tokenizer
Tiktokenizer 在线工具
https://tiktokenizer.vercel.app/

gpt-tokenizer 截图,点击这里访问
gpt-tokenizer

支持cl100k_base and p50k_base 编码的库(也就是GPT-4和GPT-3.5)
Javascript:
https://github.com/niieani/gpt-tokenizer
https://www.npmjs.com/package/gpt-tokenizer

Python
https://github.com/openai/tiktoken

Java
https://github.com/knuddelsgmbh/jtokkit

.NET/C#
https://github.com/dmitry-brazhenko/SharpToken
https://github.com/aiqinxuancai/TiktokenSharp

标签: none

添加新评论