Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ai/models/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pydantic

from ... import _modelsdev
from ...errors import ConfigurationError
from ...errors import ConfigurationError, UnsupportedProviderError
from ...providers import base

if TYPE_CHECKING:
Expand Down Expand Up @@ -152,7 +152,8 @@ def get_model(
model_id = f"gateway:{model_id}"

ref = _modelsdev.parse_model_id(model_id)
assert ref.provider_id is not None # guaranteed to be fully-qualified here
if ref.provider_id is None:
raise UnsupportedProviderError(model_id.partition(":")[0])
provider_id = ref.provider_id
provider_model_id = ref.model_id

Expand Down
10 changes: 10 additions & 0 deletions tests/models/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

import pydantic
import pytest

import ai
from ai.types import events
Expand Down Expand Up @@ -86,3 +87,12 @@ def test_a_context_keeps_a_model_like_as_it_is() -> None:
model = Echo()
context = ai.Context(model=model, messages=[], tools=[])
assert context.model is model


@pytest.mark.parametrize("model_id", ["nope:model", "ollama:llama3"])
def test_get_model_unknown_provider_raises_unsupported_provider(
model_id: str,
) -> None:
"""The docstring promises ``UnsupportedProviderError``."""
with pytest.raises(ai.errors.UnsupportedProviderError):
ai.get_model(model_id)
Loading