Skip to content

Commit

Permalink
docs: Fix Python dynamic types example (#979)
Browse files Browse the repository at this point in the history
Stumbled upon this broken example in the documentation. This:

- removes the `const` declaration 
- uses `snake_case` variable names
- imports the async client so that the example runs without
modifications

Related but not changed here: if copied as is (with the fixes), the
example will throw a `BamlValidationError` since the input `"some user
info"` doesn't contain the needed information. Replacing that with a
sentence like "Bill (16) plays soccer in Germany" will lead to a valid
output. Happy to pull up a patch for that as well if you want.
  • Loading branch information
lorenzoh authored Sep 24, 2024
1 parent adbb6ae commit eade116
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/docs/calling-baml/dynamic-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ Here we create a new `Hobbies` enum, and a new class called `Address`.

```python Python
from baml_client.type_builder import TypeBuilder
from baml_client import b
from baml_client.async_client import b

async def run():
tb = TypeBuilder()
const hobbiesEnum = tb.add_enum('Hobbies')
hobbiesEnum.add_value('Soccer')
hobbiesEnum.add_value('Reading')
hobbies_enum = tb.add_enum("Hobbies")
hobbies_enum.add_value("Soccer")
hobbies_enum.add_value("Reading")

address_class = tb.add_class('Address')
address_class.add_property('street', tb.string())
address_class = tb.add_class("Address")
address_class.add_property("street", tb.string())

tb.User.add_property('hobby', hobbiesEnum.type().optional())
tb.User.add_property('address', addressClass.type().optional())
res = await b.DynamicUserCreator("some user info", { "tb": tb })
tb.User.add_property("hobby", hobbies_enum.type().optional())
tb.User.add_property("address", address_class.type().optional())
res = await b.DynamicUserCreator("some user info", {"tb": tb})
# Now res might have the hobby property, which can be Soccer or Reading
print(res)

Expand Down

0 comments on commit eade116

Please sign in to comment.