Code Monkey home page Code Monkey logo

Comments (7)

xenodium avatar xenodium commented on June 12, 2024

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.

MunsterPlop avatar MunsterPlop commented on June 12, 2024

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.

xenodium avatar xenodium commented on June 12, 2024

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.

MunsterPlop avatar MunsterPlop commented on June 12, 2024

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.

xenodium avatar xenodium commented on June 12, 2024

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.

MunsterPlop avatar MunsterPlop commented on June 12, 2024

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.

xenodium avatar xenodium commented on June 12, 2024

Thank you! Updated README.org.

from chatgpt-shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.