Skip to content

Commit 44346ae

Browse files
authored
docs: update all docs with bun and deno (#1736)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Update documentation to include `bun` and `deno` instructions for BAML setup and usage. > > - **Documentation Updates**: > - Add `bun` and `deno` instructions for installing BAML in `typescript.mdx` and `01-quick-start.mdx`. > - Update `generate.mdx` and `install/nodejs.mdx` snippets to include `bun` and `deno` commands. > - **Code Examples**: > - Modify TypeScript import paths in `typescript.mdx` for consistency. > - Update `Example` and `ExampleStream` functions to return `Promise<Resume>` in `typescript.mdx`. > > <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 bfc6170. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 5ab2c3e commit 44346ae

4 files changed

Lines changed: 95 additions & 30 deletions

File tree

fern/01-guide/02-languages/typescript.mdx

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ To set up BAML with Typescript do the following:
99
- syntax highlighting
1010
- testing playground
1111
- prompt previews
12-
12+
1313
### Install BAML
1414
<CodeBlocks>
1515
```bash npm
1616
npm install @boundaryml/baml
1717
```
18-
18+
1919
```bash pnpm
2020
pnpm add @boundaryml/baml
2121
```
@@ -24,19 +24,23 @@ To set up BAML with Typescript do the following:
2424
yarn add @boundaryml/baml
2525
```
2626

27+
```bash bun
28+
bun add @boundaryml/baml
29+
```
30+
2731
```bash deno
2832
deno install npm:@boundaryml/baml
2933
```
3034
</CodeBlocks>
31-
35+
3236
### Add BAML to your existing project
3337
This will give you some starter BAML code in a `baml_src` directory.
34-
38+
3539
<CodeBlocks>
3640
```bash npm
3741
npx baml-cli init
3842
```
39-
43+
4044
```bash pnpm
4145
pnpm exec baml-cli init
4246
```
@@ -45,29 +49,48 @@ To set up BAML with Typescript do the following:
4549
yarn baml-cli init
4650
```
4751

52+
```bash bun
53+
bun baml-cli init
54+
```
55+
4856
```bash deno
4957
deno run -A npm:@boundaryml/baml/baml-cli init
5058
```
5159
</CodeBlocks>
52-
60+
5361
### Generate the `baml_client` typescript package from `.baml` files
5462

5563
One of the files in your `baml_src` directory will have a [generator block](/ref/baml/generator). This tells BAML how to generate the `baml_client` directory, which will have auto-generated typescript code to call your BAML functions.
5664

57-
```bash
58-
npx baml-cli generate
59-
```
60-
```bash deno
61-
deno run --unstable-sloppy-imports -A npm:@boundaryml/baml/baml-cli generate
62-
# Note: ESM is especially important for Deno, so you must explicitly
63-
# allow our Node import style, with the `--unstable-sloppy-imports` flag
64-
# and in your Deno VSCode configuration:
65-
#
66-
# {
67-
# "deno.unstable": ["sloppy-imports"]
68-
# }
69-
70-
```
65+
<CodeBlocks>
66+
```bash npm
67+
npx baml-cli generate
68+
```
69+
70+
```bash pnpm
71+
pnpm exec baml-cli generate
72+
```
73+
74+
```bash yarn
75+
yarn baml-cli generate
76+
```
77+
78+
```bash bun
79+
bun baml-cli generate
80+
```
81+
82+
```bash deno
83+
deno run --unstable-sloppy-imports -A npm:@boundaryml/baml/baml-cli generate
84+
# Note: ESM is especially important for Deno, so you must explicitly
85+
# allow our Node import style, with the `--unstable-sloppy-imports` flag
86+
# and in your Deno VSCode configuration:
87+
#
88+
# {
89+
# "deno.unstable": ["sloppy-imports"]
90+
# }
91+
92+
```
93+
</CodeBlocks>
7194

7295
You can modify your `package.json` so you have a helper prefix in front of your build command.
7396

@@ -81,44 +104,44 @@ To set up BAML with Typescript do the following:
81104
}
82105
}
83106
```
84-
107+
85108
See [What is baml_src](/guide/introduction/baml_src) to learn more about how this works.
86109
<img src="/assets/languages/baml-to-ts.png" />
87110

88-
111+
89112
<Tip>
90113
If you set up the [VSCode extension](https://marketplace.visualstudio.com/items?itemName=Boundary.baml-extension), it will automatically run `baml-cli generate` on saving a BAML file.
91114
</Tip>
92-
115+
93116
### Use a BAML function in Typescript!
94117
<Error>If `baml_client` doesn't exist, make sure to run the previous step! </Error>
95118

96119
<CodeBlocks>
97120
```typescript index.ts
98-
import {b} from "baml_client"
99-
import type {Resume} from "baml_client/types"
121+
import { b } from "./baml_client"
122+
import type { Resume } from "./baml_client/types"
100123

101-
async function Example(raw_resume: string): Resume {
124+
async function Example(raw_resume: string): Promise<Resume> {
102125
// BAML's internal parser guarantees ExtractResume
103126
// to be always return a Resume type
104127
const response = await b.ExtractResume(raw_resume);
105128
return response;
106129
}
107130

108-
async function ExampleStream(raw_resume: string): Resume {
131+
async function ExampleStream(raw_resume: string): Promise<Resume> {
109132
const stream = b.stream.ExtractResume(raw_resume);
110133
for await (const msg of stream) {
111134
console.log(msg) // This will be a Partial<Resume> type
112135
}
113136

114137
// This is guaranteed to be a Resume type.
115-
return await stream.get_final_response();
138+
return await stream.getFinalResponse();
116139
}
117140
```
118141

119142
```typescript sync_example.ts
120-
import {b} from "baml_client/sync_client"
121-
import type {Resume} from "baml_client/types"
143+
import { b } from "./baml_client/sync_client"
144+
import type { Resume } from "./baml_client/types"
122145

123146
function Example(raw_resume: string): Resume {
124147
// BAML's internal parser guarantees ExtractResume

fern/01-guide/08-frameworks/01-react-nextjs/01-quick-start.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ function WriteMeAStory(input: string) -> Story {
3131

3232
```bash title="Generate BAML client"
3333
npx baml-cli generate
34+
35+
pnpm exec baml-cli generate
36+
37+
yarn baml-cli generate
38+
39+
bun baml-cli generate
40+
41+
deno run --unstable-sloppy-imports -A npm:@boundaryml/baml/baml-cli generate
3442
```
3543

3644
```tsx title="app/components/story-form.tsx" {8,10,15-16}
@@ -84,6 +92,15 @@ pnpm create next-app my-baml-app
8492
```bash yarn
8593
yarn create next-app my-baml-app
8694
```
95+
96+
```bash bun
97+
bun create next-app my-baml-app
98+
```
99+
100+
```bash deno
101+
deno create next-app my-baml-app
102+
```
103+
87104
</CodeBlocks>
88105

89106
When prompted, make sure to:
@@ -107,6 +124,15 @@ pnpm add @boundaryml/baml @boundaryml/baml-nextjs-plugin
107124
```bash yarn
108125
yarn add @boundaryml/baml @boundaryml/baml-nextjs-plugin
109126
```
127+
128+
```bash bun
129+
bun add @boundaryml/baml @boundaryml/baml-nextjs-plugin
130+
```
131+
132+
```bash deno
133+
deno add @boundaryml/baml @boundaryml/baml-nextjs-plugin
134+
```
135+
110136
</CodeBlocks>
111137

112138
### Configure Next.js

fern/snippets/baml/cli/generate.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ pnpm exec baml-cli generate
1010
```bash yarn
1111
yarn baml-cli generate
1212
```
13+
14+
```bash bun
15+
bun baml-cli generate
16+
```
17+
18+
```bash deno
19+
deno run --unstable-sloppy-imports -A npm:@boundaryml/baml/baml-cli generate
20+
```
1321
</CodeBlocks>

fern/snippets/baml/cli/install/nodejs.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ pnpm exec baml-cli init
1010
```bash yarn
1111
yarn baml-cli init
1212
```
13+
14+
```bash bun
15+
bun baml-cli init
16+
```
17+
18+
```bash deno
19+
deno run --unstable-sloppy-imports -A npm:@boundaryml/baml/baml-cli init
20+
```
1321
</CodeBlocks>

0 commit comments

Comments
 (0)