-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate client docstrings from BAML source docstrings (#1177)
Pass BAML docstrings through to generated code. ## Examples For this baml code: ``` /// A Martian organism with an age. /// Such a nice type. class Martian { /// The age of the Martian in Mars years. /// So many Mars years. age int @check(young_enough, {{ this < 30 }}) } /// An enum with three values, /// ONE, TWO and THREE. enum EnumOutput { /// The first enum. ONE /// The second enum. TWO THREE @@alias("VALUE_ENUM") } ``` We get this python code: ``` class Martian(BaseModel): """A Martian organism with an age. Such a nice type.""" age: Checked[int,Literal["young_enough"]] """The age of the Martian in Mars years. So many Mars years.""" class EnumOutput(str, Enum): """An enum with three values, ONE, TWO and THREE.""" ONE = "ONE" """The first enum.""" TWO = "TWO" """The second enum.""" THREE = "THREE" ``` This typescript code: ``` /** * A Martian organism with an age. * Such a nice type. */ export interface Martian { /** * The age of the Martian in Mars years. * So many Mars years. */ age: Checked<number,"young_enough"> } /** * An enum with three values, * ONE, TWO and THREE. */ export enum EnumOutput { /** * The first enum. */ ONE = "ONE", /** * The second enum. */ TWO = "TWO", THREE = "THREE", } ``` And this Ruby code: ``` # A Martian organism with an age. # Such a nice type. class Martian < T::Struct include Baml::Sorbet::Struct # The age of the Martian in Mars years. # So many Mars years. const :age, Baml::Checked[Integer] def initialize(props) super( age: props[:age], ) @props = props end end class EnumOutput < T::Enum # An enum with three values, # ONE, TWO and THREE. enums do ONE = new("ONE") TWO = new("TWO") THREE = new("THREE") end end ``` Testing done: - python, ts, and ruby integ-tests - mouse hover on {class,field,enum,variant} gives nice intellisense in VSCode. <!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > This PR generates client docstrings from BAML source docstrings for Python, Ruby, and TypeScript by extracting and rendering them in generated code. > > - **Behavior**: > - Extracts docstrings from BAML source and includes them in generated client code for Python, Ruby, and TypeScript. > - Updates `Field` and `Class` structures in `repr.rs` to include `docstring` field. > - Adds `get_documentation()` method to `ClassWalker` and `FieldWalker` in `class.rs` and `field.rs`. > - **Templates**: > - Updates Python templates (`types.py.j2`, `partial_types.py.j2`) to render docstrings. > - Updates Ruby templates (`types.rb.j2`, `partial-types.rb.j2`) to render docstrings. > - Updates TypeScript templates (`types.ts.j2`) to render docstrings. > - **Tests**: > - Adds tests in `repr.rs` and `parse_schema.rs` to verify docstring extraction and rendering. > - Updates integration test files to include docstring examples. > - **Misc**: > - Makes `Comment` struct public in `comment.rs`. > - Updates `comments.mdx` to reflect docstring support. > > <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 50a607d. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information
1 parent
7689ce7
commit 170ece9
Showing
34 changed files
with
416 additions
and
1,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub(crate) struct Comment { | ||
pub struct Comment { | ||
pub text: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.