use std::collections::HashMap; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct CountTokensRequest { pub contents: Content, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CountTokensResponse { pub total_tokens: i32, } #[derive(Serialize, Deserialize)] pub struct GenerateContentRequest { pub contents: Vec, pub generation_config: Option, pub tools: Option>, } #[derive(Serialize, Deserialize)] pub struct Tools { pub function_declarations: Option>, } #[derive(Debug, Serialize, Deserialize)] pub struct Content { pub role: String, pub parts: Option>, } #[derive(Clone, Debug, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub struct GenerationConfig { pub max_output_tokens: Option, pub temperature: Option, pub top_p: Option, pub top_k: Option, pub stop_sequences: Option>, pub candidate_count: Option, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum Part { Text(String), InlineData { mime_type: String, data: String, }, FileData { mime_type: String, file_uri: String, }, FunctionCall { name: String, args: HashMap, }, } pub type GenerateContentResponse = Vec; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(untagged)] pub enum ResponseStreamChunk { Ok(OkResponse), Error(Error), } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct OkResponse { pub candidates: Vec, pub usage_metadata: Option, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Candidate { pub content: Content, pub citation_metadata: Option, pub safety_ratings: Vec, pub finish_reason: Option, } #[derive(Debug, Serialize, Deserialize)] pub struct SafetyRating { pub category: String, pub probability: String, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Citation { pub start_index: i32, pub end_index: i32, pub uri: Option, } #[derive(Debug, Serialize, Deserialize)] pub struct CitationMetadata { pub citations: Vec, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct UsageMetadata { pub candidates_token_count: Option, pub prompt_token_count: i32, pub total_token_count: i32, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct FunctionDeclaration { pub name: String, pub description: String, pub parameters: FunctionParameters, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct FunctionParameters { pub r#type: String, pub properties: HashMap, pub required: Vec, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct FunctionParametersProperty { pub r#type: String, pub description: String, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Error { pub code: i32, pub message: String, pub status: String, pub details: Vec, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Link { pub description: String, pub url: String, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(tag = "@type")] pub enum ErrorType { #[serde(rename = "type.googleapis.com/google.rpc.ErrorInfo")] ErrorInfo { metadata: ErrorInfoMetadata }, #[serde(rename = "type.googleapis.com/google.rpc.Help")] Help { links: Vec }, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ErrorInfoMetadata { service: String, consumer: String, }