Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Mar 17, 2024
1 parent eb9fa6f commit 5d612fc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ require("codecompanion").setup({

The plugin uses adapters to bridge between generative AI services and the plugin. Currently the plugin supports:

- Anthropic (`anthropic`) - Requires `ANTHROPIC_API_KEY` to be set in your shell
- Anthropic (`anthropic`) - Requires an API key
- Ollama (`ollama`)
- OpenAI (`openai`) - Requires `OPENAI_API_KEY` to be set in your shell
- OpenAI (`openai`) - Requires an API key

You can specify an adapter for each of the strategies in the plugin:

Expand All @@ -175,18 +175,14 @@ require("codecompanion").setup({
})
```

#### Modifying Adapters

It may be necessary to modify certain parameters of an adapter. In the example below, we're changing the name of the API key that the OpenAI adapter uses by passing in a table to the `use` method:
Of course, you may need to modify certain parameters of an adapter. In the example below, we're changing the name of the API key that the OpenAI adapter uses by passing in a table to the `use` method:

```lua
require("codecompanion").setup({
adapters = {
chat = require("codecompanion.adapters").use("openai", {
env = {
api_key = "DIFFERENT_OPENAI_KEY",
-- To execute a shell command, prefix it with "cmd:"
-- api_key = "cmd:gpg --decrypt ~/.openai-api-key.gpg 2>/dev/null",
},
}),
},
Expand All @@ -196,6 +192,22 @@ require("codecompanion").setup({
> [!TIP]
> To create your own adapter please refer to the [ADAPTERS](ADAPTERS.md) guide
#### Additional API Key Options

Having API keys in plain text in your shell is not always safe as any application could access them. Thanks to [this PR](https://github.com/olimorris/codecompanion.nvim/pull/24), you can use encrypted files instead:

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

### Edgy.nvim Configuration

The author recommends pairing with [edgy.nvim](https://github.com/folke/edgy.nvim) for a Co-Pilot Chat-like experience:
Expand Down
35 changes: 25 additions & 10 deletions doc/codecompanion.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ ADAPTERS ~
The plugin uses adapters to bridge between generative AI services and the
plugin. Currently the plugin supports:

- Anthropic (`anthropic`) - Requires `ANTHROPIC_API_KEY` to be set in your shell
- Anthropic (`anthropic`) - Requires an API key
- Ollama (`ollama`)
- OpenAI (`openai`) - Requires `OPENAI_API_KEY` to be set in your shell
- OpenAI (`openai`) - Requires an API key

You can specify an adapter for each of the strategies in the plugin:

Expand All @@ -151,21 +151,16 @@ You can specify an adapter for each of the strategies in the plugin:
})
<


MODIFYING ADAPTERS

It may be necessary to modify certain parameters of an adapter. In the example
below, we’re changing the name of the API key that the OpenAI adapter uses by
passing in a table to the `use` method:
Of course, you may need to modify certain parameters of an adapter. In the
example below, we’re changing the name of the API key that the OpenAI adapter
uses by passing in a table to the `use` method:

>lua
require("codecompanion").setup({
adapters = {
chat = require("codecompanion.adapters").use("openai", {
env = {
api_key = "DIFFERENT_OPENAI_KEY",
-- To execute a shell command, prefix it with "cmd:"
-- api_key = "cmd:gpg --decrypt ~/.openai-api-key.gpg 2>/dev/null",
},
}),
},
Expand All @@ -176,6 +171,26 @@ passing in a table to the `use` method:
[!TIP] To create your own adapter please refer to the ADAPTERS <ADAPTERS.md>
guide

ADDITIONAL API KEY OPTIONS

Having API keys in plain text in your shell is not always safe as any
application could access them. Thanks to this PR
<https://github.com/olimorris/codecompanion.nvim/pull/24>, you can use
encrypted files in the configuration:

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


EDGY.NVIM CONFIGURATION ~

The author recommends pairing with edgy.nvim
Expand Down

0 comments on commit 5d612fc

Please sign in to comment.