Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to set api_key using env variable and command line option #26

Closed
johnd0e opened this issue Oct 20, 2024 · 6 comments
Closed

Comments

@johnd0e
Copy link

johnd0e commented Oct 20, 2024

No description provided.

@efugier
Copy link
Owner

efugier commented Oct 21, 2024

Hey, thanks for asking!

You had a cli option although a bit limited: instead of api_key, you can use api_key_command as demonstrated here

api_key_command = "pass mistral/api_key" # you can use a command to grab the key

The issue was that it wasn't running the command in a shell so the syntax to read environment variable didn't work.

More context here: rust-lang/rust#95400 (comment)

In the end I just released 1.5.0 and made switch from just running the command to actually using the shell. The potential issue is it requires an installed and working sh, which isn't always the case on windows machines.

Anyway, now you're able to use

api_key_command = "echo $MY_API_KEY"

which should solve your issue 🙂

@efugier efugier closed this as completed Oct 21, 2024
@johnd0e
Copy link
Author

johnd0e commented Oct 21, 2024

This doesn't work:

api_key_command = "echo %GROQ_API_KEY%"

But this works:

api_key_command = "cmd /c echo %GROQ_API_KEY%"

Perhaps you could adapt shell to use cmd.exe /c "command" on Windows.
Full path to the shell is in the COMSPEC variable:

ComSpec=C:\Windows\system32\cmd.exe

@efugier efugier reopened this Oct 21, 2024
@efugier
Copy link
Owner

efugier commented Oct 21, 2024

This doesn't work:
api_key_command = "echo %GROQ_API_KEY%"

@johnd0e, this is expected, as it's sh that is used. If available on your machine (and it is because cmd something works, the correct syntax is echo $GROQ_API_KEY.

That said, now that I started writing different code for windows and unix I might as well go all the way, try version 1.7.0

Let me know if it works are intended this time!

@johnd0e
Copy link
Author

johnd0e commented Oct 21, 2024

correct syntax is echo $GROQ_API_KEY

You are right, that works on my system

@efugier
Copy link
Owner

efugier commented Oct 21, 2024

Great! Can you tell me if the windows syntax api_key_command = "echo %GROQ_API_KEY%" now works on your system?

It should after 1.7.0 but I want to check because of the backslash (among other things) for \c.

@johnd0e
Copy link
Author

johnd0e commented Oct 21, 2024

1.7.0 is ok, thanks

@johnd0e johnd0e closed this as completed Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants