Skip to content

Commit

Permalink
Fix Python dynamic types example
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoh authored Sep 22, 2024
1 parent 93e2b9b commit df13aeb
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions docs/docs/calling-baml/dynamic-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,22 @@ 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')

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 })
# Now res might have the hobby property, which can be Soccer or Reading
print(res)
tb = TypeBuilder()
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())

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 df13aeb

Please sign in to comment.