Skip to content

solidworks_mcp.ui.routers.local_model

solidworks_mcp.ui.routers.local_model

Local Ollama model probe / pull / query routes for the Prefab CAD dashboard.

Attributes

router module-attribute

router = APIRouter()

Classes

LocalAgentResult

Bases: BaseModel, Generic[_T]

Typed envelope wrapping a structured pydantic-ai agent response.

data holds the validated result_type instance; config echoes back the LocalLLMConfig used so callers can log or audit provenance. Set success=False and error when the agent returned a RecoverableFailure or raised an exception.

Attributes:

Name Type Description
config LocalLLMConfig

The config value.

data Any

The data value.

error str | None

The error value.

retry_hint str | None

The retry hint value.

success bool

The success value.

LocalModelProbeResult

Bases: BaseModel

Full hardware-detection and Ollama availability result.

Returned by probe_local_model() and serialised as the JSON response from GET /api/ui/local-model/probe. The to_config() helper converts directly into a LocalLLMConfig ready for run_local_agent().

Attributes:

Name Type Description
all_tiers dict[str, str]

The all tiers value.

available bool

The available value.

endpoint str

The endpoint value.

label str

The label value.

ollama_model str

The ollama model value.

openai_endpoint str

The openai endpoint value.

pull_command str

The pull command value.

pulled_models list[str]

The pulled models value.

ram_gb float

The ram gb value.

service_model str

The service model value.

status_message str

The status message value.

tier Literal['small', 'balanced', 'large']

The tier value.

tier_already_pulled bool

The tier already pulled value.

vram_gb float

The vram gb value.

Functions
to_config
to_config() -> LocalLLMConfig

Convert probe result into a ready-to-use LocalLLMConfig.

Returns:

Name Type Description
LocalLLMConfig LocalLLMConfig

The result produced by the operation.

Source code in src/solidworks_mcp/ui/local_llm.py
def to_config(self) -> LocalLLMConfig:
    """Convert probe result into a ready-to-use ``LocalLLMConfig``.

    Returns:
        LocalLLMConfig: The result produced by the operation.
    """
    return LocalLLMConfig(
        endpoint=self.endpoint,
        openai_endpoint=self.openai_endpoint,
        tier=self.tier,
        ollama_model=self.ollama_model,
        service_model=self.service_model,
    )

LocalModelPullRequest

Bases: BaseModel

Request body for POST /api/ui/local-model/pull.

Attributes:

Name Type Description
endpoint str | None

The endpoint value.

model str

The model value.

LocalModelPullResult

Bases: BaseModel

Result from POST /api/ui/local-model/pull.

Attributes:

Name Type Description
error str | None

The error value.

model str

The model value.

queued bool

The queued value.

response dict[str, Any] | None

The response value.

LocalModelQueryRequest

Bases: BaseModel

Request body for POST /api/ui/local-model/query.

Attributes:

Name Type Description
endpoint str | None

The endpoint value.

model str | None

The model value.

prompt str

The prompt value.

system_prompt str

The system prompt value.

Functions

probe_local_model_endpoint async

probe_local_model_endpoint() -> LocalModelProbeResult

Probe for a running Ollama server and recommend the best Gemma model tier.

Source code in src/solidworks_mcp/ui/routers/local_model.py
@router.get("/api/ui/local-model/probe")
async def probe_local_model_endpoint() -> LocalModelProbeResult:
    """Probe for a running Ollama server and recommend the best Gemma model tier."""
    from ..local_llm import probe_local_model  # noqa: PLC0415

    return await probe_local_model()

pull_local_model_endpoint async

pull_local_model_endpoint(payload: LocalModelPullRequest) -> LocalModelPullResult

Trigger an Ollama pull for the specified model name.

Source code in src/solidworks_mcp/ui/routers/local_model.py
@router.post("/api/ui/local-model/pull")
async def pull_local_model_endpoint(
    payload: LocalModelPullRequest,
) -> LocalModelPullResult:
    """Trigger an Ollama pull for the specified model name."""
    from ..local_llm import pull_ollama_model  # noqa: PLC0415

    return await pull_ollama_model(model=payload.model, endpoint=payload.endpoint)

query_local_model_endpoint async

query_local_model_endpoint(payload: LocalModelQueryRequest) -> LocalAgentResult

Run a free-form prompt against the local Ollama model.

Source code in src/solidworks_mcp/ui/routers/local_model.py
@router.post("/api/ui/local-model/query")
async def query_local_model_endpoint(
    payload: LocalModelQueryRequest,
) -> LocalAgentResult:
    """Run a free-form prompt against the local Ollama model."""
    from pydantic import BaseModel as _BaseModel

    from ..local_llm import LocalLLMConfig, run_local_agent  # noqa: PLC0415

    class _FreeFormResponse(_BaseModel):
        text: str

    config = LocalLLMConfig.from_env()
    if payload.endpoint:
        config = config.model_copy(
            update={
                "endpoint": payload.endpoint,
                "openai_endpoint": f"{payload.endpoint}/v1",
            }
        )
    if payload.model:
        service_model = (
            payload.model
            if payload.model.startswith("local:")
            else f"local:{payload.model}"
        )
        config = config.model_copy(update={"service_model": service_model})

    return await run_local_agent(
        system_prompt=payload.system_prompt,
        user_prompt=payload.prompt,
        result_type=_FreeFormResponse,
        config=config,
    )