From 33084497619f159997f605f4bcdb39c75f887ec7 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Wed, 8 Nov 2023 12:45:30 -0800 Subject: [PATCH] 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. --- gptel.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/gptel.el b/gptel.el index 3d01906..95c9fde 100644 --- a/gptel.el +++ b/gptel.el @@ -632,14 +632,18 @@ Model parameters can be let-bound around calls to this function." ((integerp position) (set-marker (make-marker) position buffer)))) (full-prompt - (cond - ((null prompt) - (let ((gptel--system-message system)) - (gptel--create-prompt start-marker))) - ((stringp prompt) - `((:role "system" :content ,system) - (:role "user" :content ,prompt))) - ((consp prompt) prompt))) + (cond + ((null prompt) + (let ((gptel--system-message system)) + (gptel--create-prompt start-marker))) + ((stringp 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 :position start-marker)))