karthink / gptel

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

gptel does not work with Emacs 30 pretest (30.0.92) #450

Open pbgc opened 3 weeks ago

pbgc commented 3 weeks ago

Please update gptel first -- errors are often fixed by the time they're reported.

Bug Description

M-x gptel gives: Wrong type argument: bufferp, nil

M-X gptel-send gives: Querying Claude... Claude error: (HTTP/2 400) The request body is not valid JSON: unexpected character: line 1 column 1 (char 0)

Backend

Anthropic

Steps to Reproduce

run M-x gptel read: "Wrong type argument: bufferp, nil" in minibuffer

Select text run M-X gptel-send read on minibuffer: Querying Claude... Claude error: (HTTP/2 400) The request body is not valid JSON: unexpected character: line 1 column 1 (char 0)

Additional Context

gptel: 20241029.205 (installed from melpa) Emacs Version: 30.0.92 OS: macOS 13.7.1 curl: curl 8.7.1

Backtrace

No response

Log Information

No response

karthink commented 3 weeks ago

Can you generate a backtrace?

pbgc commented 3 weeks ago

@karthink M-x gptel give:

`Debugger entered--Lisp error: (wrong-type-argument bufferp nil) buffer-local-value(gptel-mode nil)

f(compiled-function (b) #<bytecode 0x8be6261920f913b>)((" temp"))

f(compiled-function (name) #<bytecode -0x18cc9977fe730f87>)(" temp")

f(compiled-function (elt) #<bytecode 0x14d5c7c7ebb1f1d3>)(" temp")

seq-map(#f(compiled-function (elt) #<bytecode 0x14d5c7c7ebb1f1d3>) (" Minibuf-1" "scratch" " Minibuf-0" "Messages" " Echo Area 0" " Echo Area 1" " code-conversion-work" " temp" "Completions" "GNU Emacs")) seq-filter(#f(compiled-function (name) #<bytecode -0x18cc9977fe730f87>) (" Minibuf-1" "scratch" " Minibuf-0" "Messages" " Echo Area 0" " Echo Area 1" " code-conversion-work" " temp" "Completions" "GNU Emacs")) ido-make-buffer-list("Claude")

f(compiled-function (item prompt hist &optional default require-match initial) "Perform the ido-read-buffer' andido-read-file-name' functions.\nReturn the name of a buffer or file selected.\nPROMPT is the prompt to give to the user.\nDEFAULT if given is the default item to start with.\nIf REQUIRE-MATCH is non-nil, an existing file must be selected.\nIf INITIAL is non-nil, it specifies the initial input string." #<bytecode 0xbaa6c0b33e2aecf>)(buffer "Create or choose gptel buffer: " ido-buffer-history "Claude" nil nil)

ad-Advice-ido-read-internal(#f(compiled-function (item prompt hist &optional default require-match initial) "Perform the ido-read-buffer' andido-read-file-name' functions.\nReturn the name of a buffer or file selected.\nPROMPT is the prompt to give to the user.\nDEFAULT if given is the default item to start with.\nIf REQUIRE-MATCH is non-nil, an existing file must be selected.\nIf INITIAL is non-nil, it specifies the initial input string." #<bytecode 0xbaa6c0b33e2aecf>) buffer "Create or choose gptel buffer: " ido-buffer-history "Claude" nil) apply(ad-Advice-ido-read-internal #f(compiled-function (item prompt hist &optional default require-match initial) "Perform the ido-read-buffer' andido-read-file-name' functions.\nReturn the name of a buffer or file selected.\nPROMPT is the prompt to give to the user.\nDEFAULT if given is the default item to start with.\nIf REQUIRE-MATCH is non-nil, an existing file must be selected.\nIf INITIAL is non-nil, it specifies the initial input string." #<bytecode 0xbaa6c0b33e2aecf>) (buffer "Create or choose gptel buffer: " ido-buffer-history "Claude" nil)) ido-read-internal(buffer "Create or choose gptel buffer: " ido-buffer-history "Claude" nil) ido-read-buffer("Create or choose gptel buffer: " "Claude" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>)) apply(ido-read-buffer ("Create or choose gptel buffer: " "Claude" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>)))

f(advice ido-read-buffer :override persp-read-buffer)("Create or choose gptel buffer: " "Claude" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>))

read-buffer("Create or choose gptel buffer: " "Claude" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>)) byte-code("\302\303!\304\305\306\3!\10>\204\24\0\307\310\303\5D\"\210\2\311H\"\312\313\2\314\315$\3161;\0\317\306\4!\10>\2043\0\307\310\303\6\6D\"\210\3\320H!0\202D\0\210\321\304\322\4\"!\211\21\323 \205N\0\324 \325 {\326F\207" [cl-struct-gptel-backend-tags gptel-api-key default-value gptel-backend format "%s" type-of signal wrong-type-argument 1 read-buffer "Create or choose gptel buffer: " nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>) (error user-error) gptel--get-api-key 7 read-passwd "%s API key: " use-region-p region-beginning region-end t] 8) call-interactively(gptel record nil) command-execute(gptel record)

f(compiled-function (prefixarg &optional command-name typed) "Read a command name, then read the arguments and call the command.\nTo pass a prefix argument to the command you are\ninvoking, give a prefix argument to execute-extended-command'.\n\nThis command provides completion when reading the command name.\nWhich completion candidates are shown can be controlled by\ncustomizingread-extended-command-predicate'." (interactive #f(compiled-function () #<bytecode -0x1f3e06e9f415fca5>)) #<bytecode 0xa5781218b81f91d>)(nil "gptel" "gptel")

ad-Advice-execute-extended-command(#f(compiled-function (prefixarg &optional command-name typed) "Read a command name, then read the arguments and call the command.\nTo pass a prefix argument to the command you are\ninvoking, give a prefix argument to execute-extended-command'.\n\nThis command provides completion when reading the command name.\nWhich completion candidates are shown can be controlled by\ncustomizingread-extended-command-predicate'." (interactive #f(compiled-function () #<bytecode -0x1f3e06e9f415fca5>)) #<bytecode 0xa5781218b81f91d>) nil "gptel" "gptel") apply(ad-Advice-execute-extended-command #f(compiled-function (prefixarg &optional command-name typed) "Read a command name, then read the arguments and call the command.\nTo pass a prefix argument to the command you are\ninvoking, give a prefix argument to execute-extended-command'.\n\nThis command provides completion when reading the command name.\nWhich completion candidates are shown can be controlled by\ncustomizingread-extended-command-predicate'." (interactive #f(compiled-function () #<bytecode -0x1f3e06e9f415fca5>)) #<bytecode 0xa5781218b81f91d>) (nil "gptel" "gptel")) execute-extended-command(nil "gptel" "gptel") funcall-interactively(execute-extended-command nil "gptel" "gptel") call-interactively(execute-extended-command nil nil) command-execute(execute-extended-command) `

karthink commented 3 weeks ago

This backtrace is unreadable, could you paste it as it appears in the backtrace buffer, inside elisp formatted blocks on github like this:

```elisp
<backtrace copied from backtrace buffer>
pbgc commented 3 weeks ago

Ok. Sorry

Debugger entered--Lisp error: (wrong-type-argument bufferp nil)
  buffer-local-value(gptel-mode nil)
  #f(compiled-function (b) #<bytecode 0x8be6261920f913b>)((" *temp*"))
  #f(compiled-function (name) #<bytecode -0x18cc9977fe730f87>)(" *temp*")
  #f(compiled-function (elt) #<bytecode 0x14d5c72df59cb1d3>)(" *temp*")
  seq-map(#f(compiled-function (elt) #<bytecode 0x14d5c72df59cb1d3>) (" *Minibuf-1*" "*scratch*" " *Minibuf-0*" "*Messages*" " *Echo Area 0*" " *Echo Area 1*" " *code-conversion-work*" " *temp*" "*Backtrace*" "*Completions*" "*GNU Emacs*"))
  seq-filter(#f(compiled-function (name) #<bytecode -0x18cc9977fe730f87>) (" *Minibuf-1*" "*scratch*" " *Minibuf-0*" "*Messages*" " *Echo Area 0*" " *Echo Area 1*" " *code-conversion-work*" " *temp*" "*Backtrace*" "*Completions*" "*GNU Emacs*"))
  ido-make-buffer-list("*Claude*")
  #f(compiled-function (item prompt hist &optional default require-match initial) "Perform the `ido-read-buffer' and `ido-read-file-name' functions.\nReturn the name of a buffer or file selected.\nPROMPT is the prompt to give to the user.\nDEFAULT if given is the default item to start with.\nIf REQUIRE-MATCH is non-nil, an existing file must be selected.\nIf INITIAL is non-nil, it specifies the initial input string." #<bytecode 0xbaa6c0b33e2aecf>)(buffer "Create or choose gptel buffer: " ido-buffer-history "*Claude*" nil nil)
  ad-Advice-ido-read-internal(#f(compiled-function (item prompt hist &optional default require-match initial) "Perform the `ido-read-buffer' and `ido-read-file-name' functions.\nReturn the name of a buffer or file selected.\nPROMPT is the prompt to give to the user.\nDEFAULT if given is the default item to start with.\nIf REQUIRE-MATCH is non-nil, an existing file must be selected.\nIf INITIAL is non-nil, it specifies the initial input string." #<bytecode 0xbaa6c0b33e2aecf>) buffer "Create or choose gptel buffer: " ido-buffer-history "*Claude*" nil)
  apply(ad-Advice-ido-read-internal #f(compiled-function (item prompt hist &optional default require-match initial) "Perform the `ido-read-buffer' and `ido-read-file-name' functions.\nReturn the name of a buffer or file selected.\nPROMPT is the prompt to give to the user.\nDEFAULT if given is the default item to start with.\nIf REQUIRE-MATCH is non-nil, an existing file must be selected.\nIf INITIAL is non-nil, it specifies the initial input string." #<bytecode 0xbaa6c0b33e2aecf>) (buffer "Create or choose gptel buffer: " ido-buffer-history "*Claude*" nil))
  ido-read-internal(buffer "Create or choose gptel buffer: " ido-buffer-history "*Claude*" nil)
  ido-read-buffer("Create or choose gptel buffer: " "*Claude*" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>))
  apply(ido-read-buffer ("Create or choose gptel buffer: " "*Claude*" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>)))
  #f(advice ido-read-buffer :override persp-read-buffer)("Create or choose gptel buffer: " "*Claude*" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>))
  read-buffer("Create or choose gptel buffer: " "*Claude*" nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>))
  byte-code("\302\303!\304\305\306\3!\10>\204\24\0\307\310\303\5D\"\210\2\311H\"\312\313\2\314\315$\3161;\0\317\306\4!\10>\2043\0\307\310\303\6\6D\"\210\3\320H!0\202D\0\210\321\304\322\4\"!\211\21\323 \205N\0\324 \325 {\326F\207" [cl-struct-gptel-backend-tags gptel-api-key default-value gptel-backend format "*%s*" type-of signal wrong-type-argument 1 read-buffer "Create or choose gptel buffer: " nil #f(compiled-function (b) #<bytecode 0x8be6261920f913b>) (error user-error) gptel--get-api-key 7 read-passwd "%s API key: " use-region-p region-beginning region-end t] 8)
  call-interactively(gptel record nil)
  command-execute(gptel record)
  #f(compiled-function (prefixarg &optional command-name typed) "Read a command name, then read the arguments and call the command.\nTo pass a prefix argument to the command you are\ninvoking, give a prefix argument to `execute-extended-command'.\n\nThis command provides completion when reading the command name.\nWhich completion candidates are shown can be controlled by\ncustomizing `read-extended-command-predicate'." (interactive #f(compiled-function () #<bytecode -0x1f3e06e9f415fca5>)) #<bytecode 0xa5781218b81f91d>)(nil "gptel" "gptel")
  ad-Advice-execute-extended-command(#f(compiled-function (prefixarg &optional command-name typed) "Read a command name, then read the arguments and call the command.\nTo pass a prefix argument to the command you are\ninvoking, give a prefix argument to `execute-extended-command'.\n\nThis command provides completion when reading the command name.\nWhich completion candidates are shown can be controlled by\ncustomizing `read-extended-command-predicate'." (interactive #f(compiled-function () #<bytecode -0x1f3e06e9f415fca5>)) #<bytecode 0xa5781218b81f91d>) nil "gptel" "gptel")
  apply(ad-Advice-execute-extended-command #f(compiled-function (prefixarg &optional command-name typed) "Read a command name, then read the arguments and call the command.\nTo pass a prefix argument to the command you are\ninvoking, give a prefix argument to `execute-extended-command'.\n\nThis command provides completion when reading the command name.\nWhich completion candidates are shown can be controlled by\ncustomizing `read-extended-command-predicate'." (interactive #f(compiled-function () #<bytecode -0x1f3e06e9f415fca5>)) #<bytecode 0xa5781218b81f91d>) (nil "gptel" "gptel"))
  execute-extended-command(nil "gptel" "gptel")
  funcall-interactively(execute-extended-command nil "gptel" "gptel")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
karthink commented 3 weeks ago

Thanks, that's much easier to read. Appears to be some issue with ido-mode or persp-mode. Can you try without ido-mode enabled?

You also mentioned an error with using gptel-send. That could be independent of this error, could you generate a backtrace for that too?

pbgc commented 3 weeks ago

Appears to be some issue with ido-mode or persp-mode. Can you try without ido-mode enabled?

Bingo. Disabling ido-mode it works! (but ido-mode is really used a lot ... strange that no one had this problem before)

regarding the other problem ... does not give a backtrace ... only the error: "Claude error: (HTTP/2 400) The request body is not valid JSON: unexpected character: line 1 column 1 (char 0)" on the minibuffer

EDIT: even using the dedicated window obtained with M-x gptel ... I get the above error trying to query anything.

EDIT2:

My configuration is:

(setq gptel-model 'claude-3-5-sonnet-20241022 gptel-backend (gptel-make-anthropic "Claude" :stream t :key " ...... ........... "))

EDIT3: some images ...

Captura de ecrã 2024-11-01, às 18 39 27 Captura de ecrã 2024-11-01, às 18 39 47
karthink commented 3 weeks ago

only the error: "Claude error: (HTTP/2 400) The request body is not valid JSON: unexpected character: line 1 column 1 (char 0)" on the minibuffer

Please generate a log and paste it here. Run (setq gptel-log-level 'info), then reproduce this error and check the *gptel-log* buffer.

pbgc commented 3 weeks ago

Here is it is:

{ "gptel": "request body", "timestamp": "2024-11-01 19:17:36" } { "model": "claude-3-5-sonnet-20241022", "system": "You are a large language model living in Emacs and a helpful assistant. Respond concisely.", "stream": true, "max_tokens": 1024, "messages": [ { "role": "user", "content": "in emacs lisp how can I remove an entry from completion-at-point-functions" } ], "temperature": 1.0 } { "gptel": "response body", "timestamp": "2024-11-01 19:17:36" } { "type": "error", "error": { "type": "invalid_request_error", "message": "The request body is not valid JSON: unexpected character: line 1 column 1 (char 0)" } }

karthink commented 3 weeks ago

Hmm, that log looks fine, I'm not sure what's causing the issue.

Could you run (setq gptel-use-curl nil) and try? (This makes gptel use Emacs' built-in url-retrieve instead of Curl. We can check if it's an issue with gptel's use of Curl 8.7.1)

pbgc commented 3 weeks ago

did and got a very similar log message:

{ "gptel": "request body", "timestamp": "2024-11-01 19:50:04" } { "model": "claude-3-5-sonnet-20241022", "system": "You are a large language model living in Emacs and a helpful assistant. Respond concisely.", "stream": false, "max_tokens": 1024, "messages": [ { "role": "user", "content": "in emacs lisp how can I remove an entry from completion-at-point-functions" } ], "temperature": 1.0 } { "gptel": "response body", "timestamp": "2024-11-01 19:50:04" }

{ "type": "error", "error": { "type": "invalid_request_error", "message": "The request body is not valid JSON: Input is a zero-length, empty document: line 1 column 1 (char 0)" } }

karthink commented 3 weeks ago

Did you already have gptel installed when you upgraded from Emacs 29 to 30? Or is it a fresh install?

pbgc commented 3 weeks ago

Fresh install. I already had upgraded to 30 way before installing gptel and had all packages byte compiled to 30. Strange that before I bought Claude api credits gptel-send was not giving me any error... Only Claude (and chatgpt that I also tried) answering my that my account didn't have credits.

pbgc commented 2 weeks ago

@karthink any clue about this ? anything I can try ? No matter what I try I always get "The request body is not valid JSON: Input is a zero-length, empty document: line 1 column 1 (char 0)" from Claude. Also .. do you plan to solve the issue with ido-mode ? that's a pretty common mode...

karthink commented 2 weeks ago

I don't know what's causing the issue, sorry. I don't have access to Emacs 30 (yet), or MacOS or Curl 8.7.1 to test this. Perhaps someone else experiencing a similar problem can provide some insight.

I'm also not able to reproduce the issue with ido-mode -- it works as expected on Emacs 29.4, 29.2 and Emacs 28.2 on Linux (which is what I could test.)

I have one question about the encoding: what is the value of the variable default-process-coding-system in your Emacs?

pbgc commented 2 weeks ago

I have one question about the encoding: what is the value of the variable default-process-coding-system in your Emacs?

(utf-8-unix . utf-8-unix)

karthink commented 2 weeks ago

I have one question about the encoding: what is the value of the variable default-process-coding-system in your Emacs?

(utf-8-unix . utf-8-unix)

That looks fine. Without the ability to reproduce these errors, I'm afraid I'm out of debugging ideas for now.

karthink commented 2 weeks ago

I think I fixed the ido error, you can try it now. Still no idea about the encoding error.

pbgc commented 2 weeks ago

@karthink sorry. only now could try it. Now with ido the error is gone .. but I get: Create or choose gptel buffer: [No match] I cannot select Claude (like I can if I remove ido) and the completions says "0 possible completions"

pbgc commented 1 week ago

Hi! With last version on melpa ... trying gptel with a simple question LOG:

{ "gptel": "request body", "timestamp": "2024-11-11 19:20:32" } { "model": "claude-3-5-sonnet-20241022", "system": "You are a large language model living in Emacs and a helpful assistant. Respond concisely.", "stream": true, "max_tokens": 1024, "messages": [ { "role": "user", "content": "write me a django view that returns hellow world" } ], "temperature": 1.0 }

I get this error (changed my api key with xxxxxxxxx)

gptel-curl--get-args: Args out of range: #s(gptel-anthropic "Claude" "api.anthropic.com" #[0 "� �� ��B�B�" [gptel--get-api-key "x-api-key" (("anthropic-version" . "2023-06-01") ("anthropic-beta" . "pdfs-2024-09-25") ("anthropic-beta" . "prompt-caching-2024-07-31"))] 3] "https" t "/v1/messages" "sk-ant-apixxxxxxxxxxxxxxxxxxxxxxx " (claude-3-5-sonnet-20241022 claude-3-5-sonnet-20240620 claude-3-opus-20240229 claude-3-5-haiku-20241022 claude-3-haiku-20240307 claude-3-sonnet-20240229) "https://api.anthropic.com/v1/messages" ...), 11

karthink commented 1 week ago

Hi! With last version on melpa ... trying gptel with a simple question LOG:

Run your gptel configuration again.

karthink commented 1 week ago

Now with ido the error is gone .. but I get: Create or choose gptel buffer: [No match] I cannot select Claude (like I can if I remove ido) and the completions says "0 possible completions"

You can type in any name you want for the gptel buffer, OR just press <return> to select a default name. If this doesn't work something is wrong with ido and I'll have to bug report it to Emacs.

pbgc commented 1 week ago

Run your gptel configuration again.

I'm sorry ... but how do I do that ?

pbgc commented 1 week ago

You can type in any name you want for the gptel buffer, OR just press to select a default name. If this doesn't work something is wrong with ido and I'll have to bug report it to Emacs.

pressing enter gives me: "Empty string for buffer name is not allowed"

It advances and "works" if I write "Claude" - but then I get the last error above

karthink commented 1 week ago

Run your gptel configuration again.

I'm sorry ... but how do I do that ?

The simplest way is to restart Emacs.

OR

Select your gptel configuration in your init.el and run M-x eval-region

pbgc commented 1 week ago

ok .. did that ... unfortunately I return to having the "The request body is not valid JSON: Input is a zero-length, empty document: line 1 column 1 (char 0)"

karthink commented 1 week ago

pressing enter gives me: "Empty string for buffer name is not allowed"

I can't reproduce this with ido-mode and ido-everywhere-mode. What is your ido-mode configuration?

pbgc commented 1 week ago

What is your ido-mode configuration?

; ### IDO ###

;; FLX
(require 'flx-ido)
(ido-mode 1)
(ido-everywhere 1)
(flx-ido-mode 1)
;; disable ido faces to see flx highlights.
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil)
(setq ido-ignore-directories '("node_modules/" "platforms/" "plugins/"))

But I tried disabling flex-ido and leaving only bare bones ido and get the same result