Skip to content

Sam/backend endpoints #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 32 commits into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d93b6fc
creating a signature for every type in the IR
hellovai Feb 26, 2025
273f741
add boundary collector
hellovai Feb 27, 2025
19a49dc
way to upload code
hellovai Feb 27, 2025
983f418
algorithm working!
hellovai Mar 3, 2025
f9db910
working for sending events!
hellovai Mar 3, 2025
89265c7
make studio backend build
sxlijin Mar 4, 2025
1d10af3
add types for the src upload handshake
sxlijin Mar 4, 2025
2fc651b
more type updates
sxlijin Mar 4, 2025
0d1a87e
add api endpoints in boundary_api.rs
sxlijin Mar 4, 2025
b2c6a16
does not exist vs exists
sxlijin Mar 4, 2025
7c4363d
rename to get-upload-status
sxlijin Mar 4, 2025
31fd4c9
trace event uploads
sxlijin Mar 4, 2025
a3ea4f2
trace upload
sxlijin Mar 4, 2025
b1254cb
add BamlValueWithType and wire out literal_type
sxlijin Mar 4, 2025
1c7cd02
Pushing up code for jsonish
hellovai Mar 4, 2025
a38d50f
type reification
sxlijin Mar 4, 2025
df4fb34
bamlvaluewithtype plumbing
sxlijin Mar 4, 2025
2b78045
baml value with type transform
sxlijin Mar 4, 2025
9b85ed9
runtime working
hellovai Mar 4, 2025
3fd01e2
update types
hellovai Mar 4, 2025
a27013c
working system
hellovai Mar 5, 2025
dab4a54
decouple tracing rpc and runtime-internal types
sxlijin Mar 5, 2025
548d1f2
byebye type safety
sxlijin Mar 5, 2025
9f5a0d7
back to project123
sxlijin Mar 5, 2025
c1e578c
fix the shape of bamlvaluewithcocnretetype
sxlijin Mar 5, 2025
04b58eb
output type encoding now fixed
sxlijin Mar 5, 2025
e9d67f8
image fix pushed, run against staging
sxlijin Mar 5, 2025
cee8fcc
fix some stuff
hellovai Mar 5, 2025
7c712d3
baml image uploads
sxlijin Mar 5, 2025
2fa03d1
add more tests
sxlijin Mar 5, 2025
21f26ba
set up rpc types
sxlijin Mar 25, 2025
cfccb83
more
sxlijin Mar 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"baml-lib/*",
"baml-runtime",
"baml-rpc",
"baml-schema-wasm",
"bstd",
"cli",
Expand All @@ -15,6 +16,7 @@ members = [
default-members = [
"baml-lib/*",
"baml-runtime",
"baml-rpc",
# Disabled by default: --features no_wasm and --features wasm are mutually exclusive
# Building baml-schema-wasm in combination with everything else triggers feature unification,
# and it's OK to not build this by default because we have to build ts separately (this may
Expand Down Expand Up @@ -55,6 +57,8 @@ internal-baml-core = { path = "baml-lib/baml-core" }
internal-baml-jinja = { path = "baml-lib/jinja-runtime" }
internal-baml-schema-ast = { path = "baml-lib/schema-ast" }
internal-llm-client = { path = "baml-lib/llm-client" }
baml-runtime = { path = "baml-runtime" }

log = "0.4.20"
# TODO: disable imports, etc
minijinja = { version = "1.0.16", default-features = false, features = [
Expand Down
2 changes: 2 additions & 0 deletions engine/baml-lib/baml-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ dissimilar = "1.0.4"
expect-test = "1.1.0"
indoc.workspace = true
either = "1.8.1"
diff = "*"
colored = "*"
1 change: 1 addition & 0 deletions engine/baml-lib/baml-core/src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod jinja_helpers;
mod json_schema;
pub mod repr;
mod walker;
pub mod signature;

pub use ir_helpers::{
scope_diagnostics, ArgCoercer, ClassFieldWalker, ClassWalker, ClientWalker, EnumValueWalker,
Expand Down
42 changes: 34 additions & 8 deletions engine/baml-lib/baml-core/src/ir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ use internal_baml_schema_ast::ast::{
use internal_llm_client::{ClientProvider, ClientSpec, UnresolvedClientProperty};
use serde::Serialize;

use crate::ir::signature::{BamlHash, ProvideBamlHash};
use crate::Configuration;

/// This class represents the intermediate representation of the BAML AST.
/// It is a representation of the BAML AST that is easier to work with than the
/// raw BAML AST, and should include all information necessary to generate
/// code in any target language.
#[derive(Debug)]
pub struct IntermediateRepr {
enums: Vec<Node<Enum>>,
classes: Vec<Node<Class>>,
type_aliases: Vec<Node<TypeAlias>>,
functions: Vec<Node<Function>>,
clients: Vec<Node<Client>>,
retry_policies: Vec<Node<RetryPolicy>>,
template_strings: Vec<Node<TemplateString>>,
pub(super) enums: Vec<Node<Enum>>,
pub(super) classes: Vec<Node<Class>>,
pub(super) type_aliases: Vec<Node<TypeAlias>>,
pub(super) functions: Vec<Node<Function>>,
pub(super) clients: Vec<Node<Client>>,
pub(super) retry_policies: Vec<Node<RetryPolicy>>,
pub(super) template_strings: Vec<Node<TemplateString>>,

/// Strongly connected components of the dependency graph (finite cycles).
finite_recursive_cycles: Vec<IndexSet<String>>,
Expand Down Expand Up @@ -1243,6 +1243,32 @@ pub struct Client {
pub options: UnresolvedClientProperty<()>,
}

impl Client {
pub fn names(&self) -> std::collections::HashSet<String> {
let mut names = std::collections::HashSet::new();

self.retry_policy_id.as_ref().map(|id| {
names.insert(id.clone());
});

match &self.options {
UnresolvedClientProperty::OpenAI(..)
| UnresolvedClientProperty::Anthropic(..)
| UnresolvedClientProperty::AWSBedrock(..)
| UnresolvedClientProperty::Vertex(..)
| UnresolvedClientProperty::GoogleAI(..) => {}
UnresolvedClientProperty::RoundRobin(options) => {
names.extend(options.names());
}
UnresolvedClientProperty::Fallback(options) => {
names.extend(options.names());
}
}

names
}
}

impl WithRepr<Client> for ClientWalker<'_> {
fn attributes(&self, _: &ParserDatabase) -> NodeAttributes {
NodeAttributes {
Expand Down
110 changes: 110 additions & 0 deletions engine/baml-lib/baml-core/src/ir/signature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use baml_types::{Resolvable, StringOr};

mod r#enum;
mod class;
mod template_string;
mod test_case;
mod client;
mod function;
mod type_alias;
mod retry_policy;
mod runtime;
/// Used to identify unique signatures of types.

trait Signature {
fn type_name(&self) -> &'static str;
// Returns the interface of the type and its named-dependencies
fn interface(&self) -> Option<String>;
// Returns the impl of the type and its named-dependencies
fn impl_(&self) -> Option<String> {
None
}
}

#[derive(Debug, PartialEq, Eq, Hash)]
pub struct BamlHash {
type_name: &'static str,
interface_hash: Option<u64>,
impl_hash: Option<u64>,
}


pub trait ProvideBamlHash {
fn to_baml_hash(&self) -> BamlHash;
}

fn hash_string(type_name: &str, s: &str) -> u64 {
let mut hasher = std::collections::hash_map::DefaultHasher::new();
std::hash::Hash::hash(&(type_name, s), &mut hasher);
std::hash::Hasher::finish(&hasher)
}

impl<T: Signature> ProvideBamlHash for T {
fn to_baml_hash(&self) -> BamlHash {
BamlHash {
type_name: self.type_name(),
interface_hash: self.interface().map(|s| hash_string(self.type_name(), &s)),
impl_hash: self.impl_().map(|s| hash_string(self.type_name(), &s)),
}
}
}

impl<Meta> Signature for Resolvable<StringOr, Meta> {
fn type_name(&self) -> &'static str {
match self {
Resolvable::String(s, _) => s.type_name(),
Resolvable::Numeric(n, _) => "numeric",
Resolvable::Bool(b, _) => "bool",
Resolvable::Array(_, _) => "array",
Resolvable::Map(_, _) => "map",
Resolvable::Null(_) => "null",
}
}

fn interface(&self) -> Option<String> {
match self {
Resolvable::String(value, _) => value.interface(),
Resolvable::Numeric(value, _) => Some(value.to_string()),
Resolvable::Bool(value, _) => Some(value.to_string()),
Resolvable::Array(resolvables, _) => Some(resolvables
.iter()
.filter_map(|r| r.interface())
.collect::<Vec<_>>()
.join("_BAML_ARRAY_")),
Resolvable::Map(index_map, _) => Some(index_map
.iter()
.filter_map(|(k, (_, v))| v.interface().map(|s| format!("{}: {}", k, s)))
.collect::<Vec<_>>()
.join("_BAML_MAP_")),
Resolvable::Null(_) => Some("null".to_string()),
}
}
}

impl Signature for StringOr {
fn type_name(&self) -> &'static str {
match self {
StringOr::EnvVar(_) => "env_var",
StringOr::Value(_) => "value",
StringOr::JinjaExpression(j) => j.type_name(),
}
}

fn interface(&self) -> Option<String> {
match self {
StringOr::EnvVar(name) => Some(name.clone()),
StringOr::Value(value) => Some(value.clone()),
StringOr::JinjaExpression(expression) => expression.interface(),
}
}
}

impl Signature for baml_types::JinjaExpression {
fn type_name(&self) -> &'static str {
"jinja_expression"
}

fn interface(&self) -> Option<String> {
Some(self.to_string())
}
}
Loading