Skip to main content

vtcode_llm/providers/
gemini.rs

1#![allow(
2    clippy::collapsible_if,
3    reason = "Intentional compatibility, platform, or test-only suppression."
4)]
5
6use self::wire::function_calling::FunctionCall as GeminiFunctionCall;
7use self::wire::{
8    Candidate, Content, FunctionDeclaration, GenerateContentRequest, GenerateContentResponse, Interaction,
9    InteractionContent, InteractionInput, InteractionOutput, InteractionRequest, InteractionResult, InteractionTool,
10    InteractionToolChoice, InteractionTurn, InteractionTurnContent, Part, StreamingCandidate, StreamingConfig,
11    StreamingError, StreamingProcessor, StreamingResponse, SystemInstruction, Tool, ToolConfig,
12};
13use self::wire::{FunctionCallingConfig, FunctionResponse};
14use crate::client::LLMClient;
15use crate::error_display;
16use crate::provider::{
17    FinishReason, FunctionCall, LLMError, LLMNormalizedStream, LLMProvider, LLMRequest, LLMResponse, LLMStream,
18    LLMStreamEvent, Message, MessageRole, NormalizedStreamEvent, ReasoningSource, ToolCall, ToolChoice,
19};
20use async_stream::try_stream;
21use async_trait::async_trait;
22use futures::StreamExt;
23use hashbrown::HashMap;
24use reqwest::Client as HttpClient;
25use serde_json::{Map, Value, json};
26use std::sync::Arc;
27use tokio::sync::mpsc;
28use tracing;
29use vtcode_config::TimeoutsConfig;
30use vtcode_config::constants::{env_vars, models, urls};
31use vtcode_config::core::{AnthropicConfig, GeminiPromptCacheMode, GeminiPromptCacheSettings, PromptCachingConfig};
32use vtcode_config::types::ReasoningEffortLevel;
33
34use super::common::{extract_prompt_cache_settings, override_base_url, resolve_model};
35use super::error_handling::{format_network_error, format_parse_error, is_rate_limit_error};
36
37mod client;
38mod explicit_cache;
39pub(crate) mod helpers;
40mod llm_provider;
41mod provider;
42mod sanitize;
43#[cfg(test)]
44mod tests;
45pub mod wire;
46
47pub use provider::GeminiProvider;
48pub(crate) use sanitize::sanitize_function_parameters;