2026-10-25 09:14:26 +01:00
|
|
|
#include "../AiDemos.hpp"
|
|
|
|
|
|
2026-10-25 15:08:12 +01:00
|
|
|
#include <functional>
|
|
|
|
|
|
2026-10-25 09:14:26 +01:00
|
|
|
#include "../../fw/Router.hpp"
|
2026-10-25 15:08:12 +01:00
|
|
|
#include "../../fw/Templates.hpp"
|
|
|
|
|
#include "security/crypto/Base64.h"
|
|
|
|
|
#include "vendors/mistral/agents.h"
|
|
|
|
|
#include "vendors/mistral/audio.h"
|
|
|
|
|
#include "vendors/mistral/batch.h"
|
|
|
|
|
#include "vendors/mistral/calls.h"
|
|
|
|
|
#include "vendors/mistral/caps.h"
|
|
|
|
|
#include "vendors/mistral/chat.h"
|
|
|
|
|
#include "vendors/mistral/classifiers.h"
|
|
|
|
|
#include "vendors/mistral/conversations.h"
|
|
|
|
|
#include "vendors/mistral/embeddings.h"
|
|
|
|
|
#include "vendors/mistral/files.h"
|
|
|
|
|
#include "vendors/mistral/finetune.h"
|
|
|
|
|
#include "vendors/mistral/libraries.h"
|
|
|
|
|
#include "vendors/mistral/models.h"
|
|
|
|
|
#include "vendors/mistral/moderation.h"
|
|
|
|
|
#include "vendors/mistral/ocr.h"
|
|
|
|
|
#include "vendors/mistral/operations.h"
|
|
|
|
|
#include "vendors/mistral/platform.h"
|
2026-10-25 09:14:26 +01:00
|
|
|
|
|
|
|
|
namespace molo::example::app {
|
|
|
|
|
|
2026-10-25 15:08:12 +01:00
|
|
|
// Mistral La Plateforme over the real src/vendors/mistral part. GET routes need
|
|
|
|
|
// no credential. Every route that calls Mistral is a POST: 422 on bad input,
|
|
|
|
|
// 503 mistral_not_configured without MISTRAL_API_KEY. Routes that cost money
|
|
|
|
|
// (completions, embeddings, OCR, transcription, batch, fine-tuning,
|
|
|
|
|
// conversations) or change resources (upload, create, cancel, delete) are dry
|
|
|
|
|
// runs that show the exact request unless the body has "confirm":true.
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
namespace mi = mistral;
|
|
|
|
|
using Json = clients::body::Json;
|
|
|
|
|
|
|
|
|
|
constexpr std::size_t kMaxBody = 24 * 1024 * 1024; // uploads travel as base64
|
|
|
|
|
constexpr std::size_t kMaxOutput = 256 * 1024; // bytes of JSON returned to the browser
|
|
|
|
|
|
|
|
|
|
const char kPage[] = R"MISTRAL({% extends "base.html" %}
|
|
|
|
|
{% block content %}
|
|
|
|
|
<h1>Mistral La Plateforme</h1>
|
|
|
|
|
<p class="hint">Chat, streaming, FIM, agents, conversations, embeddings, moderation, classifiers,
|
|
|
|
|
OCR, transcription, files, batch, fine-tuning, libraries, models and any other operation of the
|
|
|
|
|
OpenAPI document. Paid and destructive calls are dry runs until the body says
|
|
|
|
|
<code>"confirm":true</code>.</p>
|
|
|
|
|
<p id="mi-config" class="hint">Checking credential...</p>
|
|
|
|
|
<section class="mi">
|
|
|
|
|
<label>Route
|
|
|
|
|
<select id="mi-route"></select></label>
|
|
|
|
|
<label>Body (JSON object) <textarea id="mi-body" rows="8"></textarea></label>
|
|
|
|
|
<div class="mi-actions">
|
|
|
|
|
<button id="mi-send" type="button" class="primary">Send</button>
|
|
|
|
|
<button id="mi-confirm" type="button">Send with confirm</button>
|
|
|
|
|
</div>
|
|
|
|
|
<p id="mi-error" class="error" role="alert"></p>
|
|
|
|
|
<pre id="mi-out" class="mi-out"></pre>
|
|
|
|
|
</section>
|
|
|
|
|
<style>
|
|
|
|
|
.mi label{display:block;margin:.5rem 0}
|
|
|
|
|
.mi select,.mi textarea{width:100%;box-sizing:border-box}
|
|
|
|
|
.mi-actions{display:flex;flex-wrap:wrap;gap:.5rem;margin:.5rem 0}
|
|
|
|
|
.mi-out{overflow:auto;max-height:24rem;white-space:pre-wrap;word-break:break-word}
|
|
|
|
|
</style>
|
|
|
|
|
<script src="/embedded/ai_mistral.js"></script>
|
|
|
|
|
{% endblock %}
|
|
|
|
|
)MISTRAL";
|
|
|
|
|
|
|
|
|
|
[[noreturn]] void bad(const std::string& why) { throw fw::HttpError(422, "validation_error", why); }
|
|
|
|
|
|
|
|
|
|
// Keeps what goes back to the browser bounded.
|
|
|
|
|
Json bounded(const Json& j) {
|
|
|
|
|
std::string text = j.dump();
|
|
|
|
|
if (text.size() <= kMaxOutput) return j;
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("truncated", Json(true));
|
|
|
|
|
o.set("bytes", Json(static_cast<int>(text.size())));
|
|
|
|
|
o.set("preview", Json(text.substr(0, 4096)));
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fw::Response json_out(const Json& j, int status = 200) {
|
|
|
|
|
fw::Response res = fw::JsonResponse(bounded(j).dump(), status);
|
|
|
|
|
res.headers.set("Cache-Control", "no-store");
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Json parse_body(const fw::Request& req) {
|
|
|
|
|
if (req.body.size() > kMaxBody) throw fw::HttpError(413, "payload_too_large", "body too large");
|
|
|
|
|
if (req.body.empty()) return Json::object();
|
|
|
|
|
try {
|
|
|
|
|
Json j = Json::parse(req.body);
|
|
|
|
|
if (!j.is_object()) bad("body must be a JSON object");
|
|
|
|
|
return j;
|
|
|
|
|
} catch (const clients::body::JsonError&) {
|
|
|
|
|
bad("body is not valid JSON");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string text(const Json& b, const char* key, bool required = false) {
|
|
|
|
|
const Json* v = b.find(key);
|
|
|
|
|
if (!v || v->is_null()) {
|
|
|
|
|
if (required) bad(std::string(key) + " is required");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
if (!v->is_string()) bad(std::string(key) + " must be a string");
|
|
|
|
|
return v->as_string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<int> number(const Json& b, const char* key) {
|
|
|
|
|
const Json* v = b.find(key);
|
|
|
|
|
if (!v || v->is_null()) return std::nullopt;
|
|
|
|
|
if (!v->is_number()) bad(std::string(key) + " must be a number");
|
|
|
|
|
return static_cast<int>(v->as_int());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<double> real(const Json& b, const char* key) {
|
|
|
|
|
const Json* v = b.find(key);
|
|
|
|
|
if (!v || v->is_null()) return std::nullopt;
|
|
|
|
|
if (!v->is_number()) bad(std::string(key) + " must be a number");
|
|
|
|
|
return v->as_number();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool flag(const Json& b, const char* key) {
|
|
|
|
|
const Json* v = b.find(key);
|
|
|
|
|
if (!v || v->is_null()) return false;
|
|
|
|
|
if (!v->is_bool()) bad(std::string(key) + " must be true or false");
|
|
|
|
|
return v->as_bool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> strings(const Json& b, const char* key) {
|
|
|
|
|
std::vector<std::string> out;
|
|
|
|
|
const Json* v = b.find(key);
|
|
|
|
|
if (!v || v->is_null()) return out;
|
|
|
|
|
if (!v->is_array()) bad(std::string(key) + " must be an array of strings");
|
|
|
|
|
for (const Json& s : v->as_array()) {
|
|
|
|
|
if (!s.is_string()) bad(std::string(key) + " must be an array of strings");
|
|
|
|
|
out.push_back(s.as_string());
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string decode64(const Json& b, const char* key) {
|
|
|
|
|
std::string out;
|
|
|
|
|
if (!security::crypto::Base64::decode(text(b, key, true), out)) bad(std::string(key) + " is not valid base64");
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Json usage_json(const mi::TokenUsage& u) {
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("prompt_tokens", Json(u.prompt_tokens));
|
|
|
|
|
o.set("completion_tokens", Json(u.completion_tokens));
|
|
|
|
|
o.set("total_tokens", Json(u.total_tokens));
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Json chat_json(const mi::ChatResult& r) {
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("id", Json(r.id));
|
|
|
|
|
o.set("model", Json(r.model));
|
|
|
|
|
if (!r.choices.empty()) {
|
|
|
|
|
const mi::ChatChoice& c = r.first();
|
|
|
|
|
o.set("finish_reason", Json(c.finish_reason));
|
|
|
|
|
o.set("content", Json(c.content));
|
|
|
|
|
o.set("reasoning", Json(c.reasoning));
|
|
|
|
|
Json calls = Json::array();
|
|
|
|
|
for (const mi::ToolCallRecord& t : c.tool_calls) {
|
|
|
|
|
Json x = Json::object();
|
|
|
|
|
x.set("id", Json(t.id));
|
|
|
|
|
x.set("name", Json(t.name));
|
|
|
|
|
x.set("arguments", Json(t.arguments));
|
|
|
|
|
x.set("arguments_valid", Json(t.arguments_valid()));
|
|
|
|
|
calls.push(x);
|
|
|
|
|
}
|
|
|
|
|
o.set("tool_calls", calls);
|
|
|
|
|
}
|
|
|
|
|
o.set("usage", usage_json(r.usage));
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Json dry_run(const Json& request, const char* path) {
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("dry_run", Json(true));
|
|
|
|
|
o.set("would_send_to", Json(path));
|
|
|
|
|
o.set("request", request);
|
|
|
|
|
o.set("hint", Json("send confirm:true to run it"));
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mi::ChatParams chat_params(const Json& b) {
|
|
|
|
|
mi::ChatParams p;
|
|
|
|
|
std::string model = text(b, "model");
|
|
|
|
|
if (!model.empty()) p.model = model;
|
|
|
|
|
std::string system = text(b, "system");
|
|
|
|
|
if (!system.empty()) p.add(mi::Messages::system(system));
|
|
|
|
|
p.add(mi::Messages::user(text(b, "prompt", true)));
|
|
|
|
|
p.max_tokens = number(b, "max_tokens");
|
|
|
|
|
p.temperature = real(b, "temperature");
|
|
|
|
|
p.top_p = real(b, "top_p");
|
|
|
|
|
p.random_seed = number(b, "random_seed");
|
|
|
|
|
p.stop = strings(b, "stop");
|
|
|
|
|
p.reasoning_effort = text(b, "effort");
|
|
|
|
|
if (flag(b, "json")) p.format = mi::ResponseFormat::kJsonObject;
|
|
|
|
|
if (flag(b, "safe_prompt")) p.safe_prompt = true;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Plan {
|
|
|
|
|
Json request; // what would be sent (shown in a dry run)
|
|
|
|
|
const char* path = ""; // for the dry-run message
|
|
|
|
|
bool needs_confirm = false; // paid or changes a resource
|
|
|
|
|
std::function<Json()> call;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MistralRoutes {
|
|
|
|
|
public:
|
|
|
|
|
explicit MistralRoutes(mi::Platform platform) : p_(std::move(platform)) {}
|
|
|
|
|
const mi::Platform& platform() const { return p_; }
|
|
|
|
|
|
|
|
|
|
using Planner = std::function<Plan(const Json&)>;
|
|
|
|
|
|
|
|
|
|
fw::Response run(const fw::Request& req, const Planner& planner) const {
|
|
|
|
|
Json body = parse_body(req);
|
|
|
|
|
Plan plan;
|
|
|
|
|
try {
|
|
|
|
|
plan = planner(body);
|
|
|
|
|
} catch (const llm::ApiError& e) {
|
|
|
|
|
map(e);
|
|
|
|
|
}
|
|
|
|
|
if (plan.needs_confirm && !flag(body, "confirm")) return json_out(dry_run(plan.request, plan.path));
|
|
|
|
|
try {
|
|
|
|
|
return json_out(plan.call());
|
|
|
|
|
} catch (const llm::ApiError& e) {
|
|
|
|
|
map(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- completions ---------------------------------------------------------
|
|
|
|
|
Plan chat(const Json& b) const {
|
|
|
|
|
mi::ChatParams params = chat_params(b);
|
|
|
|
|
Plan pl{params.to_json(), "/v1/chat/completions", true, nullptr};
|
|
|
|
|
auto api = std::make_shared<mi::Chat>(p_.client);
|
|
|
|
|
pl.call = [api, params] { return chat_json(api->create(params)); };
|
|
|
|
|
return pl;
|
|
|
|
|
}
|
|
|
|
|
Plan stream(const Json& b) const {
|
|
|
|
|
mi::ChatParams params = chat_params(b);
|
|
|
|
|
Plan pl{params.to_json(true), "/v1/chat/completions", true, nullptr};
|
|
|
|
|
auto api = std::make_shared<mi::Chat>(p_.client);
|
|
|
|
|
pl.call = [api, params] {
|
|
|
|
|
std::size_t events = 0;
|
|
|
|
|
mi::ChatResult r = api->stream(params, [&](const mi::StreamDelta&) {
|
|
|
|
|
return ++events < mi::MistralCaps::kMaxStreamEvents;
|
|
|
|
|
});
|
|
|
|
|
Json o = chat_json(r);
|
|
|
|
|
o.set("chunks", Json(static_cast<int>(events)));
|
|
|
|
|
return o;
|
|
|
|
|
};
|
|
|
|
|
return pl;
|
|
|
|
|
}
|
|
|
|
|
Plan agent(const Json& b) const {
|
|
|
|
|
mi::ChatParams params;
|
|
|
|
|
params.agent_id = text(b, "agent_id", true);
|
|
|
|
|
params.add(mi::Messages::user(text(b, "prompt", true)));
|
|
|
|
|
params.max_tokens = number(b, "max_tokens");
|
|
|
|
|
params.random_seed = number(b, "random_seed");
|
|
|
|
|
Plan pl{params.to_json(), "/v1/agents/completions", true, nullptr};
|
|
|
|
|
auto api = std::make_shared<mi::Chat>(p_.client);
|
|
|
|
|
pl.call = [api, params] { return chat_json(api->create(params)); };
|
|
|
|
|
return pl;
|
|
|
|
|
}
|
|
|
|
|
Plan fim(const Json& b) const {
|
|
|
|
|
mi::FimParams params;
|
|
|
|
|
std::string model = text(b, "model");
|
|
|
|
|
if (!model.empty()) params.model = model;
|
|
|
|
|
params.prompt = text(b, "prompt", true);
|
|
|
|
|
params.suffix = text(b, "suffix");
|
|
|
|
|
params.max_tokens = number(b, "max_tokens");
|
|
|
|
|
params.stop = strings(b, "stop");
|
|
|
|
|
params.temperature = real(b, "temperature");
|
|
|
|
|
Plan pl{params.to_json(), "/v1/fim/completions", true, nullptr};
|
|
|
|
|
auto api = std::make_shared<mi::Fim>(p_.client);
|
|
|
|
|
pl.call = [api, params] { return chat_json(api->create(params)); };
|
|
|
|
|
return pl;
|
|
|
|
|
}
|
|
|
|
|
Plan embeddings(const Json& b) const {
|
|
|
|
|
mi::EmbeddingParams params;
|
|
|
|
|
std::string model = text(b, "model");
|
|
|
|
|
if (!model.empty()) params.model = model;
|
|
|
|
|
params.inputs = strings(b, "inputs");
|
|
|
|
|
if (params.inputs.empty() && !text(b, "input").empty()) params.inputs = {text(b, "input")};
|
|
|
|
|
params.output_dimension = number(b, "output_dimension");
|
|
|
|
|
params.output_dtype = text(b, "output_dtype");
|
|
|
|
|
Plan pl{params.to_json(), "/v1/embeddings", true, nullptr};
|
|
|
|
|
auto api = std::make_shared<mi::Embeddings>(p_.client);
|
|
|
|
|
pl.call = [api, params] {
|
|
|
|
|
mi::EmbeddingResult r = api->create(params);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("model", Json(r.model));
|
|
|
|
|
o.set("count", Json(static_cast<int>(r.vectors.size() + r.encoded.size())));
|
|
|
|
|
o.set("dimension", Json(r.vectors.empty() ? 0 : static_cast<int>(r.vectors[0].size())));
|
|
|
|
|
Json first = Json::array();
|
|
|
|
|
if (!r.vectors.empty())
|
|
|
|
|
for (std::size_t i = 0; i < r.vectors[0].size() && i < 8; ++i) first.push(Json(r.vectors[0][i]));
|
|
|
|
|
o.set("first_vector_head", first);
|
|
|
|
|
o.set("usage", usage_json(r.usage));
|
|
|
|
|
return o;
|
|
|
|
|
};
|
|
|
|
|
return pl;
|
|
|
|
|
}
|
|
|
|
|
Plan moderation(const Json& b) const {
|
|
|
|
|
std::vector<std::string> texts = strings(b, "inputs");
|
|
|
|
|
if (texts.empty() && !text(b, "input").empty()) texts = {text(b, "input")};
|
|
|
|
|
if (texts.empty()) bad("input or inputs is required");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("input", Json(texts[0]));
|
|
|
|
|
req.set("count", Json(static_cast<int>(texts.size())));
|
|
|
|
|
auto api = std::make_shared<mi::Moderation>(p_.client);
|
|
|
|
|
return Plan{req, "/v1/moderations", true, [api, texts] {
|
|
|
|
|
mi::ModerationResult r = api->moderate(texts);
|
|
|
|
|
Json arr = Json::array();
|
|
|
|
|
for (const mi::ModerationItem& it : r.results) {
|
|
|
|
|
Json x = Json::object();
|
|
|
|
|
x.set("flagged", Json(it.flagged()));
|
|
|
|
|
Json cats = Json::array();
|
|
|
|
|
for (const std::string& c : it.flagged_categories()) cats.push(Json(c));
|
|
|
|
|
x.set("categories", cats);
|
|
|
|
|
arr.push(x);
|
|
|
|
|
}
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("model", Json(r.model));
|
|
|
|
|
o.set("results", arr);
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
Plan classify(const Json& b) const {
|
|
|
|
|
std::string model = text(b, "model", true);
|
|
|
|
|
std::vector<std::string> texts = strings(b, "inputs");
|
|
|
|
|
if (texts.empty() && !text(b, "input").empty()) texts = {text(b, "input")};
|
|
|
|
|
if (texts.empty()) bad("input or inputs is required");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("model", Json(model));
|
|
|
|
|
req.set("count", Json(static_cast<int>(texts.size())));
|
|
|
|
|
auto api = std::make_shared<mi::Classifiers>(p_.client);
|
|
|
|
|
return Plan{req, "/v1/classifications", true, [api, model, texts] { return api->classify(model, texts).raw; }};
|
|
|
|
|
}
|
|
|
|
|
Plan ocr(const Json& b) const {
|
|
|
|
|
mi::OcrParams params;
|
|
|
|
|
std::string model = text(b, "model");
|
|
|
|
|
if (!model.empty()) params.model = model;
|
|
|
|
|
std::string kind = text(b, "kind");
|
|
|
|
|
if (kind.empty() || kind == "document_url") params.source = mi::OcrSource::kDocumentUrl;
|
|
|
|
|
else if (kind == "image_url") params.source = mi::OcrSource::kImageUrl;
|
|
|
|
|
else if (kind == "file") params.source = mi::OcrSource::kFileId;
|
|
|
|
|
else bad("kind must be document_url, image_url or file");
|
|
|
|
|
params.reference = text(b, "reference", true);
|
|
|
|
|
if (const Json* pg = b.find("pages"); pg && pg->is_array())
|
|
|
|
|
for (const Json& x : pg->as_array()) {
|
|
|
|
|
if (!x.is_number()) bad("pages must be numbers");
|
|
|
|
|
params.pages.push_back(static_cast<int>(x.as_int()));
|
|
|
|
|
}
|
|
|
|
|
params.table_format = text(b, "table_format");
|
|
|
|
|
Plan pl{params.to_json(), "/v1/ocr", true, nullptr};
|
|
|
|
|
auto api = std::make_shared<mi::Ocr>(p_.client);
|
|
|
|
|
pl.call = [api, params] {
|
|
|
|
|
mi::OcrResult r = api->process(params);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("model", Json(r.model));
|
|
|
|
|
o.set("pages_processed", Json(static_cast<int>(r.pages_processed)));
|
|
|
|
|
o.set("markdown", Json(r.markdown()));
|
|
|
|
|
return o;
|
|
|
|
|
};
|
|
|
|
|
return pl;
|
|
|
|
|
}
|
|
|
|
|
Plan transcribe(const Json& b) const {
|
|
|
|
|
mi::TranscriptionParams params;
|
|
|
|
|
std::string model = text(b, "model");
|
|
|
|
|
if (!model.empty()) params.model = model;
|
|
|
|
|
if (b.find("data_base64")) {
|
|
|
|
|
params.file_data = decode64(b, "data_base64");
|
|
|
|
|
params.file_name = text(b, "filename", true);
|
|
|
|
|
}
|
|
|
|
|
params.file_url = text(b, "file_url");
|
|
|
|
|
params.file_id = text(b, "file_id");
|
|
|
|
|
params.language = text(b, "language");
|
|
|
|
|
params.diarize = flag(b, "diarize");
|
|
|
|
|
params.timestamp_granularities = strings(b, "timestamp_granularities");
|
|
|
|
|
params.validate();
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("model", Json(params.model));
|
|
|
|
|
req.set("source", Json(!params.file_data.empty() ? "upload" : !params.file_url.empty() ? "file_url" : "file_id"));
|
|
|
|
|
req.set("bytes", Json(static_cast<int>(params.file_data.size())));
|
|
|
|
|
auto api = std::make_shared<mi::Audio>(p_.client);
|
|
|
|
|
return Plan{req, "/v1/audio/transcriptions", true, [api, params] {
|
|
|
|
|
mi::TranscriptionResult r = api->transcribe(params);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("model", Json(r.model));
|
|
|
|
|
o.set("language", Json(r.language));
|
|
|
|
|
o.set("text", Json(r.text));
|
|
|
|
|
o.set("segments", Json(static_cast<int>(r.segments.size())));
|
|
|
|
|
o.set("usage", usage_json(r.usage));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- resources -----------------------------------------------------------
|
|
|
|
|
Plan models(const Json& b) const {
|
|
|
|
|
auto api = std::make_shared<mi::Models>(p_.client);
|
|
|
|
|
std::string action = text(b, "action");
|
|
|
|
|
if (action == "get" || action == "delete") {
|
|
|
|
|
std::string id = text(b, "id", true);
|
|
|
|
|
if (!llm::Service::valid_id(id)) bad("id has invalid characters");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("id", Json(id));
|
|
|
|
|
if (action == "get") return Plan{req, "/v1/models/{id}", false, [api, id] {
|
|
|
|
|
mi::ModelCard m = api->get(id);
|
|
|
|
|
Json x = Json::object();
|
|
|
|
|
x.set("id", Json(m.id));
|
|
|
|
|
x.set("type", Json(m.type));
|
|
|
|
|
x.set("owned_by", Json(m.owned_by));
|
|
|
|
|
x.set("max_context_length", Json(static_cast<int>(m.max_context_length)));
|
|
|
|
|
x.set("archived", Json(m.archived));
|
|
|
|
|
return x;
|
|
|
|
|
}};
|
|
|
|
|
return Plan{req, "DELETE /v1/models/{id}", true, [api, id] {
|
|
|
|
|
mi::ModelDeleted d = api->remove(id);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("id", Json(d.id));
|
|
|
|
|
o.set("deleted", Json(d.deleted));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
if (!action.empty() && action != "list") bad("action must be list, get or delete");
|
|
|
|
|
return Plan{Json::object(), "/v1/models", false, [api] {
|
|
|
|
|
mi::ModelList l = api->list();
|
|
|
|
|
Json arr = Json::array();
|
|
|
|
|
for (const mi::ModelCard& m : l.models) {
|
|
|
|
|
Json x = Json::object();
|
|
|
|
|
x.set("id", Json(m.id));
|
|
|
|
|
x.set("type", Json(m.type));
|
|
|
|
|
x.set("max_context_length", Json(static_cast<int>(m.max_context_length)));
|
|
|
|
|
x.set("chat", Json(m.capabilities.completion_chat));
|
|
|
|
|
x.set("vision", Json(m.capabilities.vision));
|
|
|
|
|
x.set("fim", Json(m.capabilities.completion_fim));
|
|
|
|
|
x.set("ocr", Json(m.capabilities.ocr));
|
|
|
|
|
arr.push(x);
|
|
|
|
|
}
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("models", arr);
|
|
|
|
|
o.set("truncated", Json(l.truncated));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
Plan files(const Json& b) const {
|
|
|
|
|
std::string action = text(b, "action", true);
|
|
|
|
|
auto api = std::make_shared<mi::Files>(p_.client);
|
|
|
|
|
auto file_json = [](const mi::FileInfo& f) {
|
|
|
|
|
Json x = Json::object();
|
|
|
|
|
x.set("id", Json(f.id));
|
|
|
|
|
x.set("filename", Json(f.filename));
|
|
|
|
|
x.set("purpose", Json(f.purpose));
|
|
|
|
|
x.set("bytes", Json(static_cast<int>(f.bytes)));
|
|
|
|
|
x.set("created_at", Json(static_cast<int>(f.created_at)));
|
|
|
|
|
return x;
|
|
|
|
|
};
|
|
|
|
|
if (action == "list") {
|
|
|
|
|
mi::FileListParams lp;
|
|
|
|
|
if (auto n = number(b, "page_size")) lp.page_size = *n;
|
|
|
|
|
if (auto n = number(b, "page")) lp.page = *n;
|
|
|
|
|
lp.purpose = text(b, "purpose");
|
|
|
|
|
lp.validate();
|
|
|
|
|
return Plan{Json::object(), "/v1/files", false, [api, lp, file_json] {
|
|
|
|
|
mi::FileList l = api->list(lp);
|
|
|
|
|
Json arr = Json::array();
|
|
|
|
|
for (const mi::FileInfo& f : l.files) arr.push(file_json(f));
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("files", arr);
|
|
|
|
|
o.set("total", Json(static_cast<int>(l.total)));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
if (action == "get" || action == "delete") {
|
|
|
|
|
std::string id = text(b, "id", true);
|
|
|
|
|
if (!llm::Service::valid_id(id)) bad("id has invalid characters");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("id", Json(id));
|
|
|
|
|
if (action == "get") return Plan{req, "/v1/files/{id}", false, [api, id, file_json] { return file_json(api->get(id)); }};
|
|
|
|
|
return Plan{req, "DELETE /v1/files/{id}", true, [api, id] {
|
|
|
|
|
mi::FileDeleted d = api->remove(id);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("id", Json(d.id));
|
|
|
|
|
o.set("deleted", Json(d.deleted));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
if (action == "upload") {
|
|
|
|
|
mi::FileUploadParams up;
|
|
|
|
|
up.filename = text(b, "filename", true);
|
|
|
|
|
up.data = decode64(b, "data_base64");
|
|
|
|
|
std::string purpose = text(b, "purpose");
|
|
|
|
|
if (!purpose.empty()) up.purpose = purpose;
|
|
|
|
|
up.validate();
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("filename", Json(up.filename));
|
|
|
|
|
req.set("bytes", Json(static_cast<int>(up.data.size())));
|
|
|
|
|
req.set("purpose", Json(up.purpose));
|
|
|
|
|
return Plan{req, "POST /v1/files", true, [api, up, file_json] { return file_json(api->upload(up)); }};
|
|
|
|
|
}
|
|
|
|
|
bad("action must be list, get, upload or delete");
|
|
|
|
|
}
|
|
|
|
|
Plan batch(const Json& b) const {
|
|
|
|
|
std::string action = text(b, "action", true);
|
|
|
|
|
auto api = std::make_shared<mi::Batch>(p_.client);
|
|
|
|
|
if (action == "list") {
|
|
|
|
|
mi::BatchListParams lp;
|
|
|
|
|
lp.status = text(b, "status");
|
|
|
|
|
lp.validate();
|
|
|
|
|
return Plan{Json::object(), "/v1/batch/jobs", false, [api, lp] { return api->list(lp).raw; }};
|
|
|
|
|
}
|
|
|
|
|
if (action == "create") {
|
|
|
|
|
mi::BatchParams bp;
|
|
|
|
|
bp.endpoint = text(b, "endpoint").empty() ? bp.endpoint : text(b, "endpoint");
|
|
|
|
|
bp.model = text(b, "model");
|
|
|
|
|
bp.agent_id = text(b, "agent_id");
|
|
|
|
|
bp.input_files = strings(b, "input_files");
|
|
|
|
|
if (auto n = number(b, "timeout_hours")) bp.timeout_hours = *n;
|
|
|
|
|
return Plan{bp.to_json(), "POST /v1/batch/jobs", true, [api, bp] { return api->create(bp).raw; }};
|
|
|
|
|
}
|
|
|
|
|
std::string id = text(b, "id", true);
|
|
|
|
|
if (!llm::Service::valid_id(id)) bad("id has invalid characters");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("id", Json(id));
|
|
|
|
|
if (action == "get") return Plan{req, "/v1/batch/jobs/{id}", false, [api, id] { return api->get(id).raw; }};
|
|
|
|
|
if (action == "cancel") return Plan{req, "POST /v1/batch/jobs/{id}/cancel", true, [api, id] { return api->cancel(id).raw; }};
|
|
|
|
|
if (action == "delete") return Plan{req, "DELETE /v1/batch/jobs/{id}", true, [api, id] { return api->remove(id); }};
|
|
|
|
|
bad("action must be list, get, create, cancel or delete");
|
|
|
|
|
}
|
|
|
|
|
Plan finetune(const Json& b) const {
|
|
|
|
|
std::string action = text(b, "action", true);
|
|
|
|
|
auto api = std::make_shared<mi::FineTuning>(p_.client);
|
|
|
|
|
if (action == "list") {
|
|
|
|
|
mi::FineTuneListParams lp;
|
|
|
|
|
lp.status = text(b, "status");
|
|
|
|
|
lp.validate();
|
|
|
|
|
return Plan{Json::object(), "/v1/fine_tuning/jobs", false, [api, lp] { return api->list_jobs(lp).raw; }};
|
|
|
|
|
}
|
|
|
|
|
if (action == "create") {
|
|
|
|
|
mi::FineTuneJobParams jp;
|
|
|
|
|
jp.model = text(b, "model", true);
|
|
|
|
|
for (const std::string& f : strings(b, "training_files")) jp.training_files.push_back({f, 1.0});
|
|
|
|
|
jp.validation_files = strings(b, "validation_files");
|
|
|
|
|
jp.suffix = text(b, "suffix");
|
|
|
|
|
jp.job_type = text(b, "job_type");
|
|
|
|
|
if (const Json* h = b.find("hyperparameters"); h && h->is_object()) jp.hyperparameters = *h;
|
|
|
|
|
jp.auto_start = flag(b, "auto_start");
|
|
|
|
|
jp.dry_run = flag(b, "dry_run");
|
|
|
|
|
return Plan{jp.to_json(), "POST /v1/fine_tuning/jobs", true, [api, jp] { return api->create_job(jp).raw; }};
|
|
|
|
|
}
|
|
|
|
|
std::string id = text(b, "id", true);
|
|
|
|
|
if (!llm::Service::valid_id(id)) bad("id has invalid characters");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("id", Json(id));
|
|
|
|
|
if (action == "get") return Plan{req, "/v1/fine_tuning/jobs/{id}", false, [api, id] { return api->get_job(id).raw; }};
|
|
|
|
|
if (action == "start") return Plan{req, "POST /v1/fine_tuning/jobs/{id}/start", true, [api, id] { return api->start_job(id).raw; }};
|
|
|
|
|
if (action == "cancel") return Plan{req, "POST /v1/fine_tuning/jobs/{id}/cancel", true, [api, id] { return api->cancel_job(id).raw; }};
|
|
|
|
|
bad("action must be list, get, create, start or cancel");
|
|
|
|
|
}
|
|
|
|
|
Plan agents(const Json& b) const {
|
|
|
|
|
std::string action = text(b, "action", true);
|
|
|
|
|
auto api = std::make_shared<mi::Agents>(p_.client);
|
|
|
|
|
if (action == "list") return Plan{Json::object(), "/v1/agents/pages", false, [api] { return api->list().raw; }};
|
|
|
|
|
if (action == "create") {
|
|
|
|
|
mi::AgentParams ap;
|
|
|
|
|
ap.model = text(b, "model", true);
|
|
|
|
|
ap.name = text(b, "name", true);
|
|
|
|
|
ap.instructions = text(b, "instructions");
|
|
|
|
|
ap.description = text(b, "description");
|
|
|
|
|
if (const Json* t = b.find("tools"); t && t->is_array()) ap.tools = *t;
|
|
|
|
|
return Plan{ap.to_json(true), "POST /v1/agents", true, [api, ap] { return api->create(ap).raw; }};
|
|
|
|
|
}
|
|
|
|
|
std::string id = text(b, "id", true);
|
|
|
|
|
if (!llm::Service::valid_id(id)) bad("id has invalid characters");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("id", Json(id));
|
|
|
|
|
if (action == "get") return Plan{req, "/v1/agents/{id}", false, [api, id] { return api->get(id).raw; }};
|
|
|
|
|
if (action == "delete")
|
|
|
|
|
return Plan{req, "DELETE /v1/agents/{id}", true, [api, id] {
|
|
|
|
|
api->remove(id);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("deleted", Json(true));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
bad("action must be list, get, create or delete");
|
|
|
|
|
}
|
|
|
|
|
Plan conversations(const Json& b) const {
|
|
|
|
|
std::string action = text(b, "action", true);
|
|
|
|
|
auto api = std::make_shared<mi::Conversations>(p_.client);
|
|
|
|
|
if (action == "list") return Plan{Json::object(), "/v1/conversations", false, [api] { return api->list().raw; }};
|
|
|
|
|
if (action == "start") {
|
|
|
|
|
mi::ConversationStartParams sp;
|
|
|
|
|
sp.inputs = mi::ConversationInput::text(text(b, "prompt", true));
|
|
|
|
|
sp.model = text(b, "model");
|
|
|
|
|
sp.agent_id = text(b, "agent_id");
|
|
|
|
|
if (sp.model.empty() && sp.agent_id.empty()) sp.model = mi::ChatParams::kDefaultModel;
|
|
|
|
|
if (const Json* t = b.find("tools"); t && t->is_array()) sp.tools = *t;
|
|
|
|
|
return Plan{sp.to_json(false), "POST /v1/conversations", true, [api, sp] {
|
|
|
|
|
mi::ConversationResult r = api->start(sp);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("conversation_id", Json(r.conversation_id));
|
|
|
|
|
o.set("text", Json(r.text()));
|
|
|
|
|
o.set("usage", usage_json(r.usage));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
std::string id = text(b, "id", true);
|
|
|
|
|
if (!llm::Service::valid_id(id)) bad("id has invalid characters");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("id", Json(id));
|
|
|
|
|
if (action == "append") {
|
|
|
|
|
mi::ConversationAppendParams ap;
|
|
|
|
|
ap.inputs = mi::ConversationInput::text(text(b, "prompt", true));
|
|
|
|
|
return Plan{ap.to_json(false), "POST /v1/conversations/{id}", true, [api, id, ap] {
|
|
|
|
|
mi::ConversationResult r = api->append(id, ap);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("text", Json(r.text()));
|
|
|
|
|
o.set("usage", usage_json(r.usage));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
if (action == "get") return Plan{req, "/v1/conversations/{id}", false, [api, id] { return api->get(id); }};
|
|
|
|
|
if (action == "history") return Plan{req, "/v1/conversations/{id}/history", false, [api, id] { return api->history(id); }};
|
|
|
|
|
if (action == "delete")
|
|
|
|
|
return Plan{req, "DELETE /v1/conversations/{id}", true, [api, id] {
|
|
|
|
|
api->remove(id);
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("deleted", Json(true));
|
|
|
|
|
return o;
|
|
|
|
|
}};
|
|
|
|
|
bad("action must be list, start, append, get, history or delete");
|
|
|
|
|
}
|
|
|
|
|
Plan libraries(const Json& b) const {
|
|
|
|
|
std::string action = text(b, "action", true);
|
|
|
|
|
auto api = std::make_shared<mi::Libraries>(p_.client);
|
|
|
|
|
if (action == "list") return Plan{Json::object(), "/v1/libraries", false, [api] { return api->list().raw; }};
|
|
|
|
|
if (action == "create") {
|
|
|
|
|
mi::LibraryCreateParams cp;
|
|
|
|
|
cp.name = text(b, "name", true);
|
|
|
|
|
cp.description = text(b, "description");
|
|
|
|
|
cp.chunk_size = number(b, "chunk_size");
|
|
|
|
|
cp.validate();
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("name", Json(cp.name));
|
|
|
|
|
return Plan{req, "POST /v1/libraries", true, [api, cp] { return api->create(cp).raw; }};
|
|
|
|
|
}
|
|
|
|
|
std::string id = text(b, "id", true);
|
|
|
|
|
if (!llm::Service::valid_id(id)) bad("id has invalid characters");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("id", Json(id));
|
|
|
|
|
if (action == "get") return Plan{req, "/v1/libraries/{id}", false, [api, id] { return api->get(id).raw; }};
|
|
|
|
|
if (action == "documents") return Plan{req, "/v1/libraries/{id}/documents", false, [api, id] { return api->documents(id).raw; }};
|
|
|
|
|
if (action == "delete") return Plan{req, "DELETE /v1/libraries/{id}", true, [api, id] { return api->remove(id).raw; }};
|
|
|
|
|
if (action == "upload") {
|
|
|
|
|
mi::DocumentUploadParams up;
|
|
|
|
|
up.filename = text(b, "filename", true);
|
|
|
|
|
up.data = decode64(b, "data_base64");
|
|
|
|
|
up.validate();
|
|
|
|
|
req.set("filename", Json(up.filename));
|
|
|
|
|
req.set("bytes", Json(static_cast<int>(up.data.size())));
|
|
|
|
|
return Plan{req, "POST /v1/libraries/{id}/documents", true, [api, id, up] { return api->upload_document(id, up).raw; }};
|
|
|
|
|
}
|
|
|
|
|
bad("action must be list, get, create, documents, upload or delete");
|
|
|
|
|
}
|
|
|
|
|
// Any JSON operation of the table: {op, ids[], query{}, body{}}.
|
|
|
|
|
Plan operation(const Json& b) const {
|
|
|
|
|
mi::Invocation inv;
|
|
|
|
|
inv.op = text(b, "op", true);
|
|
|
|
|
inv.ids = strings(b, "ids");
|
|
|
|
|
if (const Json* q = b.find("query"); q && q->is_object())
|
|
|
|
|
for (const auto& [k, v] : q->as_object()) {
|
|
|
|
|
if (!v.is_string() && !v.is_number() && !v.is_bool()) bad("query values must be scalars");
|
|
|
|
|
inv.query[k] = v.is_string() ? v.as_string() : v.dump();
|
|
|
|
|
}
|
|
|
|
|
if (const Json* body = b.find("body"); body && !body->is_null()) inv.body = *body;
|
|
|
|
|
mi::Invocation probe = inv;
|
|
|
|
|
probe.allow_destructive = true; // the dry run gate below decides, not the table check
|
|
|
|
|
const mi::CallSpec& spec = mi::Operations::check(probe);
|
|
|
|
|
bool changes = std::string(spec.http_method) != "GET";
|
|
|
|
|
inv.allow_destructive = flag(b, "confirm");
|
|
|
|
|
Json req = Json::object();
|
|
|
|
|
req.set("op", Json(inv.op));
|
|
|
|
|
req.set("method", Json(spec.http_method));
|
|
|
|
|
req.set("path", Json(mi::Calls::render(spec, inv.ids)));
|
|
|
|
|
if (!inv.body.is_null()) req.set("body", inv.body);
|
|
|
|
|
auto api = std::make_shared<mi::Operations>(p_.client);
|
|
|
|
|
return Plan{req, spec.path, changes, [api, inv] { return api->invoke(inv); }};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
[[noreturn]] static void map(const llm::ApiError& e) {
|
|
|
|
|
if (e.http_status() == 503 && e.type() == "NOT_CONFIGURED")
|
|
|
|
|
throw fw::HttpError(503, "mistral_not_configured", e.message());
|
|
|
|
|
if (e.type() == "INVALID_ARGUMENT" && e.http_status() == 400 && e.request_id().empty())
|
|
|
|
|
throw fw::HttpError(422, "validation_error", e.message());
|
|
|
|
|
throw fw::HttpError(502, "mistral_error", std::to_string(e.http_status()) + " " + e.type() + ": " + e.message());
|
|
|
|
|
}
|
|
|
|
|
mi::Platform p_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2026-10-25 09:14:26 +01:00
|
|
|
void register_ai_mistral_demo(fw::Router& router, Services& services) {
|
2026-10-25 15:08:12 +01:00
|
|
|
auto routes = std::make_shared<MistralRoutes>(mi::Platform::from_env());
|
|
|
|
|
fw::Environment* env = services.templates.get();
|
|
|
|
|
services.templates->add_template("ai_mistral.html", kPage);
|
|
|
|
|
services.add_feature("ai-mistral", "/ai/mistral");
|
|
|
|
|
|
|
|
|
|
router.get("/ai/mistral", "ai-mistral-page", [env](fw::Request req) {
|
|
|
|
|
(void)req;
|
|
|
|
|
fw::TemplateCtx ctx;
|
|
|
|
|
ctx["title"] = std::string("Mistral La Plateforme");
|
|
|
|
|
return fw::Response(200, env->render("ai_mistral.html", ctx), "text/html; charset=utf-8");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get("/ai/mistral/status", "ai-mistral-status", [routes](fw::Request req) {
|
|
|
|
|
(void)req;
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("configured", Json(routes->platform().configured()));
|
|
|
|
|
o.set("credential_env", Json(mi::Platform::kKeyEnv));
|
|
|
|
|
o.set("base_url", Json(mi::Platform::kHost));
|
|
|
|
|
o.set("calls", Json(static_cast<int>(mi::Calls::count())));
|
|
|
|
|
Json areas = Json::array();
|
|
|
|
|
for (const std::string& a : mi::Operations::areas()) areas.push(Json(a));
|
|
|
|
|
o.set("areas", areas);
|
|
|
|
|
o.set("default_chat_model", Json(mi::ChatParams::kDefaultModel));
|
|
|
|
|
o.set("default_fim_model", Json(mi::FimParams::kDefaultModel));
|
|
|
|
|
o.set("default_embedding_model", Json(mi::EmbeddingParams::kDefaultModel));
|
|
|
|
|
o.set("default_ocr_model", Json(mi::OcrParams::kDefaultModel));
|
|
|
|
|
o.set("max_upload_bytes", Json(static_cast<int>(mi::MistralCaps::kMaxUploadBytes / (1024 * 1024))));
|
|
|
|
|
return json_out(o);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get("/ai/mistral/calls", "ai-mistral-calls", [](fw::Request req) {
|
|
|
|
|
std::string area = req.query_or("area", "");
|
|
|
|
|
Json arr = Json::array();
|
|
|
|
|
for (std::size_t i = 0; i < mi::Calls::count(); ++i) {
|
|
|
|
|
const mi::CallSpec& s = mi::Calls::at(i);
|
|
|
|
|
if (!area.empty() && area != s.area) continue;
|
|
|
|
|
Json row = Json::object();
|
|
|
|
|
row.set("op", Json(s.op));
|
|
|
|
|
row.set("http", Json(s.http_method));
|
|
|
|
|
row.set("path", Json(s.path));
|
|
|
|
|
row.set("area", Json(s.area));
|
|
|
|
|
row.set("source", Json(s.source));
|
|
|
|
|
row.set("deprecated", Json(s.deprecated));
|
|
|
|
|
arr.push(row);
|
|
|
|
|
}
|
|
|
|
|
Json o = Json::object();
|
|
|
|
|
o.set("calls", arr);
|
|
|
|
|
return json_out(o);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
using Member = MistralRoutes::Planner;
|
|
|
|
|
auto add = [&](const char* path, const char* name, Member planner) {
|
|
|
|
|
router.post(path, name, [routes, planner](fw::Request req) { return routes->run(req, planner); });
|
|
|
|
|
};
|
|
|
|
|
MistralRoutes* r = routes.get();
|
|
|
|
|
auto bind = [r](Plan (MistralRoutes::*m)(const Json&) const) {
|
|
|
|
|
return Member([r, m](const Json& b) { return (r->*m)(b); });
|
|
|
|
|
};
|
|
|
|
|
add("/ai/mistral/chat", "ai-mistral-chat", bind(&MistralRoutes::chat));
|
|
|
|
|
add("/ai/mistral/stream", "ai-mistral-stream", bind(&MistralRoutes::stream));
|
|
|
|
|
add("/ai/mistral/agent", "ai-mistral-agent", bind(&MistralRoutes::agent));
|
|
|
|
|
add("/ai/mistral/fim", "ai-mistral-fim", bind(&MistralRoutes::fim));
|
|
|
|
|
add("/ai/mistral/embeddings", "ai-mistral-embeddings", bind(&MistralRoutes::embeddings));
|
|
|
|
|
add("/ai/mistral/moderation", "ai-mistral-moderation", bind(&MistralRoutes::moderation));
|
|
|
|
|
add("/ai/mistral/classify", "ai-mistral-classify", bind(&MistralRoutes::classify));
|
|
|
|
|
add("/ai/mistral/ocr", "ai-mistral-ocr", bind(&MistralRoutes::ocr));
|
|
|
|
|
add("/ai/mistral/transcribe", "ai-mistral-transcribe", bind(&MistralRoutes::transcribe));
|
|
|
|
|
add("/ai/mistral/models", "ai-mistral-models", bind(&MistralRoutes::models));
|
|
|
|
|
add("/ai/mistral/files", "ai-mistral-files", bind(&MistralRoutes::files));
|
|
|
|
|
add("/ai/mistral/batch", "ai-mistral-batch", bind(&MistralRoutes::batch));
|
|
|
|
|
add("/ai/mistral/finetune", "ai-mistral-finetune", bind(&MistralRoutes::finetune));
|
|
|
|
|
add("/ai/mistral/agents", "ai-mistral-agents", bind(&MistralRoutes::agents));
|
|
|
|
|
add("/ai/mistral/conversations", "ai-mistral-conversations", bind(&MistralRoutes::conversations));
|
|
|
|
|
add("/ai/mistral/libraries", "ai-mistral-libraries", bind(&MistralRoutes::libraries));
|
|
|
|
|
add("/ai/mistral/operation", "ai-mistral-operation", bind(&MistralRoutes::operation));
|
2026-10-25 09:14:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace molo::example::app
|