gsuuon / model.nvim

Neovim plugin for interacting with LLM's and building editor integrated prompts.
MIT License
293 stars 21 forks source link

Use markdown for mchat filetype #54

Closed GordianDziwis closed 2 months ago

GordianDziwis commented 3 months ago

With the params as YAML front matter, the system prompt as a quoted block and the messages separated by >>> the syntax highlighting comes free with tree-sitter.

Also, nested code blocks with syntax highlighting are possible!

Here is an example how the mchat file could look like:

image

gsuuon commented 3 months ago

Sorry for the late response - I originally wanted something that looked a lot like that, but ended up not going that direction just because lua parsing comes free with neovim and I didn't want to implement a YAML parser or require luarocks to bring something in. If there's another way to get something that looks like this I'd take a PR!

I think it should be (somewhat?) straightforward to get markdown highlighting via treesitter with the current mchat syntax, would also happily take a PR for this as well (#44).

I didn't go with the explicit roles because these chats are meant to be portable across LLM's, and the role title changes so they end up needing to be converted at some point. It might make sense to allow opting in to explicitly setting the role for LLMs with multiple roles..

GordianDziwis commented 3 months ago

Do not be sorry, I am thankful for this nice piece of software and that you reply it all, is an amazing thing and gives me hope for humanity.

Ok, a YAML preamble is out.

But providing a file ftplugin/mchat.luat with the content:

vim.treesitter.start(0, 'markdown')
vim.bo[0].syntax = 'on'
vim.opt_local.conceallevel = 2

Changing the separator from ===== to >>> and inserting newlines before and after the separator would be all what is needed, to achieve the look from the op.

The roles would be there only for parsing, so that it does not break, when the llm returns a markdown document with >>>.

I do not have currently time for an PR, I will do it when it annoys me enough.

gsuuon commented 2 months ago

Glad you're enjoying the plugin! I think moving to treesitter is the right step generally and was my original intent - I've been taking another look at #44, I'll see if I can get something working soonish.

gsuuon commented 2 months ago

Closing in favor of #44