-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAML functions now support passing in which model / configuration they use at runtime. * Enables dynamically picking which options they want to run. * Tracing captures dynamic properties * Retry policies must be defined in BAML
- Loading branch information
Showing
51 changed files
with
1,298 additions
and
480 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// This is designed to build any type of client, not just primitives | ||
use anyhow::{Context, Result}; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use baml_types::{BamlMap, BamlValue}; | ||
use serde::Serialize; | ||
|
||
use crate::{internal::llm_client::llm_provider::LLMProvider, RuntimeContext}; | ||
|
||
#[derive(Clone)] | ||
pub enum PrimitiveClient { | ||
OpenAI, | ||
Anthropic, | ||
Google, | ||
} | ||
|
||
#[derive(Serialize, Clone)] | ||
pub struct ClientProperty { | ||
pub name: String, | ||
pub provider: String, | ||
pub retry_policy: Option<String>, | ||
pub options: BamlMap<String, BamlValue>, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct ClientBuilder { | ||
clients: HashMap<String, ClientProperty>, | ||
primary: Option<String>, | ||
} | ||
|
||
impl ClientBuilder { | ||
pub fn new() -> Self { | ||
Self { | ||
clients: Default::default(), | ||
primary: None, | ||
} | ||
} | ||
|
||
pub fn add_client(&mut self, client: ClientProperty) { | ||
self.clients.insert(client.name.clone(), client); | ||
} | ||
|
||
pub fn set_primary(&mut self, primary: String) { | ||
self.primary = Some(primary); | ||
} | ||
|
||
pub fn to_clients( | ||
&self, | ||
ctx: &RuntimeContext, | ||
) -> Result<(Option<String>, HashMap<String, Arc<LLMProvider>>)> { | ||
let mut clients = HashMap::new(); | ||
for (name, client) in &self.clients { | ||
let provider = LLMProvider::try_from((client, ctx)) | ||
.context(format!("Failed to parse client: {}", name))?; | ||
clients.insert(name.into(), Arc::new(provider)); | ||
} | ||
// TODO: Also do validation here | ||
Ok((self.primary.clone(), clients)) | ||
} | ||
} |
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.