-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
326 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
title: "BAML in 2 minutes" | ||
url: "/docs/guides/hello_world/writing-ai-functions" | ||
url: "docs/guides/hello_world/writing-ai-functions" | ||
--- |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: "Interactive Demo" | ||
--- | ||
|
||
## Interactive playground | ||
You can try BAML online over at [Prompt Fiddle](https://www.promptfiddle.com) | ||
|
||
|
||
## Examples built with BAML | ||
|
||
You can find the code here: https://github.com/BoundaryML/baml-examples/tree/main/nextjs-starter | ||
|
||
|
||
| Example | Link | | ||
| - | - | | ||
| Streaming Simple Objects | https://baml-examples.vercel.app/examples/stream-object | | ||
| RAG + Citations | https://baml-examples.vercel.app/examples/rag | | ||
| Generative UI / Streaming charts | https://baml-examples.vercel.app/examples/book-analyzer | | ||
| Getting a recipe | https://baml-examples.vercel.app/examples/get-recipe | |
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: "Typescript Installation" | ||
--- | ||
|
||
Here's a sample repository: | ||
https://github.com/BoundaryML/baml-examples/tree/main/nextjs-starter | ||
|
||
To set up BAML in typescript do the following: | ||
|
||
<Steps> | ||
<Step title="Install BAML VSCode Extension"> | ||
https://marketplace.visualstudio.com/items?itemName=boundary.BAML | ||
|
||
- syntax highlighting | ||
- testing playground | ||
- prompt previews | ||
</Step> | ||
<Step title="Install baml"> | ||
<CodeGroup> | ||
```bash npm | ||
npm install @boundaryml/baml | ||
``` | ||
|
||
```bash pnpm | ||
pnpm add @boundaryml/baml | ||
``` | ||
|
||
```bash yarn | ||
yarn add @boundaryml/baml | ||
``` | ||
</CodeGroup> | ||
</Step> | ||
<Step title="Add some starter code"> | ||
This will give you some starter BAML code in a `baml_src` directory. | ||
<CodeGroup> | ||
```bash npm | ||
npx baml-cli init | ||
``` | ||
|
||
```bash pnpm | ||
pnpx baml-cli init | ||
``` | ||
|
||
```bash yarn | ||
yarn baml-cli init | ||
``` | ||
</CodeGroup> | ||
</Step> | ||
<Step title="Update your package.json"> | ||
|
||
This command will help you convert `.baml` files to `.ts` files. Everytime you modify your `.baml` files, | ||
you must re-run this command, and regenerate the `baml_client` folder. | ||
|
||
<Tip> | ||
If you download our [VSCode extension](https://marketplace.visualstudio.com/items?itemName=Boundary.baml-extension), it will automatically generate `baml_client` on save! | ||
</Tip> | ||
|
||
```json package.json | ||
{ | ||
"scripts": { | ||
// Add a new command | ||
"baml-generate": "baml-cli generate", | ||
// Always call baml-generate on every build. | ||
"build": "npm run baml-generate && tsc --build", | ||
} | ||
} | ||
``` | ||
</Step> | ||
<Step title="Use a baml function in typescript!"> | ||
<Tip>If `baml_client` doesn't exist, make sure to run `npm run baml-generate`</Tip> | ||
|
||
```typescript index.ts | ||
import {b} from "baml_client" | ||
import type {Resume} from "baml_client/types" | ||
|
||
async function Example(raw_resume: string): Resume { | ||
// BAML's internal parser guarantees ExtractResume | ||
// to be always return a Resume type | ||
const response = await b.ExtractResume(raw_resume); | ||
return response; | ||
} | ||
|
||
async function ExampleStream(raw_resume: string): Resume { | ||
const stream = b.stream.ExtractResume(raw_resume); | ||
for await (const msg of stream) { | ||
console.log(msg) // This will be a Partial<Resume> type | ||
} | ||
|
||
// This is guaranteed to be a Resume type. | ||
return await stream.get_final_response(); | ||
} | ||
``` | ||
</Step> | ||
</Steps> |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
title: "Python Installation" | ||
--- | ||
|
||
Here's a sample repository: | ||
https://github.com/BoundaryML/baml-examples/tree/main/python-fastapi-starter | ||
|
||
To set up BAML in typescript do the following: | ||
|
||
<Steps> | ||
<Step title="Install BAML VSCode Extension"> | ||
https://marketplace.visualstudio.com/items?itemName=boundary.BAML | ||
|
||
- syntax highlighting | ||
- testing playground | ||
- prompt previews | ||
|
||
<Tip> | ||
In your VSCode User Settings, highly recommend adding this to get better autocomplete for python in general, not just BAML. | ||
|
||
```json | ||
{ | ||
"python.analysis.typeCheckingMode": "basic" | ||
} | ||
``` | ||
</Tip> | ||
</Step> | ||
<Step title="Install baml"> | ||
```bash | ||
pip install baml-py | ||
``` | ||
</Step> | ||
<Step title="Add some starter code"> | ||
This will give you some starter BAML code in a `baml_src` directory. | ||
|
||
```bash | ||
baml-cli init | ||
``` | ||
</Step> | ||
<Step title="Generate python code from .baml files"> | ||
|
||
This command will help you convert `.baml` files to `.py` files. Everytime you modify your `.baml` files, | ||
you must re-run this command, and regenerate the `baml_client` folder. | ||
|
||
<Tip> | ||
If you download our [VSCode extension](https://marketplace.visualstudio.com/items?itemName=Boundary.baml-extension), it will automatically generate `baml_client` on save! | ||
</Tip> | ||
|
||
```bash | ||
baml-cli generate | ||
``` | ||
</Step> | ||
<Step title="Use a baml function in python!"> | ||
<Tip>If `baml_client` doesn't exist, make sure to run the previous step!</Tip> | ||
|
||
```python main.py | ||
from baml_client import b | ||
from baml_client.types import Resume | ||
|
||
async def example(raw_resume: str) -> Resume: | ||
# BAML's internal parser guarantees ExtractResume | ||
# to be always return a Resume type | ||
response = await b.ExtractResume(raw_resume) | ||
return response | ||
|
||
async def example_stream(raw_resume: str) -> Resume: | ||
stream = b.stream.ExtractResume(raw_resume) | ||
async for msg in stream: | ||
print(msg) # This will be a PartialResume type | ||
|
||
# This will be a Resume type | ||
final = stream.get_final_response() | ||
|
||
return final | ||
``` | ||
</Step> | ||
</Steps> |
Oops, something went wrong.