Files
moloapp/src/google/generative.h
T

55 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
// Generative Language API (Gemini): models/{model}:generateContent.
#include <string>
#include <vector>
#include "google/endpoints.h"
#include "google/service.h"
#include "google/voice_io.h"
namespace molo::google {
struct ChatMessage {
std::string role; // "user" or "model"
std::string text;
};
struct GenerationRequest {
std::string model; // Empty: GOOGLE_GENAI_MODEL or the built-in default.
std::string system;
std::vector<ChatMessage> messages;
int max_output_tokens = 300;
double temperature = 0.7;
// Reasoning tokens count against max_output_tokens on thinking models and
// can truncate a spoken reply. -1: model default; 0: no thinking.
int thinking_budget = -1;
};
class Generative : public Service {
public:
explicit Generative(std::shared_ptr<GoogleClient> client,
ServiceEndpoint endpoint = endpoints::generative());
static std::string default_model();
static std::string default_stt_model(); // GOOGLE_STT_MODEL, else default_model().
static std::string default_tts_model(); // GOOGLE_TTS_MODEL, else gemini-2.5-flash-tts.
static constexpr const char* kDefaultTtsVoice = "Kore";
std::string generate(const GenerationRequest& request) const;
// Audio in, text out (Gemini audio understanding). Empty string: no speech.
std::string transcribe(const std::string& model, const std::string& audio,
const std::string& mime,
const std::string& language) const;
// Text in, spoken WAV out (Gemini TTS models return raw 24 kHz PCM).
Audio speak(const std::string& model, const std::string& text,
const std::string& voice) const;
private:
clients::body::Json generate_content(const std::string& model,
const clients::body::Json& body) const;
};
} // namespace molo::google