gsuuon/model.nvim

User message not parsed when using `ollama:starling`.

codetalker7 opened this issue · 1 comments

I tried following the example config from the README using ollama's starling-lm model. In particular, here's the steps I'm following (I'm not making any changes to the default configuration):

  1. First I run :Mchat ollama:starling You are a helpful assistant. This opens an .mchat buffer with the following contents:
ollama:starling
---
{
  params = {
    model = "starling-lm"
  }
}
---
> You are a helpful assistant.

So the system message and the config is indeed correct. Next, I type something as my first message; so, say the contents of the mchat buffer are as follows:

ollama:starling
---
{
  params = {
    model = "starling-lm"
  }
}
---
> You are a helpful assistant.

Hi! I'm Siddhant, and I need some help with `lua` coding!

So now hopefully the parser should identify the system message and the first user message correctly; however, on running :Mchat, this gives me an error:

Error executing Lua callback: ...local/share/nvim/lazy/model.nvim/lua/model/cor
e/chat.lua:314: attempt to index local 'last_msg' (a nil value)
stack traceback:
        ...local/share/nvim/lazy/model.nvim/lua/model/core/chat.lua:314: in fun
ction 'run_chat'
        ...er7/.local/share/nvim/lazy/model.nvim/lua/model/init.lua:313: in fun
ction <...er7/.local/share/nvim/lazy/model.nvim/lua/model/init.lua:259>

So it seems that the user message is not being parsed. I tried to dump the parsed table from the code in run_chat, and I got this:

{ ["contents"] = { ["messages"] = { } ,["config"] = { ["system"] = You are a he
lpful assistant.,["params"] = { ["model"] = starling-lm,} ,} ,} ,["chat"] = oll
ama:starling,}

Indeed, it couldn't parse the user message. Or am I missing something here?

I think I figured out the error; it's this line:

local first_msg = table.remove(messages, 1)

When we do this, we're actually popping off the first message from messages table. But this table is being later reused:

local last_msg = parsed.contents.messages[#parsed.contents.messages]

So when this line runs, the table is empty; hence giving nil.

I'll make a PR to fix the prompt format.