#pragma once // Partner models: Claude on Vertex AI through publishers/anthropic // rawPredict and streamRawPredict. Project scoped only (Discovery has no // express form for the raw predict methods). #include #include #include #include #include "google/models/vertex_service.h" namespace molo::google::models { struct ClaudeMessage { std::string role; // "user" | "assistant" std::string text; }; struct ClaudeRequest { std::string model; // e.g. claude-sonnet-4-6 std::string system; std::vector messages; int max_tokens = 1024; std::optional temperature; int thinking_budget = 0; // 0: off; else >= 1024 and < max_tokens clients::body::Json tools; // Anthropic tools array; null: none clients::body::Json to_json(bool stream) const; }; struct ClaudeResponse { std::string id; std::string model; std::string stop_reason; std::string text; // concatenated text blocks int input_tokens = 0; int output_tokens = 0; clients::body::Json content; // raw content blocks (tool_use included) static ClaudeResponse from_json(const clients::body::Json& doc); }; class ClaudeModels : public VertexService { public: static constexpr const char* kAnthropicVersion = "vertex-2023-10-16"; ClaudeModels(std::shared_ptr client, VertexTarget target); ClaudeResponse generate(const ClaudeRequest& request) const; // Calls sink per Anthropic stream event (message_start, content_block_delta, // ...); return false to stop. void stream(const ClaudeRequest& request, const std::function& sink) const; PlannedCall plan_generate(const ClaudeRequest& request) const; PlannedCall plan_stream(const ClaudeRequest& request) const; // Text of a content_block_delta / text_delta event, else "". static std::string text_delta(const clients::body::Json& event); static void validate(const ClaudeRequest& request); }; } // namespace molo::google::models