Ollama is disabled by default, as it normally does not require API keys
to be defined. Users are supposed to override is_env_set() method in
their configs to enable Ollama.
Provide check_endpoint_alive() helper in Ollama provider module that can
be used directly in place of is_env_set() and checks whether the server
replies to "get list of models" query:
...
ollama = {
is_env_set = require("avante.providers.ollama").check_endpoint_alive,
},
...
Without on_error() handler curl.get() will raise an error which then
will interrupt execution of the plenary job. This interruption will
result in timeout handling code triggering, introducing unneeded delay
and ugly stack traces.
Fix the problem by defining on_error() and callback() handlers and
explicitly wait for job completion with pcall() and Job:wait(). This
allows proper error handling and control over error messages.
Because plenary's curl implementation mangles stderr data, use a local
table to map select error codes to descriptive text messages.
Also do not emit hard error when endpoint is not configured, use
Utils.error().
With Ollama majority of people are using their own models, and Ollama
provider by default queries the server for list of models, so there is
no need to inherit anything.
Change the constructor to accept role and a single content item instead
of raw AvanteLLMMessage instance. This will help when we will start
changing message.content from being a string or a list of tables to just
a string or a single table.
The utils module has grown too big and contains unrelated functionality.
Start moving code related to managing history messages comprising chat
history into lua/avante/history module to keep the code more manageable.
* feat: add ollama as supported provider
*This implementation is only working with `stream = true`*
- Uses the actual ollama api and allows for passing additional options
- Properly passes the system prompt to api
Use ollama as provider in opts like this:
opts = {
debug = true,
provider = "ollama",
ollama = {
api_key_name = "",
endpoint = "http://127.0.0.1:11434",
model = "qwen2.5-coder:latest",
options = {
num_ctx = 32768,
temperature = 0,
},
stream = true,
},
* fix: ollama types
---------
Co-authored-by: jtabke <25010496+jtabke@users.noreply.github.com>