|
31 | 31 |
|
32 | 32 | ;;; Code:
|
33 | 33 |
|
| 34 | +(require 'auth-source) |
34 | 35 | (require 'cl-lib)
|
35 | 36 | (require 'let-alist)
|
36 | 37 | (require 'pcase)
|
|
57 | 58 | (when openai--show-log
|
58 | 59 | (apply 'message fmt args)))
|
59 | 60 |
|
60 |
| -(defun openai-key--auth-source () |
61 |
| - "Retrieve the OpenAI API key from auth-source." |
62 |
| - (let ((auth-info (auth-source-search :max 1 |
63 |
| - :host "api.openai.com" |
64 |
| - :require '(:user :secret)))) |
65 |
| - (if auth-info |
66 |
| - (funcall (plist-get (car auth-info) :secret)) |
67 |
| - (error "OpenAI API key not found in auth-source")))) |
68 |
| - |
69 | 61 | ;;
|
70 | 62 | ;;; Request
|
71 | 63 |
|
| 64 | +;;;###autoload |
| 65 | +(defun openai-key-auth-source () |
| 66 | + "Retrieve the OpenAI API key from auth-source." |
| 67 | + (if-let ((auth-info (auth-source-search :max 1 |
| 68 | + :host "api.openai.com" |
| 69 | + :require '(:user :secret)))) |
| 70 | + (funcall (plist-get (car auth-info) :secret)) |
| 71 | + (error "OpenAI API key not found in auth-source"))) |
72 | 72 |
|
73 |
| -(defcustom openai-key "" |
74 |
| - "Variable storing the openai key or a function to retrieve it. |
| 73 | +(defvar openai-key "" |
| 74 | + "Variable storing the openai key or a function name to retrieve it. |
75 | 75 |
|
76 | 76 | The function should take no arguments and return a string containing the key.
|
77 | 77 |
|
78 |
| -A function, `openai-key--auth-source', that retrieves the key from auth-source is provided for convenience. |
79 |
| -" |
80 |
| - :type '(choice string function) |
81 |
| - :set (lambda (option value) |
82 |
| - (cond ((stringp value) |
83 |
| - (set-default option value)) |
84 |
| - ((functionp value) |
85 |
| - (set-default option (symbol-name value))) |
86 |
| - (t |
87 |
| - (error "Invalid value for %s" option)))) |
88 |
| - :group 'openai) |
| 78 | +A function, `openai-key-auth-source', that retrieves the key from |
| 79 | +auth-source is provided for convenience. |
| 80 | +") |
89 | 81 |
|
90 | 82 |
|
91 | 83 | (defvar openai-user ""
|
|
0 commit comments