karthink / gptel

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

"Set directives for chat" failes with error #45

Closed phuhl closed 1 year ago

phuhl commented 1 year ago

Hi, great package.

I have this issue that when running M-x gptel-menu h the following error is thrown and no menu is shown:

    transient-setup: Suffix transient:gptel-system-prompt:Programming is not defined or autoloaded as a command

I installed from MELPA: Version: 20230413.602 Commit: a5be53d5e3733ed48023e4862b59ac12fa98be07

I call gptel-menu from a normal markdown-buffer.

Wired thing though is, that when I install gptel freshly via list-packages it works. Only when I restart emacs and load gptel via require or use-package it does not work.

Here is my use-package code:

  (use-package gptel
    :ensure t
    :config
    (setq gptel-api-key #'(lambda nil
                          (plist-get
                           (nth 0
                                (auth-source-search :Title "Chat GPT"))
                           :API\ Key))))

Similar to https://github.com/karthink/gptel/issues/27 ?

xuan-w commented 1 year ago

Yes, I have the same problem.

karthink commented 1 year ago

Thanks, I'm able to reproduce it using package-install. It's very strange indeed. It works after gptel-transient is loaded, but not otherwise even if gptel-system-prompt is autoloaded.

This looks like a quirk of how Transient works. I'll ask Tarsius (author of Transient) what's happening here.

karthink commented 1 year ago

In the meantime, you can get it to work by adding (require 'gptel-transient) in the config section of your use-package block.

phuhl commented 1 year ago

Thanks for the quick response!

In the meantime, you can get it to work by adding (require 'gptel-transient) in the config section of your use-package block.

This does not seem to fix the issue for me. The error remains the same. This is my updated use-package call:

  (use-package gptel
    :ensure t
    :config
+   (require 'gptel-transient)
    (setq gptel-api-key #'(lambda nil
        (plist-get
         (nth 0
        (auth-source-search :Title "Chat GPT"))
         :API\ Key))))
stephenjayakar commented 1 year ago

I am also having the same issue, and adding the require didn't fix things for me:(

karthink commented 1 year ago

I just pushed a fix. Once there's a new release of transient, dynamically generated menus can be supported and the whole custom prompts system should work much better.

karthink commented 1 year ago

Could someone check if the error is still thrown?

will-hanlen commented 1 year ago

Works for me now, thx

colonelpanic8 commented 1 year ago

@karthink looks like there was a new release of transient 6 days ago. Can we refactor this now?

colonelpanic8 commented 1 year ago

Also, I think it would be nice if the transient automatically used everything that is defined in gptel-directives instead of just a fixed setup.

karthink commented 1 year ago

Also, I think it would be nice if the transient automatically used everything that is defined in gptel-directives instead of just a fixed setup.

The code for this is already in the file, it's just commented out: https://github.com/karthink/gptel/blob/master/gptel-transient.el#L174

Now that Transient 4.0 is out, this code can replace the current version of gptel-system-prompt at https://github.com/karthink/gptel/blob/master/gptel-transient.el#L126.

If you're up to testing it a PR would be welcome! It will be a few days before I can get to it myself, unfortunately.

karthink commented 1 year ago

I've pushed a fix in 706ad703. Please test. To make sure the dynamic menus are generated correclty, it will help further to test with a list of directives with overlapping names, such as

(setq gptel-directives
      '((programming . "You are a large language model and a careful programmer. Provide code and only code as output without any additional text, prompt or note.")
        (prose . "You are a large language model and a writing assistant. Respond concisely.")
        (default-chat . "You are a large language model and a conversation partner. Respond concisely.")
        (default . "You are a large language model living in Emacs and a helpful assistant. Respond concisely.")))
karthink commented 1 year ago

I'm assuming this now works as intended with the new transient version. Please re-open if this is not the case.

phuhl commented 1 year ago

Sorry, forgot to answer. Yes, seems to work, thank you!