Replies: 6 comments 2 replies
-
You can use A more general solution is to use (defun gptel-tag-response (beg end)
(save-excursion
(goto-char end)
;; ending tag
(insert "</llm-content>\n\n<llm-prompt>")
(goto-char beg)
(skip-chars-backward " \n\r\t")
;; end of prompt tag
(insert "</llm-prompt>")
(skip-chars-forward " \n\r\t")
;; beginning of response tag
(insert (format "<llm-content model=\"%s\">\n"
gptel-model))))
(add-hook 'gptel-post-response-functions #'gptel-tag-response) Modify as needed. |
Beta Was this translation helpful? Give feedback.
-
Closing this now, please reopen if the above solution doesn't work. |
Beta Was this translation helpful? Give feedback.
-
Hi @karthink, Thank you for showing me how to do this! It works well, however, when I ran it, I had problems with it not putting text annotations in the correct spot. However, I am reopening as well because I realized a few more desirable features:
If you wish I can attempt to implement this in Elisp with Claude's help. Best, |
Beta Was this translation helpful? Give feedback.
-
None of these are features planned for gptel, so I'm moving this to discussions. To watermark text you can use |
Beta Was this translation helpful? Give feedback.
-
Hello @karthik I liked your solution, and used it for the last months to annotate the LLM responses. (defun gptel-add-properties-block (beg end)
(when (and gptel-annotate (not gptel-mode))
(save-excursion
(goto-char beg)
(let ((current-time (current-time)))
(insert (format ":PROPERTIES:\nmodel: %s\ndate: %s\ntime: %s\n:END:\n"
gptel-model
(format-time-string "%Y%m%d" current-time)
(format-time-string "%H:%M" current-time)))))))
(add-hook 'gptel-post-response-functions #'gptel-add-properties-block)
(defvar gptel-annotate t
"When non-nil, gptel-add-properties-block will generate output.")
(setq gptel-annotate t)
(defun gptel-toggle-annotation ()
"Toggle the value of gptel-annotate between nil and t."
(interactive)
(setq gptel-annotate (not gptel-annotate))
(message "gptel-annotate is now %s" (if gptel-annotate "enabled" "disabled"))) that is the code, which nicely puts bocks like this at the beginning of LLM responses:
But there is a race condition If you change the Model to "Model B" before the first response is finished. It adds the wrong annotation with "Model B" to the first LLM response Do you know a solution? Do you have to save the model name at the beginning of the request? But where? A buffer local variable is not a solution. I often run 2 or more requests in parallel in the same buffer. @karthink as are a seasoned emacs lisp coding wizard: Do you have an idea how to accomplish this elegantly, to get the original model name, the request was made with in the 'gptel-post-response-functions hook? The race condition problem has become more eminent, with long running "thinking"-model responses. For me now it is much more common to have multiple requests running in parallel. |
Beta Was this translation helpful? Give feedback.
-
there is an update outlined in: if you want a solution, that works also for google gemini, you need the following code. (defun gptel-add-properties-block (fsm)
(when-let* ((info (gptel-fsm-info fsm))
(position (plist-get info :position))
(model (plist-get info :model))
(buffer (plist-get info :buffer))
(current-time (current-time)))
(when (buffer-live-p buffer)
(with-current-buffer buffer
(when (and (not gptel-mode) (derived-mode-p 'org-mode) gptel-annotate)
(save-excursion
(goto-char position)
(forward-line -1) ;; Move up one line
(insert (format ":PROPERTIES:\nmodel: %s\ndate: %s\ntime: %s\n:END:\n"
model
(format-time-string "%Y%m%d" current-time)
(format-time-string "%H:%M" current-time)))))))))
(defun my/gptel-record-model (fsm)
(let ((info (gptel-fsm-info fsm)))
(plist-put info :model gptel-model)))
(cl-pushnew 'my/gptel-record-model
(alist-get 'WAIT gptel-send--handlers))
(cl-pushnew 'gptel-add-properties-block
(alist-get 'DONE gptel-send--handlers))
(defvar gptel-annotate t
"When non-nil, gptel-add-properties-block will generate output.")
(setq gptel-annotate t)
(defun gptel-toggle-annotation ()
"Toggle the value of gptel-annotate between nil and t."
(interactive)
(setq gptel-annotate (not gptel-annotate))
(message "gptel-annotate is now %s" (if gptel-annotate "enabled" "disabled"))) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I was wondering whether some feature such as the following could be implemented:
E.g.
Would become
(in hypothetical file: apartments.el)
Thanks!
Andrew
Beta Was this translation helpful? Give feedback.
All reactions