gptel: tweak prompt, rename url functions

gptel.el (gptel--system-message-alist, gptel--url-get-response,
gptel--url-parse-response): Tweak default programming prompt.  Rename
`gptel--get-response' to the more specific `gptel--url-parse-response'.
Likewise `gptel--parse-response' -> `gptel--url-parse-response'.
This commit is contained in:
Karthik Chikmagalur 2023-03-10 03:55:43 -08:00
parent de70a066d7
commit b212c24c4a

View file

@ -96,7 +96,7 @@ When set to nil, it is inserted all at once.
"You are a large language model living in Emacs and a helpful assistant. Respond concisely.") "You are a large language model living in Emacs and a helpful assistant. Respond concisely.")
(defvar gptel--system-message-alist (defvar gptel--system-message-alist
`((default . ,gptel--system-message) `((default . ,gptel--system-message)
(programming . "You are a large language model and a careful programmer. Respond only with code unless explicitly asked.") (programming . "You are a large language model and a careful programmer. Provide code and only code as output without any additional text, prompt or note.")
(writing . "You are a large language model and a writing assistant. Respond concisely.") (writing . "You are a large language model and a writing assistant. Respond concisely.")
(chat . "You are a large language model and a conversation partner. Respond concisely.")) (chat . "You are a large language model and a conversation partner. Respond concisely."))
"Prompt templates (directives).") "Prompt templates (directives).")
@ -117,13 +117,14 @@ When set to nil, it is inserted all at once.
(message "Querying ChatGPT...") (message "Querying ChatGPT...")
(and header-line-format (and header-line-format
(setf (nth 1 header-line-format) (setf (nth 1 header-line-format)
(propertize " Waiting..." 'face 'warning))) (propertize " Waiting..." 'face 'warning))
(force-mode-line-update))
(let* ((gptel-buffer (current-buffer)) (let* ((gptel-buffer (current-buffer))
(full-prompt (gptel--create-prompt)) (full-prompt (gptel--create-prompt))
(response (aio-await (response (aio-await
(funcall (funcall
(if gptel-use-curl (if gptel-use-curl
#'gptel-curl-get-response #'gptel--get-response) #'gptel-curl-get-response #'gptel--url-get-response)
full-prompt))) full-prompt)))
(content-str (plist-get response :content)) (content-str (plist-get response :content))
(status-str (plist-get response :status))) (status-str (plist-get response :status)))
@ -205,6 +206,7 @@ instead."
prompts-plist)) prompts-plist))
(aio-defun gptel--get-response (prompts) (aio-defun gptel--get-response (prompts)
(aio-defun gptel--url-get-response (prompts)
"Fetch response for PROMPTS from ChatGPT. "Fetch response for PROMPTS from ChatGPT.
Return the message received." Return the message received."
@ -224,10 +226,10 @@ Return the message received."
(aio-await (aio-await
(aio-url-retrieve "https://api.openai.com/v1/chat/completions")))) (aio-url-retrieve "https://api.openai.com/v1/chat/completions"))))
(prog1 (prog1
(gptel--parse-response response-buffer) (gptel--url-parse-response response-buffer)
(kill-buffer response-buffer))))) (kill-buffer response-buffer)))))
(defun gptel--parse-response (response-buffer) (defun gptel--url-parse-response (response-buffer)
"Parse response in RESPONSE-BUFFER." "Parse response in RESPONSE-BUFFER."
(when (buffer-live-p response-buffer) (when (buffer-live-p response-buffer)
(with-current-buffer response-buffer (with-current-buffer response-buffer