llm.nvim
llm.nvim copied to clipboard
Merge of user config with default config causes issues
Hi there, thanks for the cool plugin.
I noticed an issue caused by how you merge the default config with the user provided config in config.lua. I usually use ollama and decided to try out vllm, but had a a bit of trouble getting it to work because of this.
vllm exposes an openAI compatible API, so my request_body looked something like the following:
request_body = {
temperature = 0,
top_p = 0.9,
presence_penalty = 1,
stop = { '<|file_separator|>', '<|fim_prefix|>', '<|fim_suffix|>', '<|fim_middle|>' }
}
vllm kept throwing me HTTP bad request errors, and sniffing the requests sent to vllm showed me that the default values for the request body (the parameters object) were being sent along with my own request body, which was unexpected. vllm visibly does not like unexpected arguments.
The problem comes from the use of vim.tbl_deep_extend(), which recursively merges the default config map with the user provided one. As a consequence, the user provided request body gets merged with the default one, which for the request body in particular is surprising behavior.
You can observe the same behavior by using the configuration provided in the README for say, ollama and looking at the transmitted request body: the parameters object is present alongside the options object although it's not present in the user config, ollama is just more graceful than vllm about it.
I worked around it by explicitly deleting the parameters object from the llm.nvim config table just after the setup() call with this: require('llm.config').config.request_body.parameters = nil. Not a complex workaround, but I did need to go and check the plugin source to figure it out.
The fix that I would suggest is that, since the default config is provided for the huggingface backend, you should either not merge the default request_body with the user config if the user is not using the huggingface backend, or include a matching default request body for other backends (for instance what's in the README) and merge with that. Let me know if you'd like a PR for it.