From da5bb8e43d31f63a6be849b9044624232771cc35 Mon Sep 17 00:00:00 2001 From: imeepos Date: Mon, 14 Jul 2025 13:33:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=A4=9A=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=E9=85=8D=E7=BD=AE=E7=9A=84Cloudflare=20Gateway=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多区域支持: - 将region改为regions字符串数组 - 支持多个区域: us-central1, us-east1, europe-west1 - 使用第一个区域作为默认区域 - 添加区域选择的详细日志 Cloudflare Gateway URL格式: - 完整的URL构建逻辑 - 格式: https://gateway.ai.cloudflare.com/v1/{project_id}/{gateway_id}/google-vertex-ai/v1/projects/{google_project_id}/locations/{region}/publishers/google/models - 支持动态区域切换 配置参数: - cloudflare_project_id: 67720b647ff2b55cf37ba3ef9e677083 - cloudflare_gateway_id: bowong-dev - google_project_id: gen-lang-client-0413414134 - regions: [us-central1, us-east1, europe-west1] 日志增强: - 显示构建的完整Gateway URL - 显示当前使用的区域 - 显示所有可用区域列表 现在支持标准的Cloudflare Gateway多区域配置。 --- .../src/infrastructure/gemini_service.rs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) 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, } }