Skip to content

Commit 7d9e5a9

Browse files
committed
fix(vertexai): make project_id and location optional for API key mode
1 parent b62f945 commit 7d9e5a9

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ providers:
249249
- key: vertexai
250250
type: vertexai
251251
api_key: your-gemini-api-key
252-
project_id: your-project
253-
location: us-central1
254252
255253
# Option 2: Service Account (uses Vertex AI)
256254
providers:

src/providers/vertexai/provider.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,22 @@ impl VertexAIProvider {
103103
#[async_trait]
104104
impl Provider for VertexAIProvider {
105105
fn new(config: &ProviderConfig) -> Self {
106-
let project_id = config
107-
.params
108-
.get("project_id")
109-
.expect("project_id is required for VertexAI provider")
110-
.to_string();
111-
let location_str = config
112-
.params
113-
.get("location")
114-
.expect("location is required for VertexAI provider")
115-
.to_string();
106+
let has_api_key = !config.api_key.is_empty();
116107

117-
let location = Self::validate_location(&location_str)
118-
.expect("Invalid location provided in configuration");
108+
let project_id = config.params.get("project_id").cloned().unwrap_or_default();
109+
let location_str = config.params.get("location").cloned().unwrap_or_default();
110+
111+
// project_id and location only required for service account mode
112+
if !has_api_key && (project_id.is_empty() || location_str.is_empty()) {
113+
panic!("project_id and location are required when no api_key is provided");
114+
}
115+
116+
let location = if location_str.is_empty() {
117+
String::new()
118+
} else {
119+
Self::validate_location(&location_str)
120+
.expect("Invalid location provided in configuration")
121+
};
119122

120123
Self {
121124
config: config.clone(),

0 commit comments

Comments
 (0)