diff --git a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs index 38ef6c2..eeafb03 100644 --- a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs +++ b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs @@ -17,6 +17,10 @@ pub struct GeminiConfig { pub retry_delay: u64, pub temperature: f32, pub max_tokens: u32, + pub cloudflare_project_id: String, + pub cloudflare_gateway_id: String, + pub google_project_id: String, + pub regions: Vec, } impl Default for GeminiConfig { @@ -30,6 +34,14 @@ impl Default for GeminiConfig { retry_delay: 2, temperature: 0.1, max_tokens: 2048, + cloudflare_project_id: "67720b647ff2b55cf37ba3ef9e677083".to_string(), + cloudflare_gateway_id: "bowong-dev".to_string(), + google_project_id: "gen-lang-client-0413414134".to_string(), + regions: vec![ + "us-central1".to_string(), + "us-east1".to_string(), + "europe-west1".to_string(), + ], } } } @@ -208,9 +220,27 @@ impl GeminiService { let mut headers = std::collections::HashMap::new(); headers.insert("Authorization".to_string(), format!("Bearer {}", access_token)); headers.insert("Content-Type".to_string(), "application/json".to_string()); - + + // 使用第一个区域作为默认区域 + let region = self.config.regions.first() + .unwrap_or(&"us-central1".to_string()) + .clone(); + + // 构建Cloudflare Gateway URL + let gateway_url = format!( + "https://gateway.ai.cloudflare.com/v1/{}/{}/google-vertex-ai/v1/projects/{}/locations/{}/publishers/google/models", + self.config.cloudflare_project_id, + self.config.cloudflare_gateway_id, + self.config.google_project_id, + region + ); + + println!("🔗 构建的Cloudflare Gateway URL: {}", gateway_url); + println!("🌍 使用的区域: {}", region); + println!("📋 可用区域: {:?}", self.config.regions); + ClientConfig { - gateway_url: self.config.base_url.clone(), + gateway_url, headers, } }