llm icon indicating copy to clipboard operation
llm copied to clipboard

`llm.get_model()` fails with UnknownModelError for plugin-provided models (Ollama, GPT4All)

Open jwgcurrie opened this issue 1 year ago • 1 comments

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:

  1. Install llm and plugins:
    pip install llm llm-ollama llm-gpt4all
    
  2. 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
    
  3. Verify Ollama model is visible to llm-ollama plugin:
    llm ollama models
    # Expected output: smollm2:1.7b should be listed
    
  4. 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.
    
  5. Attempt to use an Ollama model via llm -m (fails):
    llm -m smollm2:1.7b 'Hello'
    # Expected output: UnknownModelError: 'Unknown model: smollm2:1.7b'
    
  6. Attempt to use an Ollama model via llm.get_model() in Python (fails): Create a Python script (e.g., test_model.py):
    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}")
    
    Run the script:
    python test_model.py
    # Expected output: Error loading model: 'Unknown model: smollm2:1.7b'
    
  7. Repeat steps 5 and 6 for a gpt4all model (e.g., gpt4all:qwen2-1_5b-instruct-q4_0): (Ensure you have downloaded a gpt4all model first, e.g., by running llm -m gpt4all:qwen2-1_5b-instruct-q4_0 'test' once to trigger download) The behavior is identical: llm models list doesn't show them, and llm.get_model()/llm -m fail with UnknownModelError.

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
  • llm version: 0.26
  • llm-ollama version: 0.12.0
  • llm-gpt4all version: 0.4
  • Ollama version: 0.5.7

jwgcurrie avatar Jul 06 '25 15:07 jwgcurrie

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'

erlingrj avatar Aug 20 '25 08:08 erlingrj