-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability for certain models to disable streaming. (#1157)
openai/o1-* models by default don't support streaming */* by default do support streaming users can add the `supports_streaming <bool>` as an option to their client to manually configure this ✅ Raw Curl works ✅ Shorthand clients work well for `o1-*` models without any twiddling ✅ Docs updated <img width="620" alt="Screenshot 2024-11-11 at 11 46 39 AM" src="https://github.com/user-attachments/assets/7d1fdd7d-a8ce-4049-87a9-8ef6a19cf759"> <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Add `supports_streaming` option to configure streaming for models, defaulting `openai/o1-*` to non-streaming, with documentation updates. > > - **Behavior**: > - Adds `supports_streaming` option to client configuration to manually enable/disable streaming. > - `openai/o1-*` models default to non-streaming; other models default to streaming. > - Updates `supports_streaming()` in `WithClientProperties` to reflect new behavior. > - **Code Changes**: > - Modifies `resolve_properties()` in `anthropic_client.rs`, `aws_client.rs`, `googleai_client.rs`, `openai_client.rs`, and `vertex_client.rs` to handle `SupportedRequestModes`. > - Adds `SupportedRequestModes` struct in `llm_client/mod.rs`. > - Updates `WithStreamable` trait to handle non-streaming fallback. > - **Documentation**: > - Updates various `.mdx` files to document `supports_streaming` option. > - Adds new snippets `supports-streaming.mdx` and `supports-streaming-openai.mdx`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 4e8efd1. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information
Showing
34 changed files
with
390 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
engine/baml-runtime/src/internal/llm_client/primitive/anthropic/properties/anthropic.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::collections::HashMap; | ||
use anyhow::Result; | ||
use crate::{ | ||
internal::llm_client::{properties_hander::PropertiesHandler, SharedProperties}, | ||
RuntimeContext, | ||
}; | ||
use super::PostRequestProperties; | ||
|
||
pub fn resolve_properties( | ||
mut properties: PropertiesHandler, | ||
ctx: &RuntimeContext, | ||
) -> Result<PostRequestProperties> { | ||
let shared = properties.pull_shared_properties("system"); | ||
|
||
// Override defaults in shared | ||
let shared = SharedProperties { | ||
base_url: shared.base_url | ||
.map(|url| url.unwrap_or_else(|| "https://api.anthropic.com".into())), | ||
api_key: shared.api_key | ||
.map(|key| key.or_else(|| ctx.env.get("ANTHROPIC_API_KEY").map(|s| s.to_string()))), | ||
headers: shared.headers.map(|mut h| { | ||
h.entry("anthropic-version".to_string()) | ||
.or_insert("2023-06-01".to_string()); | ||
h | ||
}), | ||
..shared | ||
}; | ||
|
||
let mut properties = properties.finalize(); | ||
properties.entry("max_tokens".into()) | ||
.or_insert_with(|| 4096.into()); | ||
|
||
Ok(PostRequestProperties { | ||
shared, | ||
proxy_url: ctx.env.get("BOUNDARY_PROXY_URL").map(|s| s.to_string()), | ||
}) | ||
} |
6 changes: 6 additions & 0 deletions
6
engine/baml-runtime/src/internal/llm_client/primitive/anthropic/properties/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use crate::internal::llm_client::properties_hander::SharedProperties; | ||
|
||
pub struct PostRequestProperties { | ||
pub shared: SharedProperties, | ||
pub proxy_url: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
engine/baml-runtime/src/internal/llm_client/primitive/google/properties/google.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::collections::HashMap; | ||
use anyhow::Result; | ||
use crate::{ | ||
internal::llm_client::{properties_hander::PropertiesHandler, SharedProperties}, | ||
RuntimeContext, | ||
}; | ||
use super::PostRequestProperties; | ||
|
||
pub fn resolve_properties( | ||
mut properties: PropertiesHandler, | ||
ctx: &RuntimeContext, | ||
) -> Result<PostRequestProperties> { | ||
let shared = properties.pull_shared_properties("user"); | ||
|
||
// Override defaults in shared | ||
let shared = SharedProperties { | ||
base_url: shared.base_url | ||
.map(|url| url.unwrap_or_else(|| "https://generativelanguage.googleapis.com/v1beta".to_string())), | ||
api_key: shared.api_key | ||
.map(|key| key.or_else(|| ctx.env.get("GOOGLE_API_KEY").map(|s| s.to_string()))), | ||
..shared | ||
}; | ||
|
||
let model_id = properties.remove_str("model")? | ||
.unwrap_or_else(|| "gemini-1.5-flash".to_string()); | ||
|
||
Ok(PostRequestProperties { | ||
shared, | ||
proxy_url: ctx.env.get("BOUNDARY_PROXY_URL").map(|s| s.to_string()), | ||
model_id: Some(model_id), | ||
}) | ||
} |
7 changes: 7 additions & 0 deletions
7
engine/baml-runtime/src/internal/llm_client/primitive/google/properties/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crate::internal::llm_client::properties_hander::SharedProperties; | ||
|
||
pub struct PostRequestProperties { | ||
pub shared: SharedProperties, | ||
pub proxy_url: Option<String>, | ||
pub model_id: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.