binary-husky / gpt_academic

为GPT/GLM等LLM大语言模型提供实用化交互接口,特别优化论文阅读/润色/写作体验,模块化设计,支持自定义快捷按钮&函数插件,支持Python和C++等项目剖析&自译解功能,PDF/LaTex论文翻译&总结功能,支持并行问询多种LLM模型,支持chatglm3等本地模型。接入通义千问, deepseekcoder, 讯飞星火, 文心一言, llama2, rwkv, claude2, moss等。
https://github.com/binary-husky/gpt_academic/wiki/online
GNU General Public License v3.0
65.36k stars 8.04k forks source link

[Bug]: KeyError: 'Could not automatically map gpt-4 to a tokeniser. Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect.' #718

Closed hongyi-zhao closed 1 year ago

hongyi-zhao commented 1 year ago

Installation Method | 安装方法与平台

Pip Install (I used latest requirements.txt and python>=3.8)

Describe the bug & Screen Shot | 简述 与 有帮助的截图

$ python main.py 
 [PROXY] 网络代理状态:已配置。配置信息如下: {'http': 'socks5h://localhost:18890', 'https': 'socks5h://localhost:18890'} 
 [API_KEY] 本项目现已支持OpenAI和API2D的api-key。也支持同时填写多个api-key,如API_KEY="openai-key1,openai-key2,api2d-key3" 
 [API_KEY] 您既可以在config.py中修改api-key(s),也可以在问题输入区输入临时的api-key(s),然后回车键提交后即可生效。 
 [API_KEY] 您的 API_KEY 是: sk-uqK3QZVkFjSH*** API_KEY 导入成功 
所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!
查询代理的地理位置,返回的结果是{'ip': '60.249.28.129', 'network': '60.249.28.0/23', 'version': 'IPv4', 'city': 'New Taipei', 'region': 'New Taipei', 'region_code': 'NWT', 'country': 'TW', 'country_name': 'Taiwan', 'country_code': 'TW', 'country_code_iso3': 'TWN', 'country_capital': 'Taipei', 'country_tld': '.tw', 'continent_code': 'AS', 'in_eu': False, 'postal': None, 'latitude': 24.9466, 'longitude': 121.586, 'timezone': 'Asia/Taipei', 'utc_offset': '+0800', 'country_calling_code': '+886', 'currency': 'TWD', 'currency_name': 'Dollar', 'languages': 'zh-TW,zh,nan,hak', 'country_area': 35980.0, 'country_population': 23451837, 'asn': 'AS3462', 'org': 'Data Communication Business Group'}
代理配置 socks5h://localhost:18890, 代理所在地:Taiwan
如果浏览器没有自动打开,请复制并转到以下URL:
    (亮色主题): http://localhost:54021
    (暗色主题): http://localhost:54021/?__theme=dark
正在执行一些模块的预热...
正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数
加载tokenizer完毕
正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数
Exception in thread warm-up:
Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/home/werner/Public/repo/github.com/binary-husky/gpt_academic.git/check_proxy.py", line 152, in warm_up_modules
    enc.encode("模块预热", disallowed_special=())
  File "/home/werner/Public/repo/github.com/binary-husky/gpt_academic.git/request_llm/bridge_all.py", line 43, in encode
    encoder = self.get_encoder(self.model) 
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/Public/repo/github.com/binary-husky/gpt_academic.git/request_llm/bridge_all.py", line 38, in get_encoder
    tmp = tiktoken.encoding_for_model(model)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/datasci/lib/python3.11/site-packages/tiktoken/model.py", line 68, in encoding_for_model
    raise KeyError(
KeyError: 'Could not automatically map gpt-4 to a tokeniser. Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect.'
Running on local URL:  http://0.0.0.0:54021

To create a public link, set `share=True` in `launch()`.
[GFX1-]: glxtest: VA-API test failed: no supported VAAPI profile found.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
[ERROR viaduct::backend::ffi] Missing HTTP status
[ERROR viaduct::backend::ffi] Missing HTTP status

Terminal Traceback & Material to Help Reproduce Bugs | 终端traceback(如有) + 帮助我们复现的测试材料样本(如有)

No response

binary-husky commented 1 year ago

是否使用了 requirements.txt 安装依赖? tiktoken的版本是多少?

hongyi-zhao commented 1 year ago

多谢提醒,执行下面的命令后成功了:

$ pip install -U tiktoken

image

实际上,我的 API_KEY 是购买了 GPT-4 的:

image

但是,从 gpt_academic 中无法使用这个功能:

image

这是什么原因?

hongyi-zhao commented 1 year ago

就是没有获得 GPT-4 API 访问的体验资格。参考下面的讨论:

https://github.com/karthink/gptel/issues/59 https://github.com/emacs-openai/chatgpt/issues/11