Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support calc tokens precisely #614

Merged
merged 2 commits into from
Mar 26, 2023
Merged

feat: support calc tokens precisely #614

merged 2 commits into from
Mar 26, 2023

Conversation

lanvent
Copy link
Collaborator

@lanvent lanvent commented Mar 26, 2023

安装tiktoken包后能够精确计算token数量,避免prompt超出上限。
如果未安装tiktoken,则仍使用默认方式,但prompt有超出上限的风险,API会报错。

@goldfishh
Copy link
Contributor

你好,有个问题好奇想问一下你,官方提供的这个函数在计算中文的token数和api返回是完全一致的吗?
另外我觉得这个类的SessionManager可以和openai的Session做一个单独session类的整合
btw,其实感觉openai这个包已经废弃了

@lanvent
Copy link
Collaborator Author

lanvent commented Mar 26, 2023

你好,有个问题好奇想问一下你,官方提供的这个函数在计算中文的token数和api返回是完全一致的吗? 另外我觉得这个类的SessionManager可以和openai的Session做一个单独session类的整合 btw,其实感觉openai这个包已经废弃了

我测试了几个query是一致的,毕竟是openai官方提供的示例代码,这些包也一直随着model的发布有在更新。
openai的Session指的是?

@zhayujie
Copy link
Owner

没毛病

@zhayujie zhayujie merged commit f8e0716 into zhayujie:master Mar 26, 2023
Leslie0310 pushed a commit to Leslie0310/chatgpt-on-wechat that referenced this pull request Dec 8, 2024
feat: support calc tokens precisely
zcpisme pushed a commit to zcpisme/dify-on-wechat that referenced this pull request Dec 28, 2024
feat: support calc tokens precisely
zcpisme pushed a commit to zcpisme/dify-on-wechat that referenced this pull request Dec 28, 2024
feat: support calc tokens precisely
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants