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

WIP: Add support for int keys in maps #1180

Draft
wants to merge 8 commits into
base: canary
Choose a base branch
from

Conversation

antoniosarosi
Copy link
Contributor

WIP, some ideas to implement int keys:

  1. Parse strings and carry the type of the key in BamlValue::Map.
  2. Use BamlMapKey enum everywhere.
  3. Some combination of the previous two.

The FFI code that converts BamlValue back to Python or other targets needs the information
about the type of the key, which is not currently provided by BamlValue::Map. But then BamlValue::Map is also used for converting JSONs from LLMs into classes or similar operations, basically the runtime is designed around maps supporting string keys only.

Copy link

vercel bot commented Nov 19, 2024

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

Name Status Preview Comments Updated (UTC)
baml ❌ Failed (Inspect) Nov 19, 2024 3:57am

github-merge-queue bot pushed a commit that referenced this pull request Nov 19, 2024
Issue #1050

Added support for enums and literal strings in map keys:

```baml
enum MapKey {
  A
  B
  C
}

class Fields {
  // Enum as key
  e map<MapKey, string>
  // Single literal as key
  l1 map<"literal", string>
  // Union of literals as keys
  l2 map<"one" | "two" | ("three" | "four"), string>
}
``` 

Literal integers are more complicated since they require maps to support
int keys. See #1180.
<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Add support for enums and literal strings as map keys in BAML, with
updated validation, coercion logic, and tests.
> 
>   - **Behavior**:
> - Support for enums and literal strings as map keys added in `mod.rs`
and `types.rs`.
> - Validation logic updated to allow enums and literal strings as map
keys.
> - Coercion logic updated to handle enums and literal strings as map
keys.
>   - **Tests**:
> - Added tests in `map_enums_and_literals.baml` and `map_types.baml` to
verify new map key functionality.
> - Updated `test_functions.py` and `integ-tests.test.ts` to include
cases for enum and literal string map keys.
>   - **Misc**:
> - Updated error messages in `error.rs` to reflect new map key types.
> - Minor updates in `async_client.py`, `sync_client.py`, and
`client.rb` to support new map key types.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for c7742fd. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
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