-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set the ollama_models list based on locally available models when litellm starts. #8116
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -4146,7 +4146,7 @@ def _get_model_info_helper( # noqa: PLR0915 | |||
supports_prompt_caching=None, | |||
supports_pdf_input=None, | |||
) | |||
elif custom_llm_provider == "ollama" or custom_llm_provider == "ollama_chat": | |||
elif (custom_llm_provider == "ollama" or custom_llm_provider == "ollama_chat") and "*" not in model: | |||
return litellm.OllamaConfig().get_model_info(model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows ollama/*
and ollama_chat/*
to fall through to the else clause, where the entry becomes a placeholder that expands to the full model list later.
litellm/__init__.py
Outdated
# Since Ollama models are local, it is inexpensive to refresh the list at startup. | ||
# Also, this list can change very quickly. | ||
|
||
ollama_dir = os.environ.get("OLLAMA_MODELS", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the canonical way that the directory to use might be specified, though when not set has the home dir default.
litellm/__init__.py
Outdated
url = "http://localhost:11434/api/tags" | ||
try: | ||
response = requests.get(url) | ||
json_dict = response.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is fast and light, and only runs if an Ollama directory is specified and present. So it should be a no-op on systems that do not use ollama.
@@ -925,6 +949,7 @@ def add_known_models(): | |||
"bedrock": bedrock_models + bedrock_converse_models, | |||
"petals": petals_models, | |||
"ollama": ollama_models, | |||
"ollama_chat": ollama_models, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was required for ollama_chat/*
to work, keeping it symmetrical w/ support for ollama_chat/MODELNAME
.
…n litellm.proxy.proxy_server initialize().
@ishaan-jaff I just pushed a change to:
|
@@ -2833,6 +2836,39 @@ async def initialize( # noqa: PLR0915 | |||
if experimental: | |||
pass | |||
user_telemetry = telemetry | |||
refresh_local_model_lists() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this assume the user always has ollama models setup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be a no-op if there are no local models accessible?
from litellm import ollama_models | ||
|
||
# Use the same list reference in the module to avoid import order problems. | ||
ollama_models.clear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list remains empty unless there are local models found.
Title
Set
ollama_models
from the locally installed list at bootup.Relevant issues
Fixes #8095
Type
🆕 New Feature
🐛 Bug Fix
Changes
Previously: the
ollama_models
list was hard-coded to one model that might or might not be available on the host.Now: if the host has an ollama install available, it gets the list at bootup, and if not it has a zero-size list
Previously: using
ollama/*
orollama_chat/*
failed wildcard expansion when used in a config.Now: Either work to match all ollama models available at litellm start.
Attach a screenshot of any new tests passing locally
No new tests.
Functionality Demonstration
A CLI-based demonstration of litellm finding the full list of local ollama models:
Demonstration of equivalent data in the local ollama system:
Demonstration of the model counts matching (1-off b/c of the header):