Comments (2)
我也类似:Unterminated string in JSON at position 112
from chatgpt-nuxt.
I also faced the same issue. I investigated and fixed it: #16
Investigation Result
I confirmed that this issue occurs when data received through the stream is incorrectly divided. This causes errors at JSON.parse
, as the data is cut off in the middle of the JSON format.
The following example shows a case where the stream is split into two parts and it works correctly:
Successful Case
The first stream:
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"role":"assistant"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"H"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"e"},"index":0,"finish_reason":null}]}
The second stream:
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"l"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"l"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"o"},"index":0,"finish_reason":null}]}
data: [DONE]
Error Case
The following example shows a case where JSON parsing fails and an error as the current issue occurs:
The first stream:
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"role":"assistant"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"H"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"e"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","obj
The second stream:
ect":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"l"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"l"},"index":0,"finish_reason":null}]}
data: {"id":"chatcmpl-6wbHdXzs8Cgh4arATBF53vGOV1YmB","object":"chat.completion.chunk","created":1679424361,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"o"},"index":0,"finish_reason":null}]}
data: [DONE]
Solution
I have fixed this issue by combining the received stream data and parsing only the remaining data in each loop.
from chatgpt-nuxt.
Related Issues (20)
- 有没有联系方式 HOT 1
- 如何我想把apikey写死且不在页面展示应该怎么做啊 HOT 1
- ERR MODULE NOT FOUND HOT 3
- 新的模型
- 希望支持 gpt4.0
- 希望接入手机端的适配
- 【BUG】乱码问题 HOT 4
- 【BUG】显示异常问题 HOT 3
- docker-compose打出来的镜像无法启动 HOT 5
- docker-compose报错 HOT 2
- npm i或者npm run dev 提示报错 HOT 3
- yarn error incorrect data check
- 我是用nginx代理的,每次提问,是要等一段时间后,才出来,是本来就这样 吗?还是我设置问题
- 第一步npm i出错显示Segmentation fault HOT 2
- Internal server error: Missing "./dist/runtime/composables" specifier in "@nuxtjs/i18n" package HOT 12
- Cannot read properties of undefined (reading 'data') HOT 5
- 请问大佬,本地启动项目接口报错500,这个应该怎么处理呢 HOT 1
- Appeared during the reply HOT 3
- How do I configure a proxy? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chatgpt-nuxt.