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

feat: add config.chat_template to be able to customize the chat file banner #117

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

argshook
Copy link
Contributor

Hello again 👋

Your plugin is still amazing, thanks once more for working on it and keeping it open source!


This PR adds a new config option: chat_template. The default messaging is good, but as i'm familiar with how the plugin works, I don't need to be reminded about the shortcuts each time.

Therefore, i'd like to configure that message, but couldn't find a way to do so. Maybe i missed it?

A bit naive but very simple way is to expose chat_template to be configurable. If user decides to set it, then it is up to them to set it correctly.

If chat_template is not set, nothing changes and the current message is shown. So no impact for existing users.

Having chat_template config option i'm able to:

require("gp").setup({
  chat_user_prefix = "🗨:",
  chat_template = "# topic: ?\n\n"
    .. "- file: %s\n"
    .. "---\n"
    .. "🗨: "
})

and now each chat file looks like:

# topic: ?

- file: 2024-03-13.19-09-31.030.md
---
🗨:

which is neat, much cleaner!


additional thought is that perhaps markdown frontmatter would fit here for the banner? It is often used to set some extra properties that are not part of markdown body. Lua probably already has some utilities to deal with frontmatter, so chances are it might be easy addition (i'm lua noob, i wouldn't know!).

Anyway, thanks for the plugin, just wanted to share my 2 cents.

Cheers!

@argshook argshook changed the title add config.chat_template to be able to customize the chat file banner feat: add config.chat_template to be able to customize the chat file banner Mar 13, 2024
argshook and others added 6 commits May 17, 2024 11:06
`gp.nvim` has autosave feature which is triggered by few events, one of
which is `TextChangedI`.

when typing text in insert mode, any change done there saves the file.
This grows the `:undolist` too much, because any change in insert mode
is saved and treated as a separate change.

Normally to undo the last change, you would press `u` once in normal mode.
But with autosave triggered by `TextChangedI`, you have to press `u` multiple times, for each change.

using `InsertLeave` instead of `TextChangedI` avoids such problem.

For comparison, consider scenario:

1. open neovim
2. run `:GpChatNew`
3. go to insert mode and type `123`
4. leave insert mode
5. run `:undolist`

on my setup it shows:

```
number changes  when               saved
     4       4  2 seconds ago
```

doing the equivalent when `InsertLeave` is used instead of `TextChangedI`:

```
number changes  when               saved
     1       1  2 seconds ago        1
```

this is much better, because now you can undo the last change with single `u` press!
fixes the error:
```
ln: failed to create symbolic link 'chats/last.md': Directory not empty
```
- Set `model` parameter to "gpt-4o" in both chat and command configurations.
Add a prominent note about this repo being a fork with improvements.
this changes the `{{filename}}` substitute in templates to point to a
relative path from the `.git` repository. If `.git` repository is not
found, then full path is used.

With this change commands like `:GpChatPaste` would include a less
verbose path without including the username.

For example with config like this:

```lua
template_selection = "from `{{filename}}`"
```

we now get
```
from `my-project/file.py`
```

previously we would get

```
from `/home/username/projects/repositories/my-project/file.py`
```

which is often excessive and also leaks the username.
@marcomayer
Copy link
Contributor

just what I was looking for...hope this gets merged soon 🤞

@argshook
Copy link
Contributor Author

argshook commented Jun 27, 2024

Hey @marcomayer 👋🏻
you can try out my fork, until (and if) this gets merged to upstream.

Wrote about how to do that here

i see this PR now includes more than needed, because it points to the main branch of my fork, instead of a more appropriate one.

I'll try to remember about it and find time to update 🤞🏻

@Robitx
Copy link
Owner

Robitx commented Jul 20, 2024

@argshook Hey, I've cherry picked and slightly adjusted the

  • 0b6fc73
    • chat template now uses {{tags}} instead of %s
       M.chat_template = [[
       # topic: ?
       
       - file: {{filename}}
       {{optional_headers}}
       Write your queries after {{user_prefix}}. Use `{{respond_shortcut}}` or :{{cmd_prefix}}ChatRespond to generate a response.
       Response generation can be terminated by using `{{stop_shortcut}}` or :{{cmd_prefix}}ChatStop command.
       Chats are saved automatically. To delete this chat, use `{{delete_shortcut}}` or :{{cmd_prefix}}ChatDelete.
       Be cautious of very long chats. Start a fresh chat by using `{{new_shortcut}}` or :{{cmd_prefix}}ChatNew.
       
       ---
       
       {{user_prefix}}
       ]]
    • full and short template versions are available in gp.defaults
        chat_template = require("gp.defaults").chat_template,
      -- if you want more real estate in your chat files and don't need the helper text
      -- chat_template = require("gp.defaults").short_chat_template,
  • 0260c28
    • relative paths keep the repository folder name since "name of the project" can be a useful information for the model

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.

None yet

5 participants