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
61.54k stars 7.66k forks source link

[Bug]: 第三方api访问chatgpt3.5报错:TypeError: 'NoneType' object is not subscriptable #1221

Closed bkzy333 closed 8 months ago

bkzy333 commented 8 months ago

Installation Method | 安装方法与平台

Docker-Compose(Linux)

Version | 版本

Others | 最新版

OS | 操作系统

Linux

Describe the bug | 简述

通过docker-compose部署,国内的千帆和星火模型均可以访问,但是通过第三方api访问的chatgpt出现报错。

version: '3'
services:
  gpt_academic_nolocalllms:
    image: ghcr.io/binary-husky/gpt_academic_nolocal:master
    environment:
      API_KEY: 'sk-RQ345345'
      USE_PROXY: 'false'
      proxies: '{"http": "socks5h://localhost:10880", "https": "socks5h://localhost:10880"}'
      LLM_MODEL: 'gpt-3.5-turbo'
      AVAIL_LLM_MODELS: '["gpt-3.5-turbo-16k","gpt-3.5-turbo","sparkv2", "qianfan","gpt-4", "gpt-4-32k","chatglm", "moss","stack-claude","llama2", "qwen"]'
      API_URL_REDIRECT: '{"https": "//api.openai.com/v1/chat/completions", "https": "//api.chatanywhere.com.cn"}'
      WEB_PORT: '22303'
      AUTHENTICATION: '[("123", "333"), ("username2", "passwd2")]'
      XFYUN_APPID: "662e"
      XFYUN_API_SECRET: "YmR768OTZ87975"
      XFYUN_API_KEY: "a038hgfj5461"
      BAIDU_CLOUD_API_KEY: 'zWMhgjk3'
      BAIDU_CLOUD_SECRET_KEY: 'aqe14zghj'
      BAIDU_CLOUD_QIANFAN_MODEL: 'ERNIE-Bot'
      # 是否在提交时自动清空输入框
      AUTO_CLEAR_TXT: True
    network_mode: "host"
    command: bash -c "python3 -u main.py"

通过第三方api访问chatgpt3.5,结果报错:

Traceback (most recent call last):
  File "./request_llm/bridge_chatgpt.py", line 220, in predict
    if ('data: [DONE]' in chunk_decoded) or (len(chunkjson['choices'][0]["delta"]) == 0):
                                                 ~~~~~~~~~^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

405 Not Allowed
nginx

Screen Shot | 有帮助的截图

运行过程日志:

[ENV_VAR] 嘗試加載API_URL_REDIRECT,默認值:{} --> 修正值:{"https://api.openai.com/v1/chat/completions":"https://api.chatanywhere.com.cn"}
 [ENV_VAR] 成功讀取環境變量API_URL_REDIRECT 
[ENV_VAR] 嘗試加載API_KEY,默認值:此处填API密钥 --> 修正值:sk-R*****8l
 [ENV_VAR] 成功讀取環境變量API_KEY 
chatgpt访问错误日志:
新版本可用。新版本:3.56,当前版本:3.55。
正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数
加载tokenizer完毕
 gpt-3.5-turbo : 0 : 你好,请问你是什么模型? ..........
<head><title>405 Not Allowed</title></head><body><center><h1>405 Not Allowed</h1></center><hr><center>nginx</center></body></html>
 gpt-3.5-turbo-16k : 1 : 你好,请问你是什么模型? ..........
 gpt-3.5-turbo : 3 : 你好,请问你是什么模型? ..........
<head><title>405 Not Allowed</title></head><body><center><h1>405 Not Allowed</h1></center><hr><center>nginx</center></body></html>

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

我尝试去hub.docker找了bentwng/gpt_academic_nolocal:latest重新构建,也是依然出现这个问题

yueyangming commented 8 months ago

+1,遇到了同样的问题。

同样的第三方 api

binary-husky commented 8 months ago

API_URL_REDIRECT 写错了

LiSonglin-xidian commented 7 months ago

API_URL_REDIRECT = {"https://api.openai.com/v1/chat/completions": "https://api.chatanywhere.tech/v1/chat/completions"} 设置的这样可以了

yueyangming commented 7 months ago

API_URL_REDIRECT = {"https://api.openai.com/v1/chat/completions": "https://api.chatanywhere.tech/v1/chat/completions"} 设置的这样可以了

感谢感谢,我昨天也是刚这样做的,可以用了。以为这个issue close了没法回复,就没写上来。