Skip to content

Llm

llm

This module defines the llm_router of the Mirumoji API

Attributes:

Name Type Description
LOGGER Logger

Module's logging object

llm_router APIRouter

The FastAPI router object

breakdown(req) async

Streams the nuance of a focus word within a sentence as Server-Sent Events

The focus word (its stitched token + dictionary data) is emitted once as a focus event, then the LLM explanation streams as data: frames

sys_msg and prompt are independently optional and fall back to the default breakdown system message and prompt

Parameters:

Name Type Description Default
req BreakdownRequest

The breakdown request

required

Returns:

Type Description
StreamingResponse

An SSE stream: a focus frame (when a focus is given), the explanation chunks, and a terminal done frame

Raises:

Type Description
InvalidModelStringError

If the model selector is malformed

LLMProviderUnavailableError

If the requested provider isn't configured

LLMRequestError

If the prompt template is invalid

explain_sentence(req) async

Streams an explanation of a whole sentence as Server-Sent Events

sys_msg and prompt are independently optional and fall back to the default breakdown system message and sentence prompt

Parameters:

Name Type Description Default
req ExplainSentenceRequest

The explanation request

required

Returns:

Type Description
StreamingResponse

An SSE stream of explanation chunks ending with a done frame

Raises:

Type Description
InvalidModelStringError

If the model selector is malformed

LLMProviderUnavailableError

If the requested provider isn't configured

LLMRequestError

If the prompt template is invalid

list_models(provider) async

Lists the available models for a configured LLM provider

Lets the frontend offer a model dropdown for the cloud providers, so users pick a valid model instead of typing one that 404s

Parameters:

Name Type Description Default
provider str

The provider id (openai, anthropic, gemini, local)

required

Returns:

Type Description
dict[str, list[str]]

Mapping with a models list of model ids

Raises:

Type Description
InvalidModelStringError

If the provider id is unknown

LLMProviderUnavailableError

If the provider isn't configured

LLMRequestError

If the provider's models endpoint fails

list_providers() async

Reports which LLM providers are usable in this deployment

Returns:

Type Description
dict[str, Any]

Mapping with a providers list of {"provider", "available"} entries, used by the frontend to populate the model picker

stream(req) async

Streams a chat completion as Server-Sent Events

Parameters:

Name Type Description Default
req ChatRequest

The chat request

required

Returns:

Type Description
StreamingResponse

An SSE stream of completion chunks ending with a done event

Raises:

Type Description
InvalidModelStringError

If the model selector is malformed

LLMProviderUnavailableError

If the requested provider isn't configured