Skip to content

Commit

Permalink
fix: formatting in baml- and language_client_
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal committed Oct 21, 2024
1 parent af04c3e commit 709ae7d
Show file tree
Hide file tree
Showing 31 changed files with 200 additions and 142 deletions.
4 changes: 1 addition & 3 deletions engine/baml-lib/baml-core/src/ir/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
use baml_types::TypeValue;
use serde_json::json;

use super::{
Class, Enum, FieldType, FunctionArgs, FunctionNode, IntermediateRepr, Walker,
};
use super::{Class, Enum, FieldType, FunctionArgs, FunctionNode, IntermediateRepr, Walker};

pub trait WithJsonSchema {
fn json_schema(&self) -> serde_json::Value;
Expand Down
4 changes: 1 addition & 3 deletions engine/baml-lib/jinja-runtime/src/output_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ impl minijinja::value::Object for OutputFormat {
Err(e) => {
return Err(Error::new(
ErrorKind::SyntaxError,
format!(
"Invalid value for always_hoist_enums (expected bool): {e}"
),
format!("Invalid value for always_hoist_enums (expected bool): {e}"),
))
}
}
Expand Down
12 changes: 3 additions & 9 deletions engine/baml-lib/jinja/src/evaluate_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ impl TypeError {
} else {
// If there are multiple close names, suggest them all
let suggestions = close_names.join("`, `");
format!(
"Variable `{name}` does not exist. Did you mean one of these: `{suggestions}`?"
)
format!("Variable `{name}` does not exist. Did you mean one of these: `{suggestions}`?")
};

Self { message, span }
Expand Down Expand Up @@ -135,9 +133,7 @@ impl TypeError {

fn new_wrong_arg_count(func: &str, span: Span, expected: usize, got: usize) -> Self {
Self {
message: format!(
"Function '{func}' expects {expected} arguments, but got {got}"
),
message: format!("Function '{func}' expects {expected} arguments, but got {got}"),
span,
}
}
Expand Down Expand Up @@ -185,9 +181,7 @@ impl TypeError {
} else {
// If there are multiple close names, suggest them all
let suggestions = close_names.join("', '");
format!(
"Filter '{name}' does not exist. Did you mean one of these: '{suggestions}'?"
)
format!("Filter '{name}' does not exist. Did you mean one of these: '{suggestions}'?")
};

Self { message: format!("{message}\n\nSee: https://docs.rs/minijinja/latest/minijinja/filters/index.html#functions for the compelete list"), span }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::deserializer::{deserialize_flags::Flag, types::BamlValueWithFlags};
use anyhow::Result;
use internal_baml_core::ir::FieldType;
Expand Down
4 changes: 1 addition & 3 deletions engine/baml-lib/jsonish/src/jsonish/iterative_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ impl JsonParseState {
}
_ => {
// TODO: this should never happen as we should only be pushing objects and arrays
panic!(
"Unexpected value: {value:?} in collection stack: {last:?}"
);
panic!("Unexpected value: {value:?} in collection stack: {last:?}");
}
}
} else {
Expand Down
11 changes: 5 additions & 6 deletions engine/baml-lib/jsonish/src/jsonish/parser/fixing_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn parse<'a>(str: &'a str, _options: &ParseOptions) -> Result<Vec<(Value, Ve
#[cfg(test)]
mod tests {
use super::*;
use crate::jsonish::{Value, ParseOptions};
use crate::jsonish::{ParseOptions, Value};

#[test]
fn test_partial_array() {
Expand All @@ -117,7 +117,6 @@ mod tests {
}
_ => panic!("Expected array"),
}

}

#[test]
Expand All @@ -135,10 +134,10 @@ mod tests {
assert_eq!(a, &serde_json::Number::from(11));
assert_eq!(b, &serde_json::Number::from(22));
}
_ => panic!("Expected two numbers.")
_ => panic!("Expected two numbers."),
}
}
_ => panic!("Expected object")
_ => panic!("Expected object"),
}
}

Expand All @@ -157,10 +156,10 @@ mod tests {
assert_eq!(a, &serde_json::Number::from(11));
assert_eq!(b, &serde_json::Number::from(22));
}
_ => panic!("Expected two numbers.")
_ => panic!("Expected two numbers."),
}
}
_ => panic!("Expected object")
_ => panic!("Expected object"),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::jsonish::Value;

#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ impl JsonParseState {
}
_ => {
// TODO: this should never happen as we should only be pushing objects and arrays
panic!(
"Unexpected value: {value:?} in collection stack: {last:?}"
);
panic!("Unexpected value: {value:?} in collection stack: {last:?}");
}
}
} else {
Expand Down
1 change: 0 additions & 1 deletion engine/baml-lib/jsonish/src/jsonish/value.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashSet;


#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Fixes {
GreppedForJSON,
Expand Down
9 changes: 6 additions & 3 deletions engine/baml-lib/jsonish/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ fn singleton_list_int_deleted() {
let output_format = OutputFormatContent::new(Vec::new(), Vec::new(), target.clone());
let res = from_str(&output_format, &target, "[123", true).expect("Can parse");
let baml_value: BamlValue = res.into();
assert_eq!(baml_value, BamlValue::List( vec![] ));
assert_eq!(baml_value, BamlValue::List(vec![]));
}

#[test]
Expand All @@ -710,7 +710,7 @@ fn list_int_deleted() {
let output_format = OutputFormatContent::new(Vec::new(), Vec::new(), target.clone());
let res = from_str(&output_format, &target, "[123, 456", true).expect("Can parse");
let baml_value: BamlValue = res.into();
assert_eq!(baml_value, BamlValue::List( vec![ BamlValue::Int(123)] ));
assert_eq!(baml_value, BamlValue::List(vec![BamlValue::Int(123)]));
}

#[test]
Expand All @@ -722,7 +722,10 @@ fn list_int_not_deleted() {
let output_format = OutputFormatContent::new(Vec::new(), Vec::new(), target.clone());
let res = from_str(&output_format, &target, "[123, 456 // Done", true).expect("Can parse");
let baml_value: BamlValue = res.into();
assert_eq!(baml_value, BamlValue::List( vec![ BamlValue::Int(123), BamlValue::Int(456)] ));
assert_eq!(
baml_value,
BamlValue::List(vec![BamlValue::Int(123), BamlValue::Int(456)])
);
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion engine/baml-lib/parser-database/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ impl Attributes {
pub fn set_skip(&mut self) {
self.skip.replace(true);
}

}
pub(super) fn resolve_attributes(ctx: &mut Context<'_>) {
for top in ctx.ast.iter_tops() {
Expand Down
4 changes: 1 addition & 3 deletions engine/baml-lib/prompt-parser/src/parser/parse_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ pub fn parse_prompt(
}
Err(err) => {
diagnostics.push_error(DatamodelError::new_parser_error(
format!(
"Unabled to parse this raw string. Please file a bug.\n{err}"
),
format!("Unabled to parse this raw string. Please file a bug.\n{err}"),
raw_string.span().clone(),
));
Err(diagnostics)
Expand Down
3 changes: 1 addition & 2 deletions engine/baml-lib/schema-ast/src/ast/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ impl Attribute {
pub fn assert_eq_up_to_span(&self, other: &Attribute) {
assert_eq!(self.name.to_string(), other.name.to_string());
assert_eq!(self.parenthesized, other.parenthesized);
self
.arguments
self.arguments
.iter()
.zip(other.arguments.iter())
.for_each(|(arg1, arg2)| {
Expand Down
33 changes: 16 additions & 17 deletions engine/baml-lib/schema-ast/src/ast/expression.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::ast::Span;
use std::fmt;

Expand Down Expand Up @@ -191,7 +190,6 @@ impl fmt::Display for Expression {
}

impl Expression {

pub fn from_json(value: serde_json::Value, span: Span, empty_span: Span) -> Expression {
match value {
serde_json::Value::Null => Expression::StringValue("Null".to_string(), empty_span),
Expand Down Expand Up @@ -343,30 +341,31 @@ impl Expression {
pub fn assert_eq_up_to_span(&self, other: &Expression) {
use Expression::*;
match (self, other) {
(BoolValue(v1,_), BoolValue(v2,_)) => assert_eq!(v1,v2),
(BoolValue(_,_), _) => panic!("Types do not match: {self:?} and {other:?}"),
(NumericValue(n1,_), NumericValue(n2,_)) => assert_eq!(n1, n2),
(NumericValue(_,_), _) => panic!("Types do not match: {self:?} and {other:?}"),
(Identifier(i1), Identifier(i2)) => assert_eq!(i1,i2),
(BoolValue(v1, _), BoolValue(v2, _)) => assert_eq!(v1, v2),
(BoolValue(_, _), _) => panic!("Types do not match: {self:?} and {other:?}"),
(NumericValue(n1, _), NumericValue(n2, _)) => assert_eq!(n1, n2),
(NumericValue(_, _), _) => panic!("Types do not match: {self:?} and {other:?}"),
(Identifier(i1), Identifier(i2)) => assert_eq!(i1, i2),
(Identifier(_), _) => panic!("Types do not match: {self:?} and {other:?}"),
(StringValue(s1,_), StringValue(s2,_)) => assert_eq!(s1, s2),
(StringValue(_,_), _) => panic!("Types do not match: {self:?} and {other:?}"),
(StringValue(s1, _), StringValue(s2, _)) => assert_eq!(s1, s2),
(StringValue(_, _), _) => panic!("Types do not match: {self:?} and {other:?}"),
(RawStringValue(s1), RawStringValue(s2)) => s1.assert_eq_up_to_span(s2),
(RawStringValue(_), _) => panic!("Types do not match: {self:?} and {other:?}"),
(Array(xs,_), Array(ys,_)) => {
(Array(xs, _), Array(ys, _)) => {
assert_eq!(xs.len(), ys.len());
xs.iter().zip(ys).for_each(|(x,y)| { x.assert_eq_up_to_span(y); })
},
(Array(_,_), _) => panic!("Types do not match: {self:?} and {other:?}"),
(Map(m1,_), Map(m2,_)) => {
xs.iter().zip(ys).for_each(|(x, y)| {
x.assert_eq_up_to_span(y);
})
}
(Array(_, _), _) => panic!("Types do not match: {self:?} and {other:?}"),
(Map(m1, _), Map(m2, _)) => {
assert_eq!(m1.len(), m2.len());
m1.iter().zip(m2).for_each(|((k1, v1), (k2, v2))| {
k1.assert_eq_up_to_span(k2);
v1.assert_eq_up_to_span(v2);
});
},
(Map(_,_), _) => panic!("Types do not match: {self:?} and {other:?}"),

}
(Map(_, _), _) => panic!("Types do not match: {self:?} and {other:?}"),
}
}
}
20 changes: 10 additions & 10 deletions engine/baml-lib/schema-ast/src/ast/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ impl Identifier {
pub fn assert_eq_up_to_span(&self, other: &Identifier) {
use Identifier::*;
match (self, other) {
(ENV(e1,_), ENV(e2, _)) => assert_eq!(e1, e2),
(ENV(_,_), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Local(l1,_), Local(l2,_)) => assert_eq!(l1, l2),
(Local(_,_), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Ref(r1,_), Ref(r2,_)) => assert_eq!(r1, r2),
(Ref(_,_), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Identifier::String(s1,_), Identifier::String(s2,_)) => assert_eq!(s1,s2),
(Identifier::String(_,_), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Invalid(i1,_), Invalid(i2,_)) => assert_eq!(i1,i2),
(Invalid(_,_), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(ENV(e1, _), ENV(e2, _)) => assert_eq!(e1, e2),
(ENV(_, _), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Local(l1, _), Local(l2, _)) => assert_eq!(l1, l2),
(Local(_, _), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Ref(r1, _), Ref(r2, _)) => assert_eq!(r1, r2),
(Ref(_, _), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Identifier::String(s1, _), Identifier::String(s2, _)) => assert_eq!(s1, s2),
(Identifier::String(_, _), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
(Invalid(i1, _), Invalid(i2, _)) => assert_eq!(i1, i2),
(Invalid(_, _), _) => panic!("Mismatched identifiers: {self:?}, {other:?}"),
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions engine/baml-lib/schema-ast/src/parser/parse_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ pub(crate) fn parse_type_expr(
match current.as_rule() {
Rule::identifier => {
name = Some(parse_identifier(current, diagnostics));
},
}
Rule::trailing_comment => {
comment = merge_comments(comment, parse_trailing_comment(current));
}
Rule::field_type_chain => {
field_type = parse_field_type_chain(current, diagnostics);
field_type = parse_field_type_chain(current, diagnostics);
}
Rule::field_attribute => {
field_attributes.push(parse_attribute(current, false, diagnostics))
}
Rule::field_attribute => field_attributes.push(parse_attribute(current, false, diagnostics)),
_ => parsing_catch_all(current, "field"),
}
}
Expand Down Expand Up @@ -178,8 +180,7 @@ pub(crate) fn parse_field_type_with_attr(
// ft.set_attributes(attributes.clone()); // Clone the borrowed `Vec<Attribute>`
// }
}
_ => {
}
_ => {}
}
ft.extend_attributes(field_attributes);

Expand Down Expand Up @@ -252,7 +253,10 @@ mod tests {
let result = parse_field_type_chain(parsed, &mut diagnostics).unwrap();
if let FieldType::Union(_, types, _, _) = &result {
assert_eq!(types[1].clone().attributes().len(), 1);
assert_eq!(types[1].clone().attributes()[0].name.to_string().as_str(), "description");
assert_eq!(
types[1].clone().attributes()[0].name.to_string().as_str(),
"description"
);
} else {
panic!("Expected union");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
use super::*;
use crate::parser::{BAMLParser, Rule};
use internal_baml_diagnostics::{Diagnostics, SourceFile};
use pest::{Parser, consumes_to, fails_with, parses_to};
use pest::{consumes_to, fails_with, parses_to, Parser};

#[test]
fn keyword_name_mandatory_whitespace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ pub(crate) fn parse_value_expression_block(
Ok(arg) => input = Some(arg),
Err(err) => diagnostics.push_error(err),
},
Rule::field_type | Rule::field_type_chain => match parse_function_arg(current, diagnostics) {
Ok(arg) => output = Some(arg),
Err(err) => diagnostics.push_error(err),
},
Rule::field_type | Rule::field_type_chain => {
match parse_function_arg(current, diagnostics) {
Ok(arg) => output = Some(arg),
Err(err) => diagnostics.push_error(err),
}
}
Rule::BLOCK_OPEN | Rule::BLOCK_CLOSE => {}

Rule::value_expression_contents => {
Expand Down
13 changes: 10 additions & 3 deletions engine/baml-runtime/src/cli/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,23 @@ Tip: test that the server is up using `curl http://localhost:{}/_debug/ping`
true,
GeneratorDefaultClientMode::Sync,
Vec::new(),
).map_err(|_| BamlError::InternalError{ message: "Failed to make placeholder generator".to_string()})?;
)
.map_err(|_| BamlError::InternalError {
message: "Failed to make placeholder generator".to_string(),
})?;
let schema: OpenApiSchema = (locked.inner.ir.as_ref(), &fake_generator)
.try_into()
.map_err(|e| {
log::warn!("Failed to generate openapi schema: {}", e);
BamlError::InternalError{ message: format!("Failed to generate openapi schema")}
BamlError::InternalError {
message: format!("Failed to generate openapi schema"),
}
})?;
serde_json::to_string(&schema).map_err(|e| {
log::warn!("Failed to serialize openapi schema: {}", e);
BamlError::InternalError{ message: format!("Failed to serialize openapi schema") }
BamlError::InternalError {
message: format!("Failed to serialize openapi schema"),
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ pub async fn orchestrate(
let prompt = match node.render_prompt(ir, prompt, ctx, params).await {
Ok(p) => p,
Err(e) => {
results.push((node.scope, LLMResponse::InternalFailure(e.to_string()), None));
results.push((
node.scope,
LLMResponse::InternalFailure(e.to_string()),
None,
));
continue;
}
};
Expand Down
Loading

0 comments on commit 709ae7d

Please sign in to comment.