-
Notifications
You must be signed in to change notification settings - Fork 175
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
Customization of gptel-backend
causes recursive require error, prevents gptel from loading
#556
Comments
That can't quite be the problem, because by this logic the recursive load would happen if you used (use-package gptel
:init (setq gptel-backend (gptel-make-ollama "ollama"))
:defer t) But this runs without errors for me. In fact autoloading wouldn't work at all if this was a problem. For example, I'll have to look carefully at what |
The custom machinery does seem a primary factor; and it is complicated. Instead of diving too deeply into that, may I ask... Is there a reason the |
Replacing (require 'gptel) with (defvar gptel-backend (gptel-make-openai "OpenAI")) in It seems that line is necessary because the non-OpenAI backends specify If there are features to include in all backends, might a common base of some sort make sense? |
See #227
This works because
You are mixing up
|
Ah! Thanks for that clarity! If we autoload the ;;;###autoload
(cl-defstruct (gptel-backend ...)) then we can remove Without autoloading this, the other backends do require I might also consider moving the base struct for all backends out of a specific backend implementation for stylistic reasons. But as long as it is autoloaded, the recursive require error is avoided. |
A call to the autoloaded I have an idea for a solution via moving code around that doesn't require so much autoloading, but I'll work on it after merging the tool-use branch. (Essentially I plan to move all the generic backend definition code and the network code to a single file that is not
The only way to do this right now is via chained autoloading, which I don't want to do as noted in #227. Taking a step back, it would be good if |
Agreed completely
I will personally attest 🙂
Excellent! This is similar to what I had in mind, but considerably more comprehensive. |
Since I think this would separate the backend definition step from the backend selection step and avoid this type of confusion. (There's no documentation about it I believe, but defining two backends with the same name probably leads to trouble, so it's effectively a new namespace.) |
First of all, thanks for gptel!
Here's what I'm seeing...
Bug Description
When customizing the value of
gptel-backend
, which is adefcustom
, all backends fail to load with a recursive require error except for those provided in thegptel-openai
feature (ChatGPT, Azure, and GPT4All).This was previously reported as #239, and still exists.
Backend
Ollama, Gemini, Kagi, Anthropic, PrivateGPT
Steps to Reproduce
With
emacs -Q
:Additional Context
Cause
Because the value expected by
gptel-backend
is an object instance, user customization must invoke a constructor function to set this value. The constructor functions are autoloaded. The error occurs becausegptel-ollama
,gptel-gemini
,gptel-kagi
,gptel-anthropic
, andgptel-privategpt
all(require 'gptel)
. This creates a cyclic dependency: loadinggptel
autoloads the backend, which tries to loadgptel
.In contrast,
gptel-openai
does not requiregptel
. This backend does not have this issue.Possible fix
The
gptel-openai
backend usesdefvar
anddeclare-function
at the top of the file for referenced symbols instead of(require 'gptel)
. It seems that the other backend files might do this as well.Workaround
As noted in #239, using
setq
avoids triggering the issue:However,
gptel-backend
is adefcustom
, and not being able to set it using Emacs' customization mechanism is confusing (and likely a bug).Backtrace
Log Information
No response
The text was updated successfully, but these errors were encountered: