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. sys_msg falls back to
the default breakdown system message, and prompt to the default template.
The template is rendered server-side with the sentence, focus, and
context values (see render_breakdown_prompt)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req
|
BreakdownRequest
|
The breakdown request |
required |
Returns:
| Type | Description |
|---|---|
StreamingResponse
|
An SSE stream: a |
Raises:
| Type | Description |
|---|---|
InvalidModelStringError
|
If the model selector is malformed |
LLMProviderUnavailableError
|
If the requested provider isn't configured |
breakdown_preview(req)
async
¶
Renders a breakdown prompt template against sample values, no LLM call
Powers the template editor's live preview, so a user sees the assembled
prompt (and how a {#context} block appears or vanishes) as they type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req
|
BreakdownPreviewRequest
|
The template and sample values |
required |
Returns:
| Type | Description |
|---|---|
BreakdownPreviewResponse
|
The rendered prompt |
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 |
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 ( |
required |
Returns:
| Type | Description |
|---|---|
ModelsResponse
|
Mapping with a |
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 |
|---|---|
ProvidersResponse
|
A |
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 |
Raises:
| Type | Description |
|---|---|
InvalidModelStringError
|
If the model selector is malformed |
LLMProviderUnavailableError
|
If the requested provider isn't configured |