Skip to content

Add support for a shell command in place of environment variable name#24

Merged
olimorris merged 3 commits into
olimorris:mainfrom
abayomi185:main
Mar 17, 2024
Merged

Add support for a shell command in place of environment variable name#24
olimorris merged 3 commits into
olimorris:mainfrom
abayomi185:main

Conversation

@abayomi185
Copy link
Copy Markdown
Contributor

Having the API key in environment variables is not always safe, as any application or program can read it.

I also had a situation where a program didn't load the project specific .env file but used the main key from the user profile - although, this case can be rectified with the recent pattern using a different variable name.

This PR allows for this:

chat = require("codecompanion.adapters").use("openai", {
  env = {
    api_key = "cmd:gpg --decrypt ~/.openai-api-key.gpg 2>/dev/null",
  },
}),

I'm happy to make further changes; this change breaks assumptions about what the config should be.

@olimorris
Copy link
Copy Markdown
Owner

Thank you and great suggestion.

More than happy to add this to the plugin. Could you update the readme to reflect this too? I think this would be a popular addition.

@abayomi185
Copy link
Copy Markdown
Contributor Author

Yes. README has been updated.

@olimorris
Copy link
Copy Markdown
Owner

Fantastic and thanks again. I will make sure I use this for my own API keys

@olimorris olimorris merged commit f831051 into olimorris:main Mar 17, 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

Successfully merging this pull request may close these issues.

2 participants