Skip to content
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

ChatGPT error (nil): Malformed JSON in response. #60

Closed
hongyi-zhao opened this issue May 20, 2023 · 8 comments
Closed

ChatGPT error (nil): Malformed JSON in response. #60

hongyi-zhao opened this issue May 20, 2023 · 8 comments

Comments

@hongyi-zhao
Copy link

hongyi-zhao commented May 20, 2023

On Ubuntu 22.10, I updated my Emacs to its latest git master version, but found that gptel doesn't work for this version, as shown below:

image

Is this a bug of this package or Emacs itself?

Regards,
Zhao

@hongyi-zhao hongyi-zhao changed the title gptel doesn't work with latest git master version. ChatGPT error (nil): Malformed JSON in response. May 20, 2023
@karthink
Copy link
Owner

Can you run (setq gptel--debug t) and then try? This should open up a buffer with the response that we can examine.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented May 20, 2023

After eval (setq gptel--debug t) by C-x C-e in scratch buffer, I see the following with the test above:

[proxychains] DLL init: proxychains-ng 4.16-git-14-g42d2d95
HTTP/2 200 
date: Sat, 20 May 2023 01:19:13 GMT
content-type: text/event-stream
access-control-allow-origin: *
cache-control: no-cache, must-revalidate
openai-model: gpt-3.5-turbo-0301
openai-organization: user-cycirv7tg3umtkc0ijlplsz5
openai-processing-ms: 338
openai-version: 2020-10-01
strict-transport-security: max-age=15724800; includeSubDomains
x-ratelimit-limit-requests: 3
x-ratelimit-limit-tokens: 40000
x-ratelimit-remaining-requests: 2
x-ratelimit-remaining-tokens: 39952
x-ratelimit-reset-requests: 20s
x-ratelimit-reset-tokens: 72ms
x-request-id: e0f1074224be0836107634c744c7191a
cf-cache-status: DYNAMIC
server: cloudflare
cf-ray: 7ca0c0078f88108e-HKG
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"role":"assistant"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"Hello"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"!"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" \n\n"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"It"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" looks"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" like"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" you"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"'re"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" setting"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" the"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" `"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"g"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"pt"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"el"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"--"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"debug"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"`"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" variable"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" to"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" `"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"t"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"`."},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" This"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" might"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" enable"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" debug"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" output"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" for"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" some"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" package"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" or"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" code"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" that"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" you"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"'re"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" working"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":" with"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"."},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-7I5XVnlHGQY1TT3CYDVU0HrWoYpuP","object":"chat.completion.chunk","created":1684545553,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{},"index":0,"finish_reason":"stop"}]}

data: [DONE]

(7065e6b16c203dc9a71131adce8ab501 . 743)

image
image

@karthink
Copy link
Owner

karthink commented May 20, 2023

I see the problem -- it's the first line about proxychains. Could you explain your proxy setup?

I'm not sure why Curl is producing that first line.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented May 20, 2023

I see the problem -- it's the first line about proxychains. Could you explain your proxy setup?

It's a line generated by the proxychains-ng wrapper, as the issue here indicated. This problem occurred after I updated proxychains-ng to its latest git master version. The culprit information is defined here.

I use Emacs with the proxychains-ng, so the issue appears here, but I don't know how to disable this information.

I'm not sure why Curl is producing that first line.

This line is printed to STDERR, which may also be the file descriptor of curl to get the returned data.

@karthink
Copy link
Owner

This line is printed to STDERR, which may also be the file descriptor of curl to get the returned data

Ah, good to know. I think I can separate STDERR from STDOUT in the Curl output to fix this. Let me make sure this doesn't break any other edge case first.

@karthink
Copy link
Owner

It looks like using a separate STDERR buffer will make Emacs create two processes per invocation of Curl, which I'd like to avoid. Ideally this problem can be fixed by proxychains-ng.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented May 20, 2023

The author of proxychain-ng has not replied yet, but the simplest solution is to comment out this line and recompile it, which will solve the problem:

image

@max-arnold
Copy link

Have a similar problem:

HTTP/2 200 
date: Fri, 14 Jul 2023 10:33:08 GMT
content-type: text/event-stream
access-control-allow-origin: *
cache-control: no-cache, must-revalidate
openai-processing-ms: 186
openai-version: 2020-10-01
strict-transport-security: max-age=15724800; includeSubDomains
x-ratelimit-limit-requests: 3500
x-ratelimit-limit-tokens: 90000
x-ratelimit-remaining-requests: 3499
x-ratelimit-remaining-tokens: 89958
x-ratelimit-reset-requests: 17ms
x-ratelimit-reset-tokens: 28ms
x-request-id: 8f37fcfcbf110572648f215a54cd0dfb
cf-cache-status: DYNAMIC
server: cloudflare
cf-ray: 7e691b123ae5d6be-CDG
alt-svc: h3=":443"; ma=86400

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":" How"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":" can"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":" I"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":" assist"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":" you"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":" today"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"?"},"finish_reason":null}]}

data: {"id":"chatcmpl-7cAOi13xRPzImdBuQMExTnEvXUjyx","object":"chat.completion.chunk","created":1689330788,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

(4cd44fc400ed1e411711ea2a71648be2 . 692)

I'm on Aquamacs 3.6 GNU Emacs 25.3.50.1 (x86_64-apple-darwin20.6.0, NS appkit-2022.60 Version 11.6 (Build 20G165))
I had to add text-property-search.el from a newer Emacs and also add the new string-trim* functions that support an optional regex argument.

Have no idea how to fix the JSON error though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants