gptel: Fix prompt string handling in gptel-request

* gptel.el (gptel-request): When `gptel-request` is supplied a
string, it creates the full prompt plist according to the OpenAI
API.  Fix by inserting it into a temp buffer and using the
cl-generic dispatch to parse the buffer instead.  This is a janky
solution but the best possible one without defining another
generic function just to handle prompt strings differently per API.
This commit is contained in:
Karthik Chikmagalur 2023-11-08 12:45:30 -08:00
parent 66d2bafad6
commit 3308449761

View file

@ -637,8 +637,12 @@ Model parameters can be let-bound around calls to this function."
(let ((gptel--system-message system))
(gptel--create-prompt start-marker)))
((stringp prompt)
`((:role "system" :content ,system)
(:role "user" :content ,prompt)))
;; FIXME Dear reader, welcome to Jank City:
(with-temp-buffer
(let ((gptel--system-message system)
(gptel-backend (buffer-local-value 'gptel-backend buffer)))
(insert prompt)
(gptel--create-prompt))))
((consp prompt) prompt)))
(info (list :prompt full-prompt
:buffer buffer