karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.19k stars 121 forks source link

malformed JSON in response #342

Open Yousuf28 opened 1 month ago

Yousuf28 commented 1 month ago

I saw there were similar issue before. So I have updated to latest version of gptel. Still got the same Malformed Json in response error. Any idea how to solve this? I used the package few weeks ago and It was working fine. It is not working from last week.

Screenshot 2024-07-15 171644
karthink commented 1 month ago
  1. Run (setq gptel-log-level 'debug)
  2. Try to use gptel
  3. When you get an error, check the *gptel-log* buffer.
  4. Scrub your API key from this buffer and paste the contents here.
Yousuf28 commented 1 month ago

I copied from gptel-log buffer

{ "gptel": "request headers", "timestamp": "2024-07-15 20:58:41" } { "Content-Type": "application/json", "Authorization": "Bearer api_key" } { "gptel": "request body", "timestamp": "2024-07-15 20:58:41" } { "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a large language model living in Emacs and a helpful assistant. Respond concisely." }, { "role": "user", "content": "how to read csv file in R?" } ], "stream": true, "temperature": 1.0 } { "gptel": "request Curl command", "timestamp": "2024-07-15 20:58:41" } [ "curl", "--disable", "--location", "--silent", "-XPOST", "-y300", "-Y1", "-D-", "-w(53e34981eb6258c077fbcbab9f43b4ca . %{size_header})", "-d{\"model\":\"gpt-3.5-turbo\",\"messages\":[{\"role\":\"system\",\"content\":\"You are a large language model living in Emacs and a helpful assistant. Respond concisely.\"},{\"role\":\"user\",\"content\":\"how to read csv file in R?\"}],\"stream\":true,\"temperature\":1.0}", "-HContent-Type: application/json", "-HAuthorization: Bearer api_key", "https://api.openai.com/v1/chat/completions" ]

karthink commented 1 month ago

It looks like no response is being received at all. Can you run that curl command in the log from the log output in a terminal and check if it works?

takushi1969 commented 1 month ago

Hello, Yousuf28-san and Karthink-san.

First of all, I'm Japanese, So I'm not good at English.

I have the same issue recently. Before that, I'd enabled to use gptel with no problems.

And I found a workaroud for this isssue.
(setq gptel-use-curl nil)

Thanks the auther, Karthink-san for implementing this route.

For debug iformation, I attached the log of curl command execution which command line is retrieved from *gptel-log*. The command line is ommited '-w' option.

log.md

Yousuf28 commented 1 month ago

@takushi1969 Thank you so much. It worked.

karthink commented 1 month ago

It looks like no response is being received at all. Can you run that curl command in the log from the log output in a terminal and check if it works?

@Yousuf28 It will help debug the issue if you can run the curl command from the command line.

@takushi1969 It looks like a curl-specific problem then. What is the version of curl installed on your system, and what OS are you using? (curl --version)

takushi1969 commented 1 month ago

@karthink san,

You are right!

Environment

I use gptel on emacs on Windws11.

Test Reult

via gptel

# software version result
1 curl (shipped with windows) 8.8.8 NG
2 curl (installed by chocolatey) 8.9.1 OK

on cmd prompt

# software version result
1 curl (shipped with windows) 8.8.8 OK
2 curl (installed by chocolatey) 8.9.1 OK

I attached both logs when I executed curl on cmd prompt. curl_8_9_1.log win_curl.log

FYI

When I used gptel on cygwin's Emacs on the same Windows11, it worked, too.

Yousuf28 commented 1 month ago

I am using curl from windows git bash.

$ which curl
/mingw64/bin/curl

Emacs 29.3 got following response.

HTTP/1.1 200 OK Date: Wed, 07 Aug 2024 12:18:45 GMT Content-Type: text/event-stream; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive openai-organization: user-mxiaoqrwbnia96ffeiy9x9ei openai-processing-ms: 405 openai-version: 2020-10-01 strict-transport-security: max-age=15552000; includeSubDomains; preload x-ratelimit-limit-requests: 10000 x-ratelimit-limit-tokens: 200000 x-ratelimit-remaining-requests: 9999 x-ratelimit-remaining-tokens: 199958 x-ratelimit-reset-requests: 8.64s x-ratelimit-reset-tokens: 12ms x-request-id: req_b728b69855c852543d4d06f543771082 CF-Cache-Status: DYNAMIC Set-Cookie: __cf_bm=T7qatL.tvDw_g6Y1d68vU3q_rYI09EDKU08o5yfvFmQ-1723033125-1.0.1.1-CZytHO5xI9p4pLRQEb63efKmD14k95w6QIy.mPxoKZpUXOWA4K6eusHGdkLAJTZnJ5vbViFA_FYe90qwIXLD.g; path=/; expires=Wed, 07-Aug-24 12:48:45 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None X-Content-Type-Options: nosniff Set-Cookie: _cfuvid=.s7sh1vjQlOd8iz3ooHgiAz0kG22j6mE5OWTI6E_nHk-1723033125649-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None Server: cloudflare CF-RAY: 8af7360698ab505c-ORF alt-svc: h3=":443"; ma=86400

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"role":"assistant","content":"","refusal":null},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"!"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" How"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" can"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" I"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" help"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" you"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" today"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-9tZunXEIMVQ4T7ycXnoGNi1MqFw0N","object":"chat.completion.chunk","created":1723033125,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}

data: [DONE]

takushi1969 commented 1 month ago

@Yousuf28 san,

Which one of curl Emacs uses depends on the PATH environment Emacs recognizes. So, you should better wirte down the result of (getenv "PATH") on your Emacs with your study.

Best regards.

I am using curl from windows git bash.

$ which curl
/mingw64/bin/curl

Emacs 29.3 got following response.