vtcode_core/gemini/models/
mod.rs

1pub mod request;
2pub mod response;
3
4pub use request::GenerateContentRequest;
5pub use response::{Candidate, GenerateContentResponse};
6
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Content {
12    pub role: String,
13    pub parts: Vec<Part>,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct SystemInstruction {
18    pub parts: Vec<Part>,
19}
20
21impl Content {
22    pub fn user_text(text: impl Into<String>) -> Self {
23        Content {
24            role: "user".into(),
25            parts: vec![Part::Text { text: text.into() }],
26        }
27    }
28
29    pub fn system_text(text: impl Into<String>) -> Self {
30        // This creates a Content for backwards compatibility
31        // For systemInstruction field, use SystemInstruction::new() instead
32        Content {
33            role: "user".into(), // Convert system to user to avoid API error
34            parts: vec![Part::Text {
35                text: format!("System: {}", text.into()),
36            }],
37        }
38    }
39
40    pub fn user_parts(parts: Vec<Part>) -> Self {
41        Content {
42            role: "user".into(),
43            parts,
44        }
45    }
46}
47
48impl SystemInstruction {
49    pub fn new(text: impl Into<String>) -> Self {
50        SystemInstruction {
51            parts: vec![Part::Text { text: text.into() }],
52        }
53    }
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum Part {
59    Text {
60        text: String,
61    },
62    #[serde(rename_all = "camelCase")]
63    FunctionCall {
64        function_call: crate::gemini::function_calling::FunctionCall,
65    },
66    #[serde(rename_all = "camelCase")]
67    FunctionResponse {
68        function_response: crate::gemini::function_calling::FunctionResponse,
69    },
70}
71
72impl Part {
73    /// Get the text content if this is a Text part
74    pub fn as_text(&self) -> Option<&str> {
75        match self {
76            Part::Text { text } => Some(text),
77            _ => None,
78        }
79    }
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct Tool {
84    #[serde(rename = "functionDeclarations")]
85    pub function_declarations: Vec<FunctionDeclaration>,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct FunctionDeclaration {
90    pub name: String,
91    pub description: String,
92    pub parameters: Value,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
96pub struct ToolConfig {
97    #[serde(rename = "functionCallingConfig")]
98    pub function_calling_config: crate::gemini::function_calling::FunctionCallingConfig,
99}
100
101impl ToolConfig {
102    pub fn auto() -> Self {
103        Self {
104            function_calling_config: crate::gemini::function_calling::FunctionCallingConfig::auto(),
105        }
106    }
107}