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

Improve BAML Parser #785

Merged
merged 2 commits into from
Jul 15, 2024
Merged

Improve BAML Parser #785

merged 2 commits into from
Jul 15, 2024

Conversation

hellovai
Copy link
Contributor

@hellovai hellovai commented Jul 14, 2024

  • Support parsing fractions as numbers (LLMs tend to like this for fractions, especially repeating values). 1/3 -> 0.33 (Fixes Parsing Issue with fractions #782)
  • Better parsing of objects of single keys:
    If the schema is { foo: { bar: string }}
    These all will parse into that:
{ bar: "..." }
{ foo: { bar: "..." }}

"..." will not auto parse into { foo: { bar: "..." }}

If the schema is { foo: { bar: int }}
These all will parse into that:

{ bar: 123 }
{ foo: { bar: 123 }}
123

"... 123 ..." will not parse into { foo: { bar: int }}

  • support "," with trailing spaces in parser. Infer as end of key. Sometimes LLMs will use ", " token instead of "," token.

* Support parsing fractions as numbers (LLMs tend to like this for fractions, especially repeating values). 1/3 -> 0.33
* Better parsing of objects of single keys:
If the schema is { foo: { bar: string }}
These all will parse into that:
{ bar: "..." }
{ foo: { bar: "..." }}
"..." will not auto parse into { foo: { bar: "..." }}
* support "," with trailing spaces in parser. Infer as end of key. Sometimes LLMs will use ", " token instead of "," token.
Copy link

vercel bot commented Jul 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2024 11:46pm

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Added support for parsing fractions as numbers (engine/baml-lib/jsonish/src/deserializer/coercer/coerce_primitive.rs)
  • Improved handling of objects with single keys (engine/baml-lib/jsonish/src/deserializer/coercer/ir_ref/coerce_class.rs)
  • Introduced InferedObject flag and related methods (engine/baml-lib/jsonish/src/deserializer/deserialize_flags.rs)
  • Enhanced handling of trailing spaces after commas (engine/baml-lib/jsonish/src/jsonish/parser/fixing_parser/json_parse_state.rs)
  • Added new test cases for fractions, single keys, and trailing commas (engine/baml-lib/jsonish/src/tests/test_basics.rs, engine/baml-lib/jsonish/src/tests/test_class.rs)

11 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

if v.conditions()
.flags()
.iter()
.any(|f| matches!(f, Flag::InferedObject(jsonish::Value::String(_))))
Copy link

Choose a reason for hiding this comment

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

Spelling: Typo in Flag::InferedObject. Should be Flag::InferredObject.

Suggested change
.any(|f| matches!(f, Flag::InferedObject(jsonish::Value::String(_))))
.any(|f| matches!(f, Flag::InferredObject(jsonish::Value::String(_))))

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Updated docs/README.md to use Fern instead of Mintlify
  • Added docs/assets/styles.css for CSS styling updates
  • Introduced docs/docs.yml for improved documentation structure
  • Modified multiple .mdx files to add slugs, update code block identifiers, and improve formatting
  • Removed docs/mint.json and docs/v3/analytics/overview.mdx files

67 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@hellovai hellovai merged commit c5af7b0 into canary Jul 15, 2024
9 checks passed
@hellovai hellovai deleted the parser-fixes branch July 15, 2024 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing Issue with fractions
1 participant