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

semantic streaming #1293

Merged
merged 13 commits into from
Jan 29, 2025
Merged

semantic streaming #1293

merged 13 commits into from
Jan 29, 2025

Conversation

imalsogreg
Copy link
Contributor

@imalsogreg imalsogreg commented Jan 6, 2025

Add semantic streaming.

  • BAML syntax has new @stream.done, @stream.not_null and @stream.with_state attributes on fields, specifying how the fields behave during streaming.
  • SAP parser tracks each BamlValue node's completion state.
  • Runtime compares node streaming states against streaming behavior, dropping values where appropriate.
  • Client codegen produces modified types to match the invariants specified by the new attributes, and the respective FFIs target these new types.

Some tricky things about this PR:

  • We have to track more data in the BamlValue responses than we used to. We now have ResponseBamlValue to wrap BamlValueWithMeta<T> where T can hold all this extra data.
  • BamlValueWithMeta has a new distribute_type_with_meta method, which traverses a BamlValue in parallel with its FieldType. This traversal is the key thing that allows us to analyze each field of a nested BamlValue with respect to its expected streaming behavior. distribute_type_with_meta is conceptually simple but contains a number of difficult edge cases, especially when dealing with nested types and recursive type aliases.
  • While the old clients had a strict division between partial and complete types, the @stream.done annotation allows for the creation of types that combine parts from complete and partial codegen'd modules. The resulting Frankentypes are harder to target from the FFI. Functions like cast_to require visibility into both the complete and partial modules, and we have to thread allow_partials through the traversal of a BamlValue during serialization, and allow_partials may change when we reach a done node in an otherwise partial context.

Copy link

vercel bot commented Jan 6, 2025

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 Jan 28, 2025 11:15pm

@imalsogreg imalsogreg force-pushed the greg/semantic-streaming branch from c8d10ad to aab008a Compare January 7, 2025 20:23
@imalsogreg imalsogreg force-pushed the greg/semantic-streaming branch from 9f3d137 to c5875e8 Compare January 13, 2025 19:14
@imalsogreg imalsogreg force-pushed the greg/semantic-streaming branch from 7f691bd to 7b2d28b Compare January 18, 2025 16:05
@imalsogreg imalsogreg marked this pull request as ready for review January 28, 2025 22:20
Copy link
Contributor

ellipsis-dev bot commented Jan 28, 2025

⚠️ This PR is too big for Ellipsis, but support for larger PRs is coming soon. If you want us to prioritize this feature, let us know at [email protected]


Generated with ❤️ by ellipsis.dev

@imalsogreg imalsogreg added this pull request to the merge queue Jan 29, 2025
Merged via the queue into canary with commit e30bdd5 Jan 29, 2025
11 checks passed
@imalsogreg imalsogreg deleted the greg/semantic-streaming branch January 29, 2025 01:42
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.

1 participant