Fetch Available Models Using API for Agents that Support It #98
Replies: 1 comment 4 replies
-
Thanks for your kinds words really appreciated. And the plugin continues to improve because the community comes up with awesome ideas. I've given some thought about adding this functionality in recent weeks. I'm mostly against it, because I think it adds bloat and steps in order to add a new adapter to the plugin. I've just recently updated my ADAPTERS.md guide and would love to be able to reduce the amount of work it takes to get to that stage. Also...Anthropic, Gemini, OpenAI...their models change so infrequently, it's easier just to make a PR to their respective adapters and add them to the choice table. There are some users who may like to show the adapter's settings in the chat buffer and calling an API every time you open a chat buffer is expensive. We'd need to implement some level of caching. It would end up being a lot of new lines of code for minimal reward (crikey I sound like a PM...). Ollama, however, is very different and I think this feature should be implemented. I had no idea they had a local endpoint for grabbing all the models so great spot and suggestion. I've added this support in e25932e. The default Ollama model will now be the most recent one. |
Beta Was this translation helpful? Give feedback.
-
For each adapter in source (except ollama, but more on that later), we have hard-coded model lists in
schema.model.choices
, eg:OpenAI in this example can instead be queried for models:
curl https://api.openai.com/v1/models \ -H "Authorization: Bearer $OPENAI_API_KEY"
I think it would be really cool to use this endpoint for populating the choices table, ideally with a simple local cache preventing over-fetching. To my knowledge Anthropic doesn't have this unfortunately.
Coming back to ollama, it looks like something similar to my suggestion is being done:
The issue here is if you are not running ollama locally, (and even if you are, you might be running in a container). Running ollama commands directly on the machine running neovim will not work in these cases. Luckily, ollama has an endpoint for this!:
/v1/models
. Example:Yields:
Of course the response comes back as json, so it would need to be parsed differently from the code above.
UPDATE: here is a quick crack at reimplementing
get_ollama_choices()
usingcurl
viaplenary
:If acceptable, I'd love to make a contribution to this wonderful project.
UPDATE:
Implemented for OpenAI as well -- check my branch!
Beta Was this translation helpful? Give feedback.
All reactions