feat(clients): mistral: La Plateforme package, 347-op call table, typed services, ChatModel, demo
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Vendored
+90
@@ -0,0 +1,90 @@
|
||||
#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 <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<Json>& 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<Json> messages;
|
||||
std::optional<double> temperature; // 0..1.5
|
||||
std::optional<double> top_p; // (0,1]
|
||||
std::optional<double> presence_penalty; // -2..2
|
||||
std::optional<double> frequency_penalty; // -2..2
|
||||
std::optional<double> repetition_penalty; // (0,2]
|
||||
std::optional<int> max_tokens; // >= 0
|
||||
std::optional<int> min_tokens; // >= 0
|
||||
std::optional<int> random_seed; // >= 0
|
||||
std::optional<int> top_k; // >= -1
|
||||
std::optional<int> n; // 1..16
|
||||
std::optional<int> top_logprobs;
|
||||
std::optional<bool> logprobs;
|
||||
std::optional<bool> safe_prompt;
|
||||
std::optional<bool> parallel_tool_calls;
|
||||
std::vector<std::string> stop;
|
||||
std::vector<ToolDef> 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
|
||||
Reference in New Issue
Block a user