gptel, gptel-curl: Handle missing API key

gptel.el (gptel--url-get-response): When `gptel-send' is called
directly, the API key is assumed to exist. Ensure that it is read.

gptel-curl.el (gptel-curl--get-args): Ditto.
This commit is contained in:
Karthik Chikmagalur 2023-03-10 23:00:41 -08:00
parent dd5833eef3
commit a673f54a3e
2 changed files with 4 additions and 2 deletions

View file

@ -50,7 +50,8 @@ PROMPTS is the data to send, TOKEN is a unique identifier."
(api-key
(cond
((stringp gptel-api-key) gptel-api-key)
((functionp gptel-api-key) (funcall gptel-api-key))))
((functionp gptel-api-key) (funcall gptel-api-key))
(t (setq gptel-api-key (read-passwd "OpenAI API key: ")))))
(headers
`(("Content-Type" . "application/json")
("Authorization" . ,(concat "Bearer " api-key)))))

View file

@ -278,7 +278,8 @@ Return the message received."
(api-key
(cond
((stringp gptel-api-key) gptel-api-key)
((functionp gptel-api-key) (funcall gptel-api-key))))
((functionp gptel-api-key) (funcall gptel-api-key))
(t (setq gptel-api-key (read-passwd "OpenAI API key: ")))))
(url-request-method "POST")
(url-request-extra-headers
`(("Content-Type" . "application/json")