karthink / gptel

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

Re-use of prompts #83

Closed Ypot closed 11 months ago

Ypot commented 1 year ago

Is it possible to save the prompts we send, directive included, in the kill ring? In that way, we could use them in other places.

Thanks for your exciting package!

karthink commented 1 year ago

It looks like this will take a bit of code to do. I'll see about adding a hook or some other mechanism for this.

PalaceChan commented 1 year ago

maybe naive but am curious how is this useful @Ypot very simple to copy the current header to the kill ring but what's a use case for copying the whole content?

Ypot commented 1 year ago

maybe naive but am curious how is this useful @Ypot very simple to copy the current header to the kill ring but what's a use case for copying the whole content?

For example to see how act on the same prompt other LLMs.

I thought this would be very easy...

PalaceChan commented 1 year ago

ah interesting, isn't the full payload with prompt a dict that's API specific though? do other LLMs generally accept similar enough payload? what would you imagine the kill ring content look like e.g.

karthink commented 12 months ago

Is it possible to save the prompts we send, directive included, in the kill ring? In that way, we could use them in other places.

This is now possible. Here is a function that does it:

(defun gptel-copy-prompts-as-kill ()
  (interactive)
  (when-let*
      ((bounds (gptel--get-bounds))
       (prompts
        (cl-loop for (beg . end) in bounds
                 with prev-beg
                 collect (buffer-substring-no-properties (or prev-beg (point-min)) beg)
                 into prompts
                 do (setq prev-beg end)
                 finally return
                 (nconc (list gptel--system-message)
                        prompts (list (buffer-substring-no-properties end (point-max)))))))
    (kill-new (apply #'concat prompts))))

(You can modify this command to change how the prompts are returned, for instance as a list of strings instead of one string.)