Skip to content

Commit

Permalink
Add support for base_url for the google-ai provider
Browse files Browse the repository at this point in the history
  • Loading branch information
hellovai committed Jul 3, 2024
1 parent 5cb56fd commit f4b97b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/docs/snippets/clients/providers/gemini.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ The options are passed through directly to the API, barring a few. Here's a shor
`x-goog-api-key: $api_key`
</ParamField>

<ParamField path="base_url" type="string">
The base URL for the API. **Default: `https://generativelanguage.googleapis.com/v1`**
</ParamField>

<ParamField
path="default_role"
type="string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
request::create_client,
};
use anyhow::{Context, Result};
use baml_types::{BamlMedia};
use baml_types::BamlMedia;
use eventsource_stream::Eventsource;
use futures::StreamExt;
use internal_baml_core::ir::ClientWalker;
Expand All @@ -26,6 +26,7 @@ struct PostRequestProperities {
default_role: String,
api_key: Option<String>,
headers: HashMap<String, String>,
base_url: String,
proxy_url: Option<String>,
model_id: Option<String>,
properties: HashMap<String, serde_json::Value>,
Expand Down Expand Up @@ -75,6 +76,11 @@ fn resolve_properties(
.and_then(|v| v.as_str().map(|s| s.to_string()))
.or_else(|| Some("gemini-1.5-flash".to_string()));

let base_url = properties
.remove("base_url")
.and_then(|v| v.as_str().map(|s| s.to_string()))
.unwrap_or_else(|| "https://generativelanguage.googleapis.com/v1".to_string());

let headers = properties.remove("headers").map(|v| {
if let Some(v) = v.as_object() {
v.iter()
Expand Down Expand Up @@ -103,6 +109,7 @@ fn resolve_properties(
api_key,
headers,
properties,
base_url,
model_id,
proxy_url: ctx.env.get("BOUNDARY_PROXY_URL").map(|s| s.to_string()),
})
Expand Down Expand Up @@ -277,7 +284,8 @@ impl RequestBuilder for GoogleClient {
}

let baml_original_url = format!(
"https://generativelanguage.googleapis.com/v1/models/{}:{}",
"{}/models/{}:{}",
self.properties.base_url,
self.properties.model_id.as_ref().unwrap_or(&"".to_string()),
should_stream
);
Expand Down

0 comments on commit f4b97b0

Please sign in to comment.