refactor: Improve API key handling and function calls in init-ai.el
This commit is contained in:
parent
196f4803eb
commit
615855244a
@ -8,11 +8,15 @@
|
|||||||
(expand-file-name "~/.config/llm/deepseek/api_key.txt"))
|
(expand-file-name "~/.config/llm/deepseek/api_key.txt"))
|
||||||
|
|
||||||
(defun read-llm-api-key (path)
|
(defun read-llm-api-key (path)
|
||||||
"Read and return the DeepSeek API key from the configured file."
|
"Read and return the API key from the specified file path."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert-file-contents (path))
|
(insert-file-contents path)
|
||||||
(string-trim (buffer-string))))
|
(string-trim (buffer-string))))
|
||||||
|
|
||||||
|
(defun read-deepseek-api-key ()
|
||||||
|
"Read and return the DeepSeek API key."
|
||||||
|
(read-llm-api-key (deepseek-api-key-path)))
|
||||||
|
|
||||||
(use-package gptel
|
(use-package gptel
|
||||||
:ensure t
|
:ensure t
|
||||||
:config
|
:config
|
||||||
@ -22,14 +26,14 @@
|
|||||||
:host "api.deepseek.com"
|
:host "api.deepseek.com"
|
||||||
:endpoint "/chat/completions"
|
:endpoint "/chat/completions"
|
||||||
:stream t
|
:stream t
|
||||||
:key (read-deepseek-api-key(deepseek-api-key-path))
|
:key (read-deepseek-api-key)
|
||||||
:models '("deepseek-chat" "deepseek-coder"))))
|
:models '("deepseek-chat" "deepseek-coder"))))
|
||||||
|
|
||||||
;; aider.el
|
;; aider.el
|
||||||
(add-to-list 'load-path "~/.emacs.d/site-lisp/aider/")
|
(add-to-list 'load-path "~/.emacs.d/site-lisp/aider/")
|
||||||
(require 'aider)
|
(require 'aider)
|
||||||
(setq aider-args '("--model" "deepseek/deepseek-coder"))
|
(setq aider-args '("--model" "deepseek/deepseek-coder"))
|
||||||
(setenv "DEEPSEEK_API_KEY" (read-deepseek-api-key()deepseek-api-key-path))
|
(setenv "DEEPSEEK_API_KEY" (read-deepseek-api-key))
|
||||||
|
|
||||||
(provide 'init-ai)
|
(provide 'init-ai)
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
Loading…
Reference in New Issue
Block a user