Skip to content
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

[Chore] Fix typos, and organize functions for style #1087

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ The default base URL for the Gemini provider has been updated to v1beta. This ch
- LLVM install and rebuild script (#794) - ([9ee66ed](https://github.com/boundaryml/baml/commit/9ee66ed2dd14bc0ee12a788f41eae64377e7f2b0)) - Anish Palakurthi
- Prevent version mismatches when generating baml_client (#791) - ([d793603](https://github.com/boundaryml/baml/commit/d7936036e6afa4a0e738242cfb3feaa9e15b3657)) - aaronvg
- fiddle build fix (#800) - ([d304203](https://github.com/boundaryml/baml/commit/d304203241726ac0ba8781db7ac5693339189eb4)) - aaronvg
- Dont drop extra fields in dynamic classes when passing them as inputs to a function (#802) - ([4264c9b](https://github.com/boundaryml/baml/commit/4264c9b143edda0239af197d110357b1969bf12c)) - aaronvg
- Don't drop extra fields in dynamic classes when passing them as inputs to a function (#802) - ([4264c9b](https://github.com/boundaryml/baml/commit/4264c9b143edda0239af197d110357b1969bf12c)) - aaronvg
- Adding support for a sync client for Python + Typescript (#803) - ([62085e7](https://github.com/boundaryml/baml/commit/62085e79d4d86f580ce189bc60f36bd1414893c4)) - hellovai
- Fix WASM-related issues introduced in #803 (#804) - ([0a950e0](https://github.com/boundaryml/baml/commit/0a950e084748837ee2e269504d22dba66f339ca4)) - hellovai
- Adding various fixes (#806) - ([e8c1a61](https://github.com/boundaryml/baml/commit/e8c1a61a96051160566b6458dac5c89d5ddfb86e)) - hellovai
Expand Down Expand Up @@ -416,7 +416,7 @@ The default base URL for the Gemini provider has been updated to v1beta. This ch

### Bug Fixes

- Fix env variables dialoge on VSCode (#750)
- Fix env variables dialog on VSCode (#750)
- Playground selects correct function after loading (#757) - ([09963a0](https://github.com/boundaryml/baml/commit/09963a02e581da9eb8f7bafd3ba812058c97f672)) - aaronvg

### Miscellaneous Chores
Expand Down Expand Up @@ -528,7 +528,7 @@ The default base URL for the Gemini provider has been updated to v1beta. This ch
- add internal build tooling for sam (#512) - ([9ebacca](https://github.com/boundaryml/baml/commit/9ebaccaa542760cb96382ae2a91d780f1ade613b)) - Samuel Lijin
- delete clients dir, this is now dead code (#652) - ([ec2627f](https://github.com/boundaryml/baml/commit/ec2627f59c7fe9edfff46fcdb65f9b9f0e2e072c)) - Samuel Lijin
- consolidate vscode workspace, bump a bunch of deps (#654) - ([82bf6ab](https://github.com/boundaryml/baml/commit/82bf6ab1ad839f84782a7ef0441f21124c368757)) - Samuel Lijin
- Add RB2B tracking script to propmt fiddle (#681) - ([4cf806b](https://github.com/boundaryml/baml/commit/4cf806bba26563fd8b6ddbd68296ab8bdfac21c4)) - hellovai
- Add RB2B tracking script to prompt fiddle (#681) - ([4cf806b](https://github.com/boundaryml/baml/commit/4cf806bba26563fd8b6ddbd68296ab8bdfac21c4)) - hellovai
- Adding better release script (#688) - ([5bec282](https://github.com/boundaryml/baml/commit/5bec282d39d2250b39ef4aba5d6bba9830a35988)) - hellovai

### [AUTO
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Showcase of applications using BAML
- [Aer Compliance](https://www.aercompliance.com/) - AI-powered compliance tasks
- [Haven](https://www.usehaven.ai/) - Automate Tenant communications with AI
- [Muckrock](https://www.muckrock.com/) - FOIA request tracking and filing
- and more! [Let us know](https://calendly.com/boundaryml/meeting-with-founders) if you want to be showcased or want to work with us 1-1 to solve your usecase.
- and more! [Let us know](https://calendly.com/boundaryml/meeting-with-founders) if you want to be showcased or want to work with us 1-1 to solve your use cases.

## Observability

Expand Down Expand Up @@ -227,7 +227,7 @@ BAML handles this and many more cases, such as identifying `Enums` in LLM string

**Aliasing issues**

Prompt engineering requires you to think carefully about what the name of each key in the schema is. Rather than changing your code everytime you want to try a new name out, you can alias fields to a different name and convert them back into the original field name during parsing.
Prompt engineering requires you to think carefully about what the name of each key in the schema is. Rather than changing your code every time you want to try a new name out, you can alias fields to a different name and convert them back into the original field name during parsing.

Here's how BAML differs from these frameworks:

Expand Down Expand Up @@ -302,7 +302,7 @@ We basically wanted [Jinja](https://jinja.palletsprojects.com/en/3.1.x/), but wi

### Does BAML use LLMs to generate code?

No, the BAML dependency transpiles the code using Rust 🦀. It takes just a few milliseconds!
No, the BAML dependency transpile the code using Rust 🦀. It takes just a few milliseconds!

### What does BAML stand for?

Expand Down
6 changes: 3 additions & 3 deletions engine/baml-lib/baml-core/src/ir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl WithRepr<FieldType> for ast::FieldType {
pub enum Identifier {
/// Starts with env.*
ENV(String),
/// The path to a Local Identifer + the local identifer. Separated by '.'
/// The path to a Local Identifier + the local identifier. Separated by '.'
#[allow(dead_code)]
Ref(Vec<String>),
/// A string without spaces or '.' Always starts with a letter. May contain numbers
Expand Down Expand Up @@ -622,7 +622,7 @@ pub enum OracleType {
#[derive(serde::Serialize, Debug)]
pub struct AliasOverride {
pub name: String,
// This is used to generate deserializers with aliased keys (see .overload in python deserializer)
// This is used to generate deserializer with aliased keys (see .overload in python deserializer)
pub aliased_keys: Vec<AliasedKey>,
}

Expand Down Expand Up @@ -974,7 +974,7 @@ impl WithRepr<TestCase> for ConfigurationWalker<'_> {
}
#[derive(Debug, Clone, Serialize)]
pub enum Prompt {
// The prompt stirng, and a list of input replacer keys (raw key w/ magic string, and key to replace with)
// The prompt string, and a list of input replacer keys (raw key w/ magic string, and key to replace with)
String(String, Vec<(String, String)>),

// same thing, the chat message, and the replacer input keys (raw key w/ magic string, and key to replace with)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn errors_with_names<'a>(ctx: &'a mut Context<'_>, idn: &Identifier) {
///
/// Operates in two passes:
///
/// 1. Verify that the type is resolveable (for REF types)
/// 1. Verify that the type is resolvable (for REF types)
/// 2. Verify that the type is well-formed/allowed in the language
pub(crate) fn validate_type(ctx: &mut Context<'_>, field_type: &FieldType) {
validate_type_exists(ctx, field_type);
Expand Down Expand Up @@ -46,7 +46,7 @@ fn validate_type_exists(ctx: &mut Context<'_>, field_type: &FieldType) -> bool {
fn validate_type_allowed(ctx: &mut Context<'_>, field_type: &FieldType) {
match field_type {
FieldType::Map(arity, kv_types, ..) => {
if (arity.is_optional()) {
if arity.is_optional() {
ctx.push_error(DatamodelError::new_validation_error(
format!("Maps are not allowed to be optional").as_str(),
field_type.span().clone(),
Expand All @@ -70,7 +70,7 @@ fn validate_type_allowed(ctx: &mut Context<'_>, field_type: &FieldType) {
FieldType::Symbol(..) => {}

FieldType::List(arity, field_type, ..) => {
if (arity.is_optional()) {
if arity.is_optional() {
ctx.push_error(DatamodelError::new_validation_error(
format!("Lists are not allowed to be optional").as_str(),
field_type.span().clone(),
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 @@ -113,9 +113,9 @@ impl std::fmt::Display for FieldType {
.join(", ")
)
}
FieldType::Map(k, v) => write!(f, "map<{}, {}>", k.to_string(), v.to_string()),
FieldType::List(t) => write!(f, "{}[]", t.to_string()),
FieldType::Optional(t) => write!(f, "{}?", t.to_string()),
FieldType::Map(k, v) => write!(f, "map<{}, {}>", k, v),
FieldType::List(t) => write!(f, "{}[]", t),
FieldType::Optional(t) => write!(f, "{}?", t),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/baml-lib/baml/tests/parsing/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::common::*;
#[test]
fn trailing_comments_allowed_in_configuration_blocks() {
let schema = r#"
// This is a random commet
// This is a random comment

// Anther random comment
// But in a block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class TestLiterals {
}

// error: Type `True` does not exist. Did you mean one of these: `true`, `string`, `int`, `bool`, `false`, `float`, `TestLiterals`?
// --> class/misspeled_boolean_literals.baml:3
// --> class/misspelled_boolean_literals.baml:3
// |
// 2 | a "SingleLiteral"
// 3 | b "boolean" | True | False
// |
// error: Type `False` does not exist. Did you mean one of these: `false`, `float`, `true`, `int`, `bool`, `string`, `TestLiterals`?
// --> class/misspeled_boolean_literals.baml:3
// --> class/misspelled_boolean_literals.baml:3
// |
// 2 | a "SingleLiteral"
// 3 | b "boolean" | True | False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ client<llm> MyClient {
array_key_with_quoted_unquoted [ "abc", "abc", "ccc" ]
// separate by commas
key2 "some random value", hello "world", thing "hello"
block_string #"hello there my frien
block_string #"hello there my friend
d"#
inline_raw_string #"inline "raw" string,,"#
keyStringNoSpacesWorksWithoutQuotes NoQuotes!!123
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function InputEnum(color: Color) -> string {
prompt #" color {{ color }} "#
}

// Try it with wierd spacing and comments
// Try it with weird spacing and comments

function InputEnum2(
color: Color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function InputEnum(color: Color) -> string {
prompt #" color {{ color }} "#
}

// Try it with wierd spacing and comments
// Try it with weird spacing and comments

function InputEnum2(
color: Color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function InputEnum(color: Color) -> string {
prompt #" color {{ color }} "#
}

// Try it with wierd spacing and comments
// Try it with weird spacing and comments

function InputEnum2(
color: Color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function InputEnum(color: Color) -> string {
prompt #" color {{ color }} "#
}

// Try it with wierd spacing and comments
// Try it with weird spacing and comments

function InputEnum2(
color: Color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl IntoMiniJinjaValue for BamlValue {
// For enums and classes we compute the aliases from the IR, and generate custom jinja structs that print out the alias if stringified.
BamlValue::Enum(name, value) => {
minijinja::Value::from(value.clone())
// Until we can fix the broken test, just return the normal value. For now we wont suppport enum alias rendering.
// Until we can fix the broken test, just return the normal value. For now we wont support enum alias rendering.
// let mut alias: Option<String> = None;
// if let Ok(e) = ir.find_enum(name) {
// if let Some(enum_value) = e
Expand Down
2 changes: 1 addition & 1 deletion engine/baml-lib/jinja-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ mod render_tests {
}

// See the note in baml_value_to_jinja_value.rs for Enum for why we don't support aliases.
// tl;dr we don't havea way to override the equality operator for enum comparisons to NOT use the alias.
// tl;dr we don't have a way to override the equality operator for enum comparisons to NOT use the alias.
// #[test]
// fn test_render_prompt_with_enum() -> anyhow::Result<()> {
// setup_logging();
Expand Down
2 changes: 1 addition & 1 deletion engine/baml-lib/jinja/src/evaluate_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl TypeError {
)
};

Self { message: format!("{message}\n\nSee: https://docs.rs/minijinja/latest/minijinja/filters/index.html#functions for the compelete list"), span }
Self { message: format!("{message}\n\nSee: https://docs.rs/minijinja/latest/minijinja/filters/index.html#functions for the complete list"), span }
}

fn new_invalid_type(expr: &Expr, got: &Type, expected: &str, span: Span) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion engine/baml-lib/jinja/src/evaluate_type/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl PredefinedTypes {
};

// Any vars that are in both branches are merged
// Any vars that are only in one branch, unioned with undefined
// Any vars that are only in one branch, united with undefined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Any vars that are only in one branch, united with undefined
// Any vars that are only in one branch, unioned with undefined

"unioned" is technically an invalid word but is deliberately used here to reference type unions


let mut new_vars = HashMap::new();
for (name, t) in true_vars.iter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::any::Any;

use crate::deserializer::{deserialize_flags::Flag, types::BamlValueWithFlags};
use anyhow::Result;
use internal_baml_core::{ast::Field, ir::FieldType};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(super) fn coerce_optional(
Some(v) => match inner.coerce(ctx, optional_target, Some(v)) {
Ok(v) => Ok(v),
Err(e) => {
flags.add_flag(Flag::DefaultButHadUnparseableValue(e));
flags.add_flag(Flag::DefaultButHadUnparsableValue(e));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
flags.add_flag(Flag::DefaultButHadUnparsableValue(e));
flags.add_flag(Flag::DefaultButHadUnparseableValue(e));

both "parseable" and "parsable" are valid spellings, but the former will show up when grepping/searching for "parse"

Ok(BamlValueWithFlags::Null(flags))
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl DefaultValue for FieldType {
fn default_value(&self, error: Option<&ParsingError>) -> Option<BamlValueWithFlags> {
let get_flags = || {
DeserializerConditions::new().with_flag(error.map_or(Flag::DefaultFromNoValue, |e| {
Flag::DefaultButHadUnparseableValue(e.clone())
Flag::DefaultButHadUnparsableValue(e.clone())
}))
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl TypeCoercer for Class {
let parsed = match field.1.coerce(&scope, &field.1, Some(x)) {
Ok(mut v) => {
v.add_flag(Flag::ImpliedKey(field.0.real_name().into()));
flags.add_flag(Flag::InferedObject(x.clone()));
flags.add_flag(Flag::InferredObject(x.clone()));
Ok(v)
}
Err(e) => Err(e),
Expand Down Expand Up @@ -275,7 +275,7 @@ impl TypeCoercer for Class {
k.to_string(),
BamlValueWithFlags::Null(
DeserializerConditions::new()
.with_flag(Flag::DefaultButHadUnparseableValue(e)),
.with_flag(Flag::DefaultButHadUnparsableValue(e)),
),
),
}
Expand Down
10 changes: 5 additions & 5 deletions engine/baml-lib/jsonish/src/deserializer/coercer/match_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ pub(super) fn match_string(
}
};

// Trim whitespaces.
// Trim whitespace.
let match_context = jsonish_string.trim();

// First attempt, case sensitive match ignoring possible pucntuation.
// First attempt, case sensitive match ignoring possible punctuation.
if let Some(string_match) = string_match_strategy(&match_context, &candidates, &mut flags) {
return try_match_only_once(parsing_context, target, string_match, flags);
}
Expand Down Expand Up @@ -125,10 +125,10 @@ fn try_match_only_once(
/// Heuristic string match algorithm.
///
/// The algorithm is case sensitive so for case insensitive matches it must
/// recieve lowercase strings. This algorithm will first try to look for exact
/// receive lowercase strings. This algorithm will first try to look for exact
/// matches in the input string, if it doesn't find any it will look for
/// substring matches and return the one with the most matches. Whether that is
/// an ambigous match or not is up to the caller to decide.
/// an ambiguous match or not is up to the caller to decide.
fn string_match_strategy<'c>(
value_str: &str,
candidates: &'c [(&'c str, Vec<String>)],
Expand All @@ -148,7 +148,7 @@ fn string_match_strategy<'c>(
let match_count_pos = valid_names
.iter()
.filter_map(|valid_name| {
// Match ocurrences of valid name.
// Match occurrences of valid name.
let matches = value_str.match_indices(valid_name);
// Return (count, first_idx)
matches.fold(None, |acc, (idx, _)| match acc {
Expand Down
22 changes: 11 additions & 11 deletions engine/baml-lib/jsonish/src/deserializer/deserialize_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub enum Flag {
ObjectFromMarkdown(i32),
ObjectFromFixedJson(Vec<crate::jsonish::Fixes>),

DefaultButHadUnparseableValue(ParsingError),
DefaultButHadUnparsableValue(ParsingError),
ObjectToString(crate::jsonish::Value),
ObjectToPrimitive(crate::jsonish::Value),
ObjectToMap(crate::jsonish::Value),
Expand All @@ -20,7 +20,7 @@ pub enum Flag {

JsonToString(crate::jsonish::Value),
ImpliedKey(String),
InferedObject(crate::jsonish::Value),
InferredObject(crate::jsonish::Value),

// Values here are all the possible matches.
FirstMatch(usize, Vec<Result<BamlValueWithFlags, ParsingError>>),
Expand All @@ -32,15 +32,15 @@ pub enum Flag {
DefaultButHadValue(crate::jsonish::Value),
OptionalDefaultFromNoValue,

// String -> X convertions.
// String -> X conversions.
StringToBool(String),
StringToNull(String),
StringToChar(String),

// Number -> X convertions.
// Number -> X conversions.
FloatToInt(f64),

// X -> Object convertions.
// X -> Object conversions.
NoFields(Option<crate::jsonish::Value>),
}

Expand Down Expand Up @@ -77,7 +77,7 @@ impl DeserializerConditions {
}
Flag::JsonToString(_) => None,
Flag::ImpliedKey(_) => None,
Flag::InferedObject(_) => None,
Flag::InferredObject(_) => None,
Flag::FirstMatch(_idx, _) => None,
Flag::StrMatchOneFromMany(_matches) => None,
Flag::DefaultFromNoValue => None,
Expand All @@ -89,7 +89,7 @@ impl DeserializerConditions {
Flag::FloatToInt(_) => None,
Flag::NoFields(_) => None,
Flag::UnionMatch(_idx, _) => None,
Flag::DefaultButHadUnparseableValue(e) => Some(e.clone()),
Flag::DefaultButHadUnparsableValue(e) => Some(e.clone()),
})
.collect::<Vec<_>>()
}
Expand Down Expand Up @@ -119,8 +119,8 @@ impl std::fmt::Display for DeserializerConditions {
impl std::fmt::Display for Flag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Flag::InferedObject(value) => {
write!(f, "Infered object from: {}", value.r#type())?;
Flag::InferredObject(value) => {
write!(f, "Inferred object from: {}", value.r#type())?;
}
Flag::OptionalDefaultFromNoValue => {
write!(f, "Optional Default value")?;
Expand Down Expand Up @@ -165,8 +165,8 @@ impl std::fmt::Display for Flag {
writeln!(f, "Item {}: {}", idx, value)?;
}
}
Flag::DefaultButHadUnparseableValue(value) => {
write!(f, "Null but had unparseable value")?;
Flag::DefaultButHadUnparsableValue(value) => {
write!(f, "Null but had unparsable value")?;
Comment on lines +168 to +169
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unparseable

writeln!(f, "----RAW----")?;
writeln!(f, "{}", value)?;
writeln!(f, "-----------")?;
Expand Down
4 changes: 2 additions & 2 deletions engine/baml-lib/jsonish/src/deserializer/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ impl WithScore for BamlValueWithFlags {
impl WithScore for Flag {
fn score(&self) -> i32 {
match self {
Flag::InferedObject(_) => 0, // Dont penalize for this but instead handle it at the top level
Flag::InferredObject(_) => 0, // Don't penalize for this but instead handle it at the top level
Flag::OptionalDefaultFromNoValue => 1,
Flag::DefaultFromNoValue => 100,
Flag::DefaultButHadValue(_) => 110,
Flag::ObjectFromFixedJson(_) => 0,
Flag::ObjectFromMarkdown(s) => *s,
Flag::DefaultButHadUnparseableValue(_) => 2,
Flag::DefaultButHadUnparsableValue(_) => 2,
Flag::ObjectToMap(_) => 1,
Flag::ObjectToString(_) => 2,
Flag::ObjectToPrimitive(_) => 2,
Expand Down
Loading