-
Notifications
You must be signed in to change notification settings - Fork 839
fix: parse sse #532
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
fix: parse sse #532
Conversation
如果你想对比修改前后的效果:
- API 服务在这里:https://key-rental-bowencool.vercel.app/ (测试环境),免费送的额度够测试十几次了。
- 推荐的 prompt :"冬季水果推荐",90%复现率
感谢反馈!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分代码实际上是为了使fetchsse也能用于fetch普通的http响应
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是为了检测返回的不是json, 也就是检测是sse, 但这个检测方式确实不好, 已经修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分是不需要的, 原来的样子就行, 在fetchSSE具体使用中的回调函数内已经处理了
做了一些调整 90f4880
�出现的问题已经解决, 原因是先前的方式, 对每组chunk解码时, 可能出现一个中文字符分在了两个chunk中, 但先前对每个chunk转为字符串, 然后feed, 导致了parser永远在处理已经被转为乱码的字符串
我对eventsource-parser源码做了轻微修改, 使得feed参数改为了Uint8Array而非string, 以对chunk中单个中文被截断到两个chunk的情况进行处理
关于没有使用其他现成sse fetch库的原因, 上面的code review已做了解释, 主要是为了同时兼容常规fetch请求, 即此处的fakeSseData: 90f4880#diff-97ee404f37a9691da94b62082f3e27eaf3e3e10b05b36b551c4f1db52174175eR31
因为有一些用户希望方便地接入自定义API, 并且有些用户在开发自定义API时, 觉得做成sse有些麻烦
* origin/master: Update OpenAI ChatGPT Turbo models (API) (ChatGPTBox-dev#620) release v2.4.9 when opening IndependentPanel, if the latest session has been used, automatically create a new session (ChatGPTBox-dev#601) presearch support (ChatGPTBox-dev#592) formattedError (ChatGPTBox-dev#572) safe markdown renderer (ChatGPTBox-dev#609, ChatGPTBox-dev#403) improve the stability of response language (ChatGPTBox-dev#611) improve bilibili summary fix mounting failure caused by DuckDuckGo's initial rendering delay. ChatGPTBox-dev#610 gpt-4 web DALL·E support chore improve ChatGPTBox-dev#603 improve markdown styles (ChatGPTBox-dev#585) fix gpt-4 web unusual activity (ChatGPTBox-dev#615) fix: bilibili reload (ChatGPTBox-dev#603) refactor(selection-tools): remove redundant `getPreferredLanguage` calls (ChatGPTBox-dev#593) Fix GPT-4 model name and confusion in names (ChatGPTBox-dev#584) chore(deps): bump actions/upload-artifact from 3 to 4 (ChatGPTBox-dev#594) chore(deps): bump actions/setup-python from 4 to 5 (ChatGPTBox-dev#586) update readme news release v2.4.8 update core content adapters fix eventsource meta (ChatGPTBox-dev#579, ChatGPTBox-dev#567) ChatGPTBox-dev#573's patch release v2.4.7 fix ChatGPTBox-dev#569 and reduce menu items add gpt-3.5-turbo-instruct fix global side_panel patch to ChatGPTBox-dev#564 Update Claude.ai web to Claude v2.1, fix ChatGPTBox-dev#570 (ChatGPTBox-dev#573) Add ChatGLM API (ChatGPTBox-dev#567) Optimize Logic in `selection-tools` Module (ChatGPTBox-dev#564) release v2.4.6 support for chromium side panel (ChatGPTBox-dev#111) allow filling in the API Key of CustomModel mode (ChatGPTBox-dev#561, previously designed for local offline model or custom server, now you can also use it for regular openai API calls and freely fill in the model name(ChatGPTBox-dev#563)) update for chatgpt3.5 web (ChatGPTBox-dev#562, ChatGPTBox-dev#551#issuecomment-1803668105, ChatGPTBox-dev#543#issuecomment-1803666487) Added box for gh pr's and issues (ChatGPTBox-dev#558) Replace legacy gpt-3.5-turbo-0613 with the latest gpt-3.5-turbo-1106 Add OpenAI API GPT-4 Turbo Preview Turkish readme Translation (ChatGPTBox-dev#553) chore firefox patch release v2.4.5 update build scripts force scroll to bottom after submission docs: phrase translation according language README_IN improve render performance (ChatGPTBox-dev#265) docs: add Japanese README Create .gitattributes improve chatgpt web user guide release v2.4.4 improve chatgpt web mode compatibility improve chatgpt web user guide Add site adapters for Golem, EETimes release v2.4.3 fix safari background (ChatGPTBox-dev#512 (comment)) improve fetchSSE (ChatGPTBox-dev#532) re-order parse process fix: parse sse Make summarization work for text/plain content chore(deps-dev): bump @babel/traverse from 7.21.4 to 7.23.2 fix ChatGPTBox-dev#539 bing web blob file read for gitlab (ChatGPTBox-dev#544) fix chatgpt web mode arkose_token (ChatGPTBox-dev#469, ChatGPTBox-dev#543, ChatGPTBox-dev#545) remove BingImageCreator disable poe temporarily upgrade caniuse-lite remove commands permission
Uh oh!
There was an error while loading. Please reload this page.
请看图中的 Case,每个 chunk 并不是严格以
data:
分隔的:CleanShot 2023年10月17日 at 11 33 12@2x
按照
eventsource-parser
的文档,你应该把 try catch 移动到onParse
里面。我是 API 的开发者,虽然这个 API 比较特别,但确实是解析的代码不够规范,我试了其他三四种客户端,均没有出现次问题。
我在本地测试时解决了这个问题。而且貌似还顺带解决了偶尔出现"�"的问题。