File tree Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ You will need to set up your API key before you can use this library.
40
40
(setq openai-key "[YOUR API KEY]")
41
41
```
42
42
43
+ Alternatively you can configure a function to retrieve the key from some
44
+ external source. A function, ` openai-key-auth-source ` is provided to retrieve
45
+ the key from an auth-source entry under the ` :host ` key ` api.openai.com `
46
+
47
+ ``` elisp
48
+ (setq openai-key 'openai-key-auth-source)
49
+ ```
50
+
43
51
For requests that need your user identifier,
44
52
45
53
``` elisp
Original file line number Diff line number Diff line change 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
+ ; ;
62
+ ; ;; Request
63
+
64
+ ;;;### autoload
65
+ (defun openai-key-auth-source ()
61
66
" Retrieve the OpenAI API key from auth-source."
62
67
(let ((auth-info (auth-source-search :max 1
63
68
:host " api.openai.com"
66
71
(funcall (plist-get (car auth-info) :secret ))
67
72
(error " OpenAI API key not found in auth-source " ))))
68
73
69
- ; ;
70
- ; ;; Request
71
-
72
-
73
- (defcustom openai-key " "
74
- " Variable storing the openai key or a function to retrieve it.
74
+ (defvar openai-key " "
75
+ " Variable storing the openai key or a function name to retrieve it.
75
76
76
77
The function should take no arguments and return a string containing the key.
77
78
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 )
79
+ A function, `openai-key-auth-source' , that retrieves the key from
80
+ auth-source is provided for convenience.
81
+ " )
89
82
90
83
91
84
(defvar openai-user " "
You can’t perform that action at this time.
0 commit comments