Skip to content

Commit

Permalink
docs: update RECIPES.md
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Feb 24, 2024
1 parent 70ea7fb commit 2e1b3c0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions RECIPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ In the following sections, we'll explore how you can customise these actions eve

As the years go by, I find myself writing less and less HTML. So when it comes to quickly scaffolding out a HTML page, I inevitably turn to a search engine. It would be great if I could have an action that could quickly generate some boilerplate HTML from the _Action Palette_.

Let's take a look at how we can achieve that below:
Let's take a look at how we can achieve that:

```lua
require("codecompanion").setup({
Expand Down Expand Up @@ -130,18 +130,19 @@ To make this example complete, we can leverage a pre-hook to create a new buffer
vim.api.nvim_set_current_buf(bufnr)
return bufnr
end
---
}
```

For the inline strategy, the plugin will detect a number being returned and assume that is the buffer number you wish any code to be streamed into.
For the inline strategy, the plugin will detect a number being returned from the `pre_hook` and assume that is the buffer number you wish any code to be streamed into.

### Conclusion

Whilst these examples were useful at demonstrating the functionality of the _Action Palette_, they're not making the most of the GenAI models to add any real value to your workflow (this boilerplate could be snippets after all). So let's step things up in the next section.

## Recipe #2: Using context in your prompts

Now let's look at how we can get GenAI to advise us on some selected code. This is builtin to the plugin as the _Code advisor_ action:
Now let's look at how we can get our GenAI model to advise us on some code that we have visually selected in a buffer. Infact, this very example is builtin to the plugin as the _Code advisor_ action:

```lua
require("codecompanion").setup({
Expand Down Expand Up @@ -179,7 +180,7 @@ require("codecompanion").setup({
})
```

Holy smokes there's a lot of new stuff in this. Let's break it down.
At first glance there's a lot of new stuff in this. Let's break it down.

### Palette options

Expand All @@ -191,10 +192,12 @@ opts = {
},
```

In the `opts` table we're specifying that we only want this action to appear if we're in visual mode. We're also asking the chat strategy to automatically send the prompts to OpenAI. It may be useful to turn this off if you wish to add some additional context prior to asking for a response. Finally, we're telling the picker that we want to prompt the user for some custom input.
In the `opts` table we're specifying that we only want this action to appear in the _Action Palette_ if we're in visual mode. We're also asking the chat strategy to automatically send the prompts to the GenAI model. It may be useful to turn this off if you wish to add some additional context prior to asking for a response. Finally, we're telling the picker that we want to get the user's prompt before we action the response.

### Prompt options and context

In the example below you can see how we've structured the prompts to get advice on the code:

```lua
prompts = {
{
Expand All @@ -217,7 +220,7 @@ prompts = {
},
```

One of the most useful features of the _Action Palette_ prompts is the ability to receive context about the current buffer which can then be used in the prompts themselves. A typical context table looks like:
One of the most useful features of the _Action Palette_ prompts is the ability to receive context about the current buffer and any lines of code we've selected. An example context table looks like:

```lua
{
Expand All @@ -237,7 +240,7 @@ One of the most useful features of the _Action Palette_ prompts is the ability t
}
```

Using the above context as an example, our first prompt then makes more sense:
Using the context above, our first prompt then makes more sense:

```lua
{
Expand Down

0 comments on commit 2e1b3c0

Please sign in to comment.