- Models and inference
- Conversations
- Advanced
Predicted Outputs
Predicted Outputs
Predicted Outputs optimizes response time by leveraging known or predictable content. This approach minimizes latency while maintaining high output quality. In tasks such as editing large texts, modifying code, or generating template-based responses, significant portions of the output are often predetermined. By predefining these expected parts with Predicted Outputs, models can allocate more computational resources to the unpredictable elements, improving overall efficiency.
Usage Example
Code Modification
Predicted Outputs shine in scenarios where you need to regenerate text documents or code files with minor modifications. The key parameter introduced is the prediction parameter, which enables users to define predicted outputs. For example, imagine you want your model to update the model used in a chat request. You can include the code snippet you'd like to modify as both the user prompt and the predicted output.
Before continuing, we recommend reading the Chat Completions documentation to learn more about the chat completions API and how to use it before proceeding.
import os
from mistralai import Mistral
api_key = os.environ["MISTRAL_API_KEY"]
model = "mistral-large-2411"
client = Mistral(api_key=api_key)
code = """
response = client.chat.complete(
model="open-mistral-7b",
messages=[
{"role": "user", "content": "Summarize this document."}
]
)
"""
prompt = "Change the model name from open-mistral-7b to open-mistral-nemo. Respond only with code, no explanation, no formatting."
chat_response = client.chat.complete(
model= model,
messages = [
{
"role": "user",
"content": prompt,
},
{
"role": "user",
"content": code
},
],
prediction = {
"type": "content",
"content": code
}
)
{
"id": "987f971cf1d24d0cbf88a50e2c850546",
"created": 1756812876,
"model": "mistral-large-2411",
"usage": {
"prompt_tokens": 153,
"total_tokens": 270,
"completion_tokens": 117
},
"object": "chat.completion",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"tool_calls": null,
"content": "```python\nresponse = client.chat.complete(\nmodel=\"open-mistral-nemo\",\nmessages=[\n{\"role\": \"user\", \"content\": \"Summarize this document.\"}\n]\n)\n```"
}
}
]
}
FAQ
As of now, codestral-latest and mistral-large-2411 support predicted outputs.
Currently, predicted outputs do not impact pricing.
n (number of completions to return for each request) is not supported when using predicted outputs.
No, the placement of sentences or words in your prediction does not affect its effectiveness. Predictions can appear anywhere within the generated response and still help reduce the API's output latency.