Closed hongyi-zhao closed 1 year ago
Based on the discussions in "GPT Academic Developers #chat2 群号 610599535", patching as follows does the trick:
$ git log -1
commit 27f65c251a83c9b19ea5707938ae51683f1f2d8a (HEAD -> master, origin/master, origin/HEAD)
Author: binary-husky <96192199+binary-husky@users.noreply.github.com>
Date: Mon Jul 31 15:57:18 2023 +0800
Update 图片生成.py
$ git diff
diff --git a/request_llm/bridge_chatgpt.py b/request_llm/bridge_chatgpt.py
index ea48fba..96af833 100644
--- a/request_llm/bridge_chatgpt.py
+++ b/request_llm/bridge_chatgpt.py
@@ -186,15 +186,16 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
try:
chunk_decoded = chunk.decode()
# 前者是API2D的结束条件,后者是OPENAI的结束条件
- if ('data: [DONE]' in chunk_decoded) or (len(json.loads(chunk_decoded[6:])['choices'][0]["delta"]) == 0):
+ if 'data: [DONE]' in chunk_decoded:
# 判定为数据流的结束,gpt_replying_buffer也写完了
logging.info(f'[response] {gpt_replying_buffer}')
break
# 处理数据流的主体
chunkjson = json.loads(chunk_decoded[6:])
status_text = f"finish_reason: {chunkjson['choices'][0]['finish_reason']}"
- # 如果这里抛出异常,一般是文本过长,详情见get_full_error的输出
- gpt_replying_buffer = gpt_replying_buffer + json.loads(chunk_decoded[6:])['choices'][0]["delta"]["content"]
+ delta = chunkjson['choices'][0]["delta"]
+ if "content" in delta:
+ gpt_replying_buffer = gpt_replying_buffer + delta["content"]
history[-1] = gpt_replying_buffer
chatbot[-1] = (history[-2], history[-1])
yield from update_ui(chatbot=chatbot, history=history, msg=status_text) # 刷新界面
Build, config, start, and test ChatGPT-to-API as follows:
$ git clone https://github.com/acheong08/ChatGPT-to-API.git && cd ChatGPT-to-API && go build
# Create the following configuration files and adjust their content according to your environment:
$ cat accounts.txt
username:password
$ cat proxies.txt
socks5://127.0.0.1:18890
$ SERVER_PORT=18080 ./freechatgpt
Then, tell gpt_academic the corresponding endpoint as follows:
API_URL_REDIRECT='{"https://api.openai.com/v1/chat/completions": "http://127.0.0.1:18080/v1/chat/completions"}'
See below for the related discussions:
https://github.com/acheong08/ChatGPT-to-API/issues/104 https://github.com/linweiyuan/go-chatgpt-api/issues/236
Class | 类型
大语言模型
Feature Request | 功能请求
有如下两个特性,非常不错: