开源项目
https://github.com/shibing624/chatgpt-webui
一个使用gradio搭建的RAG知识检索问答Web UI
Bug发现与修复
使用中发现,调用第三方接口报错
2024-08-20 21:26:40.302 | DEBUG | src.openai_client:_get_response:203 - 使用自定义API URL: https://api.gpts.vin/v1/chat/completions
……
2024-08-20 21:26:48.212 | ERROR | src.openai_client:decode_chat_response:69 - ERROR: {'id': 'chatcmpl-jSDhdwoRc89egZYQIX6PyvKMBbFnr', 'object': 'chat.completion.chunk'
, 'created': 1724160407, 'model': 'gpt-3.5-turbo', 'system_fingerprint': None, 'choices': [{'index': 0, 'delta': {'content': '', 'logprobs': None, 'finish_reason': 'stop'
}}]}, 'finish_reason'
2024-08-20 21:26:48.249 | ERROR | src.openai_client:decode_chat_response:52 - JSON解析错误,收到的内容: data: [DONE]
2024-08-20 21:26:48.356 | INFO | src.base_model:predict:453 - 回答为:
定位问题于src/open_client.py第56行,
if "finish_reason" in chunk["choices"][0]:
finish_reason = chunk["choices"][0]["finish_reason"]
else:
finish_reason = chunk["finish_reason"]
if finish_reason == "stop":
break
try:
yield chunk["choices"][0]["delta"].get("content", "")
except Exception as e:
logger.error(f"Error: {e}")
continue
其中"finish_reason"在更深层结构中,于是应该为以下代码。(添加一个判断条件,以使其适应性更广且不影响原有功能)
if "finish_reason" in chunk["choices"][0]:
finish_reason = chunk["choices"][0]["finish_reason"]
elif "finish_reason" in chunk["choices"][0]['delta']:
finish_reason = chunk["choices"][0]['delta']["finish_reason"]
else:
finish_reason = chunk["finish_reason"]
if finish_reason == "stop":
break
try:
yield chunk["choices"][0]["delta"].get("content", "")
except Exception as e:
logger.error(f"Error: {e}")
continue
操作步骤
1.Fork项目
首先将开源项目Fork项目到自己仓库,在项目主页点”Fork“按钮。
2.克隆项目
使用git命令克隆项目到本地
git clone https://github.com/lzq603/chatgpt-webui
查看是否与远程仓库建立了连接
git remote -v
与上游项目建立连接
git remote add upstream https://github.com/shibing624/chatgpt-webui
同步最新代码
git fetch upstream main
git fetch upstream main
命令的作用是从名为upstream
的远程仓库的main
分支获取最新的提交,并将这些更新下载到本地,但不会将它们自动合并到你当前的工作分支。要将这些更新合并到当前分支,你可以在 fetch 之后执行git merge upstream/main
。
3.修改代码
接下来就可以修改代码了
4.提交代码
先将代码提交到本地版本库
git add . # 提交到暂存区
git commit -m "第三方接口响应的终止条件判断" # 提交到版本库
然后再push代码,推送到远程仓库的main分支
git push origin main
5.提交PR
依次点击Pull requests、New pull request、Create pull request