use crate::requests::Candidate as ReqCandidate;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
pub struct EmbedContentResponse {
pub embedding: Option<Embedding>,
}
#[derive(Debug, Deserialize)]
pub struct BatchEmbedContentsResponse {
pub embeddings: Option<Vec<Embedding>>,
}
#[derive(Debug, Deserialize, Default, Clone)]
pub struct Embedding {
pub values: Vec<f64>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ModelInfo {
pub name: String,
pub version: String,
#[serde(rename = "displayName")]
pub display_name: String,
pub description: Option<String>,
#[serde(rename = "inputTokenLimit")]
pub input_token_limit: i32,
#[serde(rename = "outputTokenLimit")]
pub output_token_limit: i32,
#[serde(rename = "supportedGenerationMethods")]
pub supported_generation_methods: Vec<String>,
pub temperature: Option<f32>,
#[serde(rename = "maxTemperature")]
pub max_temperature: Option<f32>,
#[serde(rename = "topP")]
pub top_p: Option<f32>,
#[serde(rename = "topK")]
pub top_k: Option<i32>,
}
impl ModelInfo {
pub fn print(&self) {
println!(
r#"
Model:
Name: {}
Version: {}
Display Name: {}
Description: {}
Input Token Limit: {}
Output Token Limit: {}
Supported Generation Methods: {:?}
Temperature: {:?}
Max Temperature: {:?}
Top P: {:?}
Top K: {:?}
"#,
self.name.replace("models/", ""),
self.version,
self.display_name,
self.description
.clone()
.unwrap_or_else(|| "N/A".to_string()),
self.input_token_limit,
self.output_token_limit,
self.supported_generation_methods,
self.temperature,
self.max_temperature,
self.top_p,
self.top_k
);
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ModelsResponse {
pub models: Vec<ModelInfo>,
}
impl ModelsResponse {
pub fn print(&self) {
for model in &self.models {
model.print();
}
}
}
#[derive(Debug, Deserialize)]
pub struct GeminiResponse {
pub candidates: Option<Vec<ReqCandidate>>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ImagenResponse {
pub candidates: Option<Vec<Candidate>>,
pub usage_metadata: Option<UsageMetadata>,
pub model_version: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TtsCandidate {
pub content: Content,
pub finish_reason: Option<String>,
pub index: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Content {
pub parts: Vec<Part>,
pub role: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum Part {
Text {
text: String,
},
Image {
#[serde(rename = "inlineData")]
inline_data: ImageContent,
},
Media {
#[serde(rename = "inlineData")]
inline_data: InlineData,
},
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ImageContent {
pub mime_type: String,
pub data: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UsageMetadata {
pub prompt_token_count: Option<i32>,
pub total_token_count: Option<i32>,
pub prompt_tokens_details: Option<Vec<PromptTokenDetail>>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PromptTokenDetail {
pub modality: Option<String>,
pub token_count: Option<i32>,
}
#[derive(Debug, Deserialize)]
pub struct VideoGenResponse {
pub name: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct OperationStatus {
pub done: Option<bool>,
pub error: Option<OperationError>,
pub response: Option<OperationResponse>,
}
#[derive(Debug, Deserialize)]
pub struct OperationError {
pub message: String,
}
#[derive(Debug, Deserialize)]
pub struct OperationResponse {
pub output: VideoOutput,
}
#[derive(Debug, Deserialize)]
pub struct VideoOutput {
pub video: EncodedVideo,
}
#[derive(Debug, Deserialize)]
pub struct EncodedVideo {
#[serde(rename = "mimeType")]
pub mime_type: String,
#[serde(rename = "base64Data")]
pub base64_data: String,
}
#[derive(Debug, Deserialize)]
pub struct ErrorWrapper {
pub error: ErrorMessage,
}
#[derive(Debug, Deserialize)]
pub struct ErrorMessage {
pub message: String,
}
#[derive(Debug, Deserialize)]
pub struct TtsResponse {
pub candidates: Option<Vec<Candidate>>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Candidate {
pub content: Content,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct InlineData {
pub mime_type: String,
pub data: String,
}