Comments (7)
I'm not using the snippet myself, but can it not be delayed with something like the following? It should only prompt you for password when you use the shell.
(setq chatgpt-shell-openai-key (lambda ()
(plist-get (car (auth-source-search :host "api.openai.com") :secret)))))
If you can validate this works, I'll update the README. Or if you can send a PR, greatly appreciated also :)
ps. Replying from mobile.
from chatgpt-shell.
I just tried this and while it asks for the passphrase when you first send a request to chatgpt, it gives back an error 400
.
I believe it is because curl is sending the resulting closure object as is somehow.
Using the hook, the expression gets evaluated to a byte code function object which seems to work fine as curl is sending the api key proper.
from chatgpt-shell.
I'd need to investigate.
I'm not familiar with authinfo though. Can you walk me through your setup so I can replicate? Maybe all the steps needed to save and restore a key like you do?
from chatgpt-shell.
My authinfo setup is pretty basic.
In my init file I have:
(setq auth-sources (list (expand-file-name
"etc/authinfo.gpg"
user-emacs-directory)
(expand-file-name "~/.authinfo.gpg")))
and in my .emacs.d/etc/authinfo.gpg, I have:
machine openai.com password MY_API_KEY
I use straight.el
to pull chatgpt-shell
which I then configure like so:
(require 'chatgpt-shell)
(add-hook 'inferior-chatgpt-mode-hook
(lambda ()
(setq chatgpt-shell-openai-key
(plist-get (car (auth-source-search :host "api.openai.com"))
:secret))))
in which case, my passphrase is being prompted when I M-x chatgpt-shell
and chatgpt-shell-openai-key
evaluates to this:
#[0 "\301\242\203\f\0\301\242\302\300!!\207\302\300!\207"
["<my_obfuscated_api_key>"
(nil)
auth-source--deobfuscate]
3]
whereas if I use your snippet, my passphrase is being prompted when I first send something ChatGPT> Hi
and chatgpt-shell-openai-key
evaluates to:
(closure
(t)
nil
(plist-get
(car
(auth-source-search :host "openai.com")
:secret)))
Apparently, by the time the curl request is formed, the byte code function ends up returning the clear key (which works) whereas the closure just gets sent as is.
I hope this helps.
from chatgpt-shell.
So it looks like (plist-get (car (auth-source-search :host "api.openai.com")) :secret)
already returns a function, so I was hoping that didn't trigger prompt for your gpg passphrase. But... I think you can actually do the following and avoid a hook:
(setq chatgpt-shell-openai-key
(lambda ()
(funcall (plist-get (car (auth-source-search :host "api.openai.com"))
:secret))))
It should give you lazy loading, so you're prompt only when you first use the ChatGPT shell.
See if the above works for ya.
from chatgpt-shell.
It works fine, thanks :).
If we're going with this method, I think the simpler auth-source-pick-first-password
mentioned in #27 could also be an improvement:
(setq chatgpt-shell-openai-key (lambda () (auth-source-pick-first-password :host "api.openai.com")))
It already does the funcall internally.
from chatgpt-shell.
Thank you! Updated README.org.
from chatgpt-shell.
Related Issues (20)
- selecting prompt for compose HOT 1
- shell maker cursor not returning properly at the end of prompt HOT 1
- better chatgpt-shell-prompt-compose interactions with existing prompt HOT 2
- Can't fold #+RESULT: section in org-babel HOT 3
- Prompt user to save shell transcript if pending HOT 1
- Tutorial on how to use, if possible Jan and other open source alternatives to chatgpt HOT 1
- Add variable to disable transcript saving prompt on exit HOT 1
- Closing the chatgpt-shell compose window while answer is streaming in 'hangs' Emacs until finished and produces many errors HOT 3
- Make display-buffer-alist configuration customizable HOT 6
- Is there a way to start a new session AND clear the chat buffer? HOT 2
- Interference of shell-maker HOT 2
- Dependence on curl HOT 1
- chatgpt-shell does not require dired
- chatgpt-shell-describe-image fails with the error "/usr/bin/emacs: /usr/bin/curl: Argument list too long" HOT 12
- Groq's API support HOT 3
- Using local Ollama models HOT 1
- How can I send a line?
- Installing dall-e-shell gives a warning/error HOT 2
- curl: (48) An unknown option was passed in to libcurl HOT 2
- You exceeded your current quota HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chatgpt-shell.