Skip to content

Commit

Permalink
chore: BoundaryML#1086 clean up unused imports, fix typos, and organi…
Browse files Browse the repository at this point in the history
…ze style

- removed unused imports

- fixed typos in code and comments

- reorganized function for improved readability and style
  • Loading branch information
miguelcsx committed Oct 23, 2024
1 parent fa200b2 commit 825d39e
Show file tree
Hide file tree
Showing 86 changed files with 213 additions and 221 deletions.
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
2 changes: 1 addition & 1 deletion engine/baml-lib/baml-core/src/ir/ir_helpers/to_baml_arg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use baml_types::{BamlMap, BamlMediaType, BamlValue, FieldType, LiteralValue, TypeValue};
use baml_types::{BamlMap, BamlValue, FieldType, LiteralValue, TypeValue};
use core::result::Result;
use std::path::PathBuf;

Expand Down
1 change: 0 additions & 1 deletion engine/baml-lib/baml-core/src/ir/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use baml_types::TypeValue;
use serde_json::json;

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

Expand Down
8 changes: 4 additions & 4 deletions engine/baml-lib/baml-core/src/ir/repr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, Result};
use baml_types::FieldType;
use either::Either;
use indexmap::IndexMap;
Expand Down 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/chat_message_part.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;

use baml_types::{BamlMedia, BamlMediaContent};
use serde::Serialize;
Expand Down
6 changes: 3 additions & 3 deletions engine/baml-lib/jinja-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use output_format::types;
mod baml_value_to_jinja_value;

use minijinja::{self, value::Kwargs};
use minijinja::{context, ErrorKind, Value};
use minijinja::{context, ErrorKind};
use output_format::types::OutputFormatContent;
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down Expand Up @@ -463,7 +463,7 @@ mod render_tests {

pub fn make_test_ir(source_code: &str) -> anyhow::Result<IntermediateRepr> {
use internal_baml_core::validate;
use internal_baml_core::{Configuration, ValidatedSchema};
use internal_baml_core::ValidatedSchema;
use internal_baml_diagnostics::SourceFile;
use std::path::PathBuf;
let path: PathBuf = "fake_file.baml".into();
Expand Down 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

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,8 +1,6 @@
use std::any::Any;

use crate::deserializer::{deserialize_flags::Flag, types::BamlValueWithFlags};
use anyhow::Result;
use internal_baml_core::{ast::Field, ir::FieldType};
use internal_baml_core::ir::FieldType;

use super::{ParsingContext, ParsingError};

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));
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
Loading

0 comments on commit 825d39e

Please sign in to comment.