#pragma once // Request side of chat completions (POST /v1/chat/completions) and agents // completions (POST /v1/agents/completions). One ChatParams serves both: with // agent_id set it targets the agents endpoint, which does not take model, // temperature, top_p or safe_prompt (validate() rejects them loudly instead of // dropping them). Field names are the OpenAPI ChatCompletionRequest / // AgentsCompletionRequest properties; tests prove every emitted key is a // column of the call table. #include #include #include #include "vendors/mistral/types.h" namespace molo::mistral { struct ToolDef { std::string name; std::string description; Json parameters = Json::object(); // JSON Schema bool strict = false; Json to_json() const; }; enum class ResponseFormat { kDefault, kText, kJsonObject, kJsonSchema }; // Message and content-chunk builders (OpenAPI SystemMessage, UserMessage, // AssistantMessage, ToolMessage and the ContentChunk variants). struct Messages { static Json system(const std::string& text); static Json user(const std::string& text); static Json user_chunks(const std::vector& chunks); static Json assistant(const std::string& text); // tool calls as returned by the model: [{id,type:function,function:{name,arguments}}] static Json assistant_calls(const std::string& text, const Json& tool_calls); // prefix:true makes the model continue this assistant text. static Json assistant_prefix(const std::string& text); static Json tool(const std::string& call_id, const std::string& name, const std::string& content); static Json text_chunk(const std::string& text); static Json image_chunk(const std::string& url); static Json document_chunk(const std::string& url, const std::string& name = ""); static Json file_chunk(const std::string& file_id); }; struct ChatParams { static constexpr const char* kDefaultModel = "mistral-small-latest"; std::string model = kDefaultModel; std::string agent_id; // set: agents completions std::vector messages; std::optional temperature; // 0..1.5 std::optional top_p; // (0,1] std::optional presence_penalty; // -2..2 std::optional frequency_penalty; // -2..2 std::optional repetition_penalty; // (0,2] std::optional max_tokens; // >= 0 std::optional min_tokens; // >= 0 std::optional random_seed; // >= 0 std::optional top_k; // >= -1 std::optional n; // 1..16 std::optional top_logprobs; std::optional logprobs; std::optional safe_prompt; std::optional parallel_tool_calls; std::vector stop; std::vector tools; std::string tool_choice; // "", auto, none, any, required, or a function name ResponseFormat format = ResponseFormat::kDefault; std::string schema_name; // kJsonSchema Json schema = Json::object(); bool schema_strict = false; std::string reasoning_effort; // "", none, minimal, low, medium, high, xhigh std::string prompt_mode; // "", reasoning std::string prompt_cache_key; std::string service_tier; // "", auto, standard_only std::string prediction; // predicted output text Json metadata; // null or object Json guardrails; // null or array (passed through) Json extra; // null or object merged last (new fields) static ChatParams prompt(const std::string& text); ChatParams& add(Json message); bool for_agent() const { return !agent_id.empty(); } void validate() const; Json to_json(bool stream = false) const; }; } // namespace molo::mistral