feat(clients): optimize: evaluation, simulation, observability and optimizer on a discovery-checked call table

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 04:40:55 +02:00
co-authored by Claude Sonnet 5.5
parent 6d744a433f
commit 1e2fb400bb
55 changed files with 5099 additions and 3 deletions
+47
View File
@@ -0,0 +1,47 @@
#include "google/optimize/direct_model.h"
#include "google/credentials.h"
#include "google/endpoints.h"
#include "google/errors.h"
#include "google/generative.h"
#include "google/resource.h"
#include "google/voice_backend.h"
namespace molo::google::optimize {
DirectModel::DirectModel(std::shared_ptr<GoogleClient> client, std::string model,
ServiceEndpoint endpoint)
: Service(std::move(client), std::move(endpoint)),
model_(std::move(model)) {}
std::shared_ptr<DirectModel> DirectModel::from_env(std::shared_ptr<GoogleClient> client,
std::string model) {
// OAuth tokens need the project-scoped Vertex path (express paths refuse them).
CloudContext ctx = CloudContext::from_env();
if (!Credentials::env("GOOGLE_ACCESS_TOKEN").empty() && ctx.valid()) {
auto m = std::make_shared<DirectModel>(std::move(client), std::move(model),
endpoints::aiplatform("global"));
m->path_prefix_ = "/projects/" + ctx.project + "/locations/global/publishers/google/models/";
return m;
}
ServiceEndpoint ep = voice_backend_from_env() == VoiceBackend::kVertex
? endpoints::vertex_generative()
: endpoints::generative();
return std::make_shared<DirectModel>(std::move(client), std::move(model), std::move(ep));
}
GenerateResponse DirectModel::generate(const GenerateRequest& request) {
std::string model = !request.model.empty() ? request.model
: !model_.empty() ? model_
: Generative::default_model();
if (!valid_segment(model)) throw GoogleError::invalid("bad model name");
return GenerateResponse::from_json(
call(path_prefix_ + model + ":generateContent", request.to_json()));
}
void DirectModel::stream(const GenerateRequest& request,
const std::function<bool(const GenerateResponse&)>& on_chunk) {
on_chunk(generate(request));
}
} // namespace molo::google::optimize