mistral_common.experimental.app.routers
detokenize_to_assistant_message(settings, tokens=Body(default_factory=list))
async
Detokenize a list of tokens to an assistant message.
Parse tool calls from the tokens and extract content before the first tool call. Requires a tokenizer version > v1 for tool call parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
list[int]
|
The token IDs to detokenize. Must be non-empty. |
Body(default_factory=list)
|
settings
|
Annotated[Settings, Depends(get_settings)]
|
The app settings providing the tokenizer. |
required |
Returns:
| Type | Description |
|---|---|
AssistantMessage
|
The detokenized assistant message with content and tool calls. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 if the tokens list is empty. |
Source code in src/mistral_common/experimental/app/routers.py
detokenize_to_string(settings, tokens=Body(default_factory=list), special_token_policy=Body(default=SpecialTokenPolicy.IGNORE))
async
Detokenize a list of tokens to a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
list[int]
|
The token IDs to detokenize. Must be non-empty. |
Body(default_factory=list)
|
special_token_policy
|
SpecialTokenPolicy
|
The policy to use for special tokens (IGNORE, KEEP, or RAISE). |
Body(default=IGNORE)
|
settings
|
Annotated[Settings, Depends(get_settings)]
|
The app settings providing the tokenizer. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The detokenized string. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 if the tokens list is empty. |
Source code in src/mistral_common/experimental/app/routers.py
generate(request, settings)
async
Generate a chat completion by proxying to the configured engine.
The request is validated and tokenized locally, then forwarded to the engine, and the returned tokens are detokenized into an assistant message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionRequest | OpenAIChatCompletionRequest
|
The chat completion request, in Mistral or OpenAI format. |
required |
settings
|
Annotated[Settings, Depends(get_settings)]
|
The settings for the Mistral-common API, providing the tokenizer and engine configuration. |
required |
Returns:
| Type | Description |
|---|---|
AssistantMessage
|
The generated assistant message. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 on invalid request or empty messages; 502 if the engine fails. |
Source code in src/mistral_common/experimental/app/routers.py
redirect_to_docs()
async
tokenize_request(request, settings)
async
Tokenize a chat completion request.