gptel: Set system message correctly in gptel-request

* gptel.el (gptel-request): let-bind `gptel--system-message`
correctly in `gptel-request`.  The Anthropic API requires the
system message to be attached to the query differently from the
others, causing the let-bindings in `gptel-request` to not work as
expected. (#276)
This commit is contained in:
Karthik Chikmagalur 2024-04-03 09:34:07 -07:00
parent 53a905dafc
commit 5d74ec4de0

View file

@ -914,7 +914,8 @@ query data as usual, but do not send the request.
Model parameters can be let-bound around calls to this function." Model parameters can be let-bound around calls to this function."
(declare (indent 1)) (declare (indent 1))
(let* ((gptel-stream stream) (let* ((gptel--system-message system)
(gptel-stream stream)
(start-marker (start-marker
(cond (cond
((null position) ((null position)
@ -926,14 +927,11 @@ Model parameters can be let-bound around calls to this function."
(set-marker (make-marker) position buffer)))) (set-marker (make-marker) position buffer))))
(full-prompt (full-prompt
(cond (cond
((null prompt) ((null prompt) (gptel--create-prompt start-marker))
(let ((gptel--system-message system))
(gptel--create-prompt start-marker)))
((stringp prompt) ((stringp prompt)
;; FIXME Dear reader, welcome to Jank City: ;; FIXME Dear reader, welcome to Jank City:
(with-temp-buffer (with-temp-buffer
(let ((gptel--system-message system) (let ((gptel-model (buffer-local-value 'gptel-model buffer))
(gptel-model (buffer-local-value 'gptel-model buffer))
(gptel-backend (buffer-local-value 'gptel-backend buffer))) (gptel-backend (buffer-local-value 'gptel-backend buffer)))
(insert prompt) (insert prompt)
(gptel--create-prompt)))) (gptel--create-prompt))))