`llm.get_model()` fails with UnknownModelError for plugin-provided models (Ollama, GPT4All)
Description:
I am consistently encountering an llm.UnknownModelError when attempting to use models provided by plugins (specifically llm-ollama and llm-gpt4all) via llm.get_model() in Python, or when using the llm -m <model_name> CLI command.
Steps to Reproduce:
- Install
llmand plugins:pip install llm llm-ollama llm-gpt4all - Ensure Ollama is running and a model is pulled (e.g.,
smollm2:1.7b):ollama serve # In a separate terminal ollama pull smollm2:1.7b - Verify Ollama model is visible to
llm-ollamaplugin:llm ollama models # Expected output: smollm2:1.7b should be listed - Attempt to list all models (fails to show Ollama/GPT4All models):
llm models list # Expected output: Should list Ollama and GPT4All models, but only shows OpenAI models. - Attempt to use an Ollama model via
llm -m(fails):llm -m smollm2:1.7b 'Hello' # Expected output: UnknownModelError: 'Unknown model: smollm2:1.7b' - Attempt to use an Ollama model via
llm.get_model()in Python (fails): Create a Python script (e.g.,test_model.py):
Run the script:import llm import os import llm_ollama # Ensure plugin is loaded # Optional: Set host if not default os.environ['LLM_OLLAMA_HOST'] = 'http://localhost:11434' try: model = llm.get_model('smollm2:1.7b') print(f"Successfully loaded model: {model.model_id}") except llm.UnknownModelError as e: print(f"Error loading model: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")python test_model.py # Expected output: Error loading model: 'Unknown model: smollm2:1.7b' - Repeat steps 5 and 6 for a
gpt4allmodel (e.g.,gpt4all:qwen2-1_5b-instruct-q4_0): (Ensure you have downloaded a gpt4all model first, e.g., by runningllm -m gpt4all:qwen2-1_5b-instruct-q4_0 'test'once to trigger download) The behavior is identical:llm models listdoesn't show them, andllm.get_model()/llm -mfail withUnknownModelError.
Expected Behavior:
llm.get_model() and llm -m <model_name> should successfully resolve and use models provided by installed plugins like llm-ollama and llm-gpt4all, and llm models list should display these models.
Actual Behavior:
llm.get_model() and llm -m <model_name> consistently raise UnknownModelError, and llm models list does not display models provided by plugins, despite llm <plugin_name> models commands successfully listing them. This indicates a disconnect in the model registration/lookup process within the llm library itself.
Environment:
- Operating System: Linux
- Python Version: 3.13
llmversion: 0.26llm-ollamaversion: 0.12.0llm-gpt4allversion: 0.4- Ollama version: 0.5.7
I am also facing this issue with mlx-community/Llama-3.2-3B-Instruct-4bit, I downloaded the model with
llm mlx download-model mlx-community/Llama-3.2-3B-Instruct-4bit
And I can use it from the command line and it shows up when I do llm models, but I cannot use it from the Python API:
Traceback (most recent call last):
File "/Users/erling.jellum/dev/llm/rm-screen-share/.venv/lib/python3.13/site-packages/llm/__init__.py", line 321, in get_model
return aliases[name]
~~~~~~~^^^^^^
KeyError: 'mlx-community/Llama-3.2-3B-Instruct-4bit'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/erling.jellum/dev/llm/rm-screen-share/test3.py", line 3, in <module>
model = llm.get_model("mlx-community/Llama-3.2-3B-Instruct-4bit")
File "/Users/erling.jellum/dev/llm/rm-screen-share/.venv/lib/python3.13/site-packages/llm/__init__.py", line 334, in get_model
raise UnknownModelError("Unknown model: " + name)
llm.UnknownModelError: 'Unknown model: mlx-community/Llama-3.2-3B-Instruct-4bit'