Skip to content

Commit

Permalink
Merge branch 'canary' into sam/normalize-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sxlijin authored Dec 4, 2024
2 parents 05fd646 + 3ebf08f commit c061b9a
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 102 deletions.
8 changes: 4 additions & 4 deletions engine/baml-lib/baml-types/src/baml_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl BamlValue {
if value_types.is_empty() {
"map<string, ?>".into()
} else {
format!("map<string, {}>", value_types)
format!("map<string, {value_types}>")
}
}
BamlValue::List(k) => {
Expand All @@ -95,16 +95,16 @@ impl BamlValue {
if value_type.is_empty() {
"list<?>".into()
} else {
format!("list<{}>", value_type)
format!("list<{value_type}>")
}
}
BamlValue::Media(m) => match m.media_type {
BamlMediaType::Image => "image",
BamlMediaType::Audio => "audio",
}
.into(),
BamlValue::Enum(e, _) => format!("enum {}", e),
BamlValue::Class(c, _) => format!("class {}", c),
BamlValue::Enum(e, _) => format!("enum {e}"),
BamlValue::Class(c, _) => format!("class {c}"),
BamlValue::Null => "null".into(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions engine/baml-lib/baml-types/src/field_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ impl std::fmt::Display for FieldType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FieldType::Enum(name) | FieldType::Class(name) => {
write!(f, "{}", name)
write!(f, "{name}")
}
FieldType::Primitive(t) => write!(f, "{}", t),
FieldType::Literal(v) => write!(f, "{}", v),
FieldType::Primitive(t) => write!(f, "{t}"),
FieldType::Literal(v) => write!(f, "{v}"),
FieldType::Union(choices) => {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion engine/baml-lib/baml-types/src/minijinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl minijinja::value::Object for MinijinjaBamlMedia {
) -> Result<minijinja::value::Value, minijinja::Error> {
Err(minijinja::Error::new(
minijinja::ErrorKind::UnknownMethod,
format!("BamlImage has no callable attribute '{:#?}'", args),
format!("BamlImage has no callable attribute '{args:#?}'"),
))
}
}
2 changes: 1 addition & 1 deletion engine/baml-lib/baml-types/src/value_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl std::fmt::Display for StringOr {
match self {
Self::Value(s) => write!(f, "{s}"),
Self::EnvVar(s) => write!(f, "${s}"),
Self::JinjaExpression(j) => write!(f, "{{ {} }}", j),
Self::JinjaExpression(j) => write!(f, "{{ {j} }}"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions engine/baml-lib/baml/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ fn build_folder_tests(dir: &'static str, out_file_name: &str) {
let mut out_file = fs::File::create(format!("{CARGO_MANIFEST_DIR}/{out_file_name}")).unwrap();
for schema_path in &all_schemas {
let file_path = format!("{CARGO_MANIFEST_DIR}/{dir}{schema_path}");
println!("Reading file: {}", file_path);
println!("Reading file: {file_path}");
let file_content = fs::read_to_string(&file_path).unwrap();
writeln!(out_file, "{}", file_content).unwrap();
writeln!(out_file, "{file_content}").unwrap();
}
}

Expand Down
4 changes: 2 additions & 2 deletions engine/baml-lib/diagnostics/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ impl std::fmt::Display for Diagnostics {
let warn_str = self.warnings_to_pretty_string();

if !err_str.is_empty() {
writeln!(f, "{}", err_str)?;
writeln!(f, "{err_str}")?;
}
if !warn_str.is_empty() {
writeln!(f, "{}", warn_str)?;
writeln!(f, "{warn_str}")?;
}

Ok(())
Expand Down
9 changes: 4 additions & 5 deletions engine/baml-lib/diagnostics/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl DatamodelError {
)
};

Self::new(format!("{}{}", prefix, suggestions), span)
Self::new(format!("{prefix}{suggestions}"), span)
}

pub fn new_client_not_found_error(
Expand All @@ -511,7 +511,7 @@ impl DatamodelError {
let close_names = sort_by_match(client_name, &names, Some(10));

let msg = if close_names.is_empty() {
format!("client `{}` does not exist.", client_name)
format!("client `{client_name}` does not exist.")
} else if close_names.len() == 1 {
format!(
"client `{}` does not exist. Did you mean `{}`?",
Expand All @@ -537,7 +537,7 @@ impl DatamodelError {

let msg = if close_names.is_empty() {
// If no names are close enough, suggest nothing or provide a generic message
format!("Type `{}` does not exist.", type_name)
format!("Type `{type_name}` does not exist.")
} else if close_names.len() == 1 {
// If there's only one close name, suggest it
format!(
Expand All @@ -548,8 +548,7 @@ impl DatamodelError {
// If there are multiple close names, suggest them all
let suggestions = close_names.join("`, `");
format!(
"Type `{}` does not exist. Did you mean one of these: `{}`?",
type_name, suggestions
"Type `{type_name}` does not exist. Did you mean one of these: `{suggestions}`?"
)
};

Expand Down
7 changes: 3 additions & 4 deletions engine/baml-lib/diagnostics/src/warning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl DatamodelWarning {

let msg = if close_names.is_empty() {
// If no names are close enough, suggest nothing or provide a generic message
format!("Type `{}` does not exist.", type_name)
format!("Type `{type_name}` does not exist.")
} else if close_names.len() == 1 {
// If there's only one close name, suggest it
format!(
Expand All @@ -55,8 +55,7 @@ impl DatamodelWarning {
// If there are multiple close names, suggest them all
let suggestions = close_names.join("`, `");
format!(
"Type `{}` does not exist. Did you mean one of these: `{}`? ",
type_name, suggestions
"Type `{type_name}` does not exist. Did you mean one of these: `{suggestions}`? "
)
};

Expand Down Expand Up @@ -141,7 +140,7 @@ impl DatamodelWarning {
)
};

Self::new(format!("{}{}", prefix, suggestions), span)
Self::new(format!("{prefix}{suggestions}"), span)
}

pub fn prompt_variable_unused(message: &str, span: Span) -> DatamodelWarning {
Expand Down
25 changes: 10 additions & 15 deletions engine/baml-lib/jinja/src/evaluate_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl TypeError {

let message = if close_names.is_empty() {
// If no names are close enough, suggest nothing or provide a generic message
format!("Variable `{}` does not exist.", name)
format!("Variable `{name}` does not exist.")
} else if close_names.len() == 1 {
// If there's only one close name, suggest it
format!(
Expand All @@ -101,8 +101,7 @@ impl TypeError {
// If there are multiple close names, suggest them all
let suggestions = close_names.join("`, `");
format!(
"Variable `{}` does not exist. Did you mean one of these: `{}`?",
name, suggestions
"Variable `{name}` does not exist. Did you mean one of these: `{suggestions}`?"
)
};

Expand Down Expand Up @@ -131,16 +130,15 @@ impl TypeError {

fn new_missing_arg(func: &str, span: Span, name: &str) -> Self {
Self {
message: format!("Function '{}' expects argument '{}'", func, name),
message: format!("Function '{func}' expects argument '{name}'"),
span,
}
}

fn new_wrong_arg_count(func: &str, span: Span, expected: usize, got: usize) -> Self {
Self {
message: format!(
"Function '{}' expects {} arguments, but got {}",
func, expected, got
"Function '{func}' expects {expected} arguments, but got {got}"
),
span,
}
Expand All @@ -154,7 +152,7 @@ impl TypeError {

let message = if close_names.is_empty() {
// If no names are close enough, suggest nothing or provide a generic message
format!("Function '{}' does not have an argument '{}'.", func, name)
format!("Function '{func}' does not have an argument '{name}'.")
} else if close_names.len() == 1 {
// If there's only one close name, suggest it
format!(
Expand All @@ -165,8 +163,7 @@ impl TypeError {
// If there are multiple close names, suggest them all
let suggestions = close_names.join("', '");
format!(
"Function '{}' does not have an argument '{}'. Did you mean one of these: '{}'?",
func, name, suggestions
"Function '{func}' does not have an argument '{name}'. Did you mean one of these: '{suggestions}'?"
)
};

Expand All @@ -180,7 +177,7 @@ impl TypeError {

let message = if close_names.is_empty() {
// If no names are close enough, suggest nothing or provide a generic message
format!("Filter '{}' does not exist", name)
format!("Filter '{name}' does not exist")
} else if close_names.len() == 1 {
// If there's only one close name, suggest it
format!(
Expand All @@ -191,8 +188,7 @@ impl TypeError {
// If there are multiple close names, suggest them all
let suggestions = close_names.join("', '");
format!(
"Filter '{}' does not exist. Did you mean one of these: '{}'?",
name, suggestions
"Filter '{name}' does not exist. Did you mean one of these: '{suggestions}'?"
)
};

Expand Down Expand Up @@ -241,16 +237,15 @@ impl TypeError {
) -> Self {
Self {
message: format!(
"class {} ({}) does not have a property '{}'",
class_name, variable_name, property
"class {class_name} ({variable_name}) does not have a property '{property}'"
),
span,
}
}

fn new_class_not_defined(class: &str) -> Self {
Self {
message: format!("Class '{}' is not defined", class),
message: format!("Class '{class}' is not defined"),
span: Span::default(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions engine/baml-lib/jinja/src/evaluate_type/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ impl Type {
v.iter().map(|x| x.name()).collect::<Vec<_>>().join(" | ")
),
Type::Both(l, r) => format!("{} & {}", l.name(), r.name()),
Type::ClassRef(name) => format!("class {}", name),
Type::FunctionRef(name) => format!("function {}", name),
Type::ClassRef(name) => format!("class {name}"),
Type::FunctionRef(name) => format!("function {name}"),
Type::Image => "image".into(),
Type::Audio => "audio".into(),
}
Expand Down
2 changes: 1 addition & 1 deletion engine/baml-lib/jinja/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct ValidationError {
impl std::fmt::Display for ValidationError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
for err in &self.errors {
writeln!(f, "{}", err)?;
writeln!(f, "{err}")?;
}
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions engine/baml-lib/llm-client/src/clients/aws_bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,21 @@ impl UnresolvedAwsBedrock {
"max_tokens" => inference_config.max_tokens = v.as_numeric().and_then(|val| match val.parse() {
Ok(v) => Some(v),
Err(e) => {
properties.push_error(format!("max_tokens must be a number: {}", e), v.meta().clone());
properties.push_error(format!("max_tokens must be a number: {e}"), v.meta().clone());
None
}
}),
"temperature" => inference_config.temperature = v.as_numeric().and_then(|val| match val.parse() {
Ok(v) => Some(v),
Err(e) => {
properties.push_error(format!("temperature must be a number: {}", e), v.meta().clone());
properties.push_error(format!("temperature must be a number: {e}"), v.meta().clone());
None
}
}),
"top_p" => inference_config.top_p = v.as_numeric().and_then(|val| match val.parse() {
Ok(v) => Some(v),
Err(e) => {
properties.push_error(format!("top_p must be a number: {}", e), v.meta().clone());
properties.push_error(format!("top_p must be a number: {e}"), v.meta().clone());
None
}
}),
Expand All @@ -234,7 +234,7 @@ impl UnresolvedAwsBedrock {
}
},
_ => {
properties.push_error(format!("unknown inference_config key: {}", k), key_span.clone());
properties.push_error(format!("unknown inference_config key: {k}"), key_span.clone());
},
}
}
Expand Down
21 changes: 10 additions & 11 deletions engine/baml-lib/llm-client/src/clients/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
let result = match ensure_string(&mut self.options, key) {
Ok(result) => {
if required && result.is_none() {
self.push_option_error(format!("Missing required property: {}", key));
self.push_option_error(format!("Missing required property: {key}"));
}
result
}
Expand All @@ -89,7 +89,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
let result = match ensure_map(&mut self.options, key) {
Ok(result) => {
if required && result.is_none() {
self.push_option_error(format!("Missing required property: {}", key));
self.push_option_error(format!("Missing required property: {key}"));
}
result
}
Expand All @@ -110,7 +110,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
let result = match ensure_array(&mut self.options, key) {
Ok(result) => {
if required && result.is_none() {
self.push_option_error(format!("Missing required property: {}", key));
self.push_option_error(format!("Missing required property: {key}"));
}
result
}
Expand All @@ -127,7 +127,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
let result = match ensure_bool(&mut self.options, key) {
Ok(result) => {
if required && result.is_none() {
self.push_option_error(format!("Missing required property: {}", key));
self.push_option_error(format!("Missing required property: {key}"));
}
result
}
Expand All @@ -144,7 +144,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
let result = match ensure_int(&mut self.options, key) {
Ok(result) => {
if required && result.is_none() {
self.push_option_error(format!("Missing required property: {}", key));
self.push_option_error(format!("Missing required property: {key}"));
}
result
}
Expand Down Expand Up @@ -191,13 +191,12 @@ impl<Meta: Clone> PropertyHandler<Meta> {
} else {
let allowed_roles_str = allowed_roles
.iter()
.map(|v| format!("{:?}", v))
.map(|v| format!("{v:?}"))
.collect::<Vec<_>>()
.join(", ");
self.push_error(
format!(
"default_role must be one of {}. Got: {}",
allowed_roles_str, value
"default_role must be one of {allowed_roles_str}. Got: {value}"
),
span,
);
Expand Down Expand Up @@ -304,7 +303,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
if let Ok(client_spec) =
crate::ClientSpec::new_from_id(value.as_str()).map_err(|e| {
self.push_error(
format!("Invalid strategy: {}", e),
format!("Invalid strategy: {e}"),
v.meta().clone(),
);
})
Expand Down Expand Up @@ -332,7 +331,7 @@ impl<Meta: Clone> PropertyHandler<Meta> {
pub fn finalize_empty(self) -> Vec<Error<Meta>> {
let mut errors = self.errors;
for (k, (key_span, _)) in self.options {
errors.push(Error::new(format!("Unsupported property: {}", k), key_span));
errors.push(Error::new(format!("Unsupported property: {k}"), key_span));
}
errors
}
Expand Down Expand Up @@ -426,7 +425,7 @@ fn ensure_int<Meta: Clone>(
Ok(Some((key_span, i, meta)))
} else {
Err(Error {
message: format!("{} must be an integer. Got: {}", key, i),
message: format!("{key} must be an integer. Got: {i}"),
span: meta,
})
}
Expand Down
3 changes: 1 addition & 2 deletions engine/baml-lib/llm-client/src/clients/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ impl<Meta: Clone> UnresolvedOpenAI<Meta> {
let resource_name = resource_name.resolve(ctx)?;
let deployment_id = deployment_id.resolve(ctx)?;
Ok(format!(
"https://{}.openai.azure.com/openai/deployments/{}",
resource_name, deployment_id
"https://{resource_name}.openai.azure.com/openai/deployments/{deployment_id}"
))
}
})
Expand Down
Loading

0 comments on commit c061b9a

Please sign in to comment.