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:
parent
dd5833eef3
commit
a673f54a3e
2 changed files with 4 additions and 2 deletions
|
@ -50,7 +50,8 @@ PROMPTS is the data to send, TOKEN is a unique identifier."
|
||||||
(api-key
|
(api-key
|
||||||
(cond
|
(cond
|
||||||
((stringp gptel-api-key) gptel-api-key)
|
((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
|
(headers
|
||||||
`(("Content-Type" . "application/json")
|
`(("Content-Type" . "application/json")
|
||||||
("Authorization" . ,(concat "Bearer " api-key)))))
|
("Authorization" . ,(concat "Bearer " api-key)))))
|
||||||
|
|
3
gptel.el
3
gptel.el
|
@ -278,7 +278,8 @@ Return the message received."
|
||||||
(api-key
|
(api-key
|
||||||
(cond
|
(cond
|
||||||
((stringp gptel-api-key) gptel-api-key)
|
((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-method "POST")
|
||||||
(url-request-extra-headers
|
(url-request-extra-headers
|
||||||
`(("Content-Type" . "application/json")
|
`(("Content-Type" . "application/json")
|
||||||
|
|
Loading…
Add table
Reference in a new issue