[emacs] Get anthropic keys from elsewhere
This commit is contained in:
parent
804926e05b
commit
8ede0fd021
1 changed files with 14 additions and 11 deletions
|
|
@ -1405,17 +1405,20 @@ Do this when you edit your project view."
|
||||||
;; AI Shit
|
;; AI Shit
|
||||||
;; =================================================================
|
;; =================================================================
|
||||||
(defun claude-get-api-key ()
|
(defun claude-get-api-key ()
|
||||||
"Get Claude API key from auth-source."
|
"Get Claude API key from ~/.config/io.datasette.llm/keys.json file."
|
||||||
(let ((auth-info (nth 0 (auth-source-search :host "anthropic.com"
|
(let* ((keys-file (expand-file-name "~/.config/io.datasette.llm/keys.json"))
|
||||||
:user "claude-api"
|
(json-object-type 'hash-table)
|
||||||
:require '(:secret)
|
(json-array-type 'list)
|
||||||
:create t))))
|
(json-key-type 'string))
|
||||||
(if auth-info
|
(if (file-exists-p keys-file)
|
||||||
(let ((secret (plist-get auth-info :secret)))
|
(let* ((json-data (with-temp-buffer
|
||||||
(if (functionp secret)
|
(insert-file-contents keys-file)
|
||||||
(funcall secret)
|
(json-read-from-string (buffer-string))))
|
||||||
secret))
|
(claude-key (gethash "claude" json-data)))
|
||||||
(error "Claude API key not found in auth-source"))))
|
(if claude-key
|
||||||
|
claude-key
|
||||||
|
(error "Claude API key not found in keys.json")))
|
||||||
|
(error "Key file keys.json file not found at %s" keys-file))))
|
||||||
|
|
||||||
(use-package gptel :ensure
|
(use-package gptel :ensure
|
||||||
:config
|
:config
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue