@@dynamic
The @@dynamic
attribute in BAML allows for the dynamic modification of fields or values at runtime. This is particularly useful when you need to adapt the structure of your data models based on runtime conditions or external inputs.
Usage
Dynamic Classes
The @@dynamic
attribute can be applied to classes, enabling the addition of fields dynamically during runtime.
BAML
Dynamic Enums
Similarly, the @@dynamic
attribute can be applied to enums, allowing for the modification of enum values at runtime.
BAML
Using @@dynamic
with TypeBuilder
To modify dynamic types at runtime, you can use the TypeBuilder
from the baml_client
. Below are examples for Python, TypeScript, and Ruby.