Skip to main content

mistral_openapi_client/models/
chat_completion_request.rs

1/*
2 * Mistral AI API
3 *
4 * Our Chat Completion and Embeddings APIs specification. Create your account on [La Plateforme](https://console.mistral.ai) to get access and read the [docs](https://docs.mistral.ai) to learn how to use it.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15pub struct ChatCompletionRequest {
16    /// ID of the model to use. You can use the [List Available Models](/api/#tag/models/operation/list_models_v1_models_get) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
17    #[serde(rename = "model")]
18    pub model: String,
19    #[serde(rename = "temperature", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
20    pub temperature: Option<Option<f64>>,
21    /// Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
22    #[serde(rename = "top_p", skip_serializing_if = "Option::is_none")]
23    pub top_p: Option<f64>,
24    #[serde(rename = "max_tokens", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
25    pub max_tokens: Option<Option<i32>>,
26    /// Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
27    #[serde(rename = "stream", skip_serializing_if = "Option::is_none")]
28    pub stream: Option<bool>,
29    #[serde(rename = "stop", skip_serializing_if = "Option::is_none")]
30    pub stop: Option<Box<models::Stop>>,
31    #[serde(rename = "random_seed", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
32    pub random_seed: Option<Option<i32>>,
33    #[serde(rename = "metadata", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
34    pub metadata: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
35    /// The prompt(s) to generate completions for, encoded as a list of dict with role and content.
36    #[serde(rename = "messages")]
37    pub messages: Vec<models::MessagesInner>,
38    #[serde(rename = "response_format", skip_serializing_if = "Option::is_none")]
39    pub response_format: Option<Box<models::ResponseFormat>>,
40    #[serde(rename = "tools", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
41    pub tools: Option<Option<Vec<models::Tool>>>,
42    #[serde(rename = "tool_choice", skip_serializing_if = "Option::is_none")]
43    pub tool_choice: Option<Box<models::ToolChoice>>,
44    /// The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
45    #[serde(rename = "presence_penalty", skip_serializing_if = "Option::is_none")]
46    pub presence_penalty: Option<f64>,
47    /// The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
48    #[serde(rename = "frequency_penalty", skip_serializing_if = "Option::is_none")]
49    pub frequency_penalty: Option<f64>,
50    #[serde(rename = "n", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
51    pub n: Option<Option<i32>>,
52    /// Enable users to specify expected results, optimizing response times by leveraging known or predictable content. This approach is especially effective for updating text documents or code files with minimal changes, reducing latency while maintaining high-quality results.
53    #[serde(rename = "prediction", skip_serializing_if = "Option::is_none")]
54    pub prediction: Option<Box<models::Prediction>>,
55    /// Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
56    #[serde(rename = "parallel_tool_calls", skip_serializing_if = "Option::is_none")]
57    pub parallel_tool_calls: Option<bool>,
58    #[serde(rename = "prompt_mode", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
59    pub prompt_mode: Option<Option<models::MistralPromptMode>>,
60    #[serde(rename = "guardrails", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
61    pub guardrails: Option<Option<Vec<models::GuardrailConfig>>>,
62    /// Whether to inject a safety prompt before all conversations.
63    #[serde(rename = "safe_prompt", skip_serializing_if = "Option::is_none")]
64    pub safe_prompt: Option<bool>,
65}
66
67impl ChatCompletionRequest {
68    pub fn new(model: String, messages: Vec<models::MessagesInner>) -> ChatCompletionRequest {
69        ChatCompletionRequest {
70            model,
71            temperature: None,
72            top_p: None,
73            max_tokens: None,
74            stream: None,
75            stop: None,
76            random_seed: None,
77            metadata: None,
78            messages,
79            response_format: None,
80            tools: None,
81            tool_choice: None,
82            presence_penalty: None,
83            frequency_penalty: None,
84            n: None,
85            prediction: None,
86            parallel_tool_calls: None,
87            prompt_mode: None,
88            guardrails: None,
89            safe_prompt: None,
90        }
91    }
92}
93