Skip to content

Commit 55e9d9d

Browse files
authored
feat: move REST API out of preview (#1818)
Fix #1765 <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Removes `--preview` flag from BAML CLI, stabilizing REST API, and updates related documentation, tests, and build scripts. > > - **Behavior**: > - Removes `--preview` flag from `DevArgs` in `dev.rs` and `ServeArgs` in `serve/mod.rs`, making REST API stable by default. > - Removes associated warnings and error messages related to the `--preview` flag in `dev.rs` and `serve/mod.rs`. > - **Documentation**: > - Updates `dev.mdx` and `serve.mdx` to remove references to the `--preview` flag and preview warnings. > - **Testing**: > - Adds a print statement in `test_streaming()` in `test_functions.py` for debugging. > - **Dependencies**: > - Adds `types-assertpy` to `uv.lock` for type checking in tests. > - **Build Script**: > - Updates `tools/build` to run specific tests in `test_functions.py` when in test mode. > > <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 d176229. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 5c3794a commit 55e9d9d

7 files changed

Lines changed: 74 additions & 127 deletions

File tree

engine/baml-runtime/src/cli/dev.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,10 @@ pub struct DevArgs {
1414
pub from: PathBuf,
1515
#[arg(long, help = "port to expose BAML on", default_value = "2024")]
1616
port: u16,
17-
#[arg(long, help = "turn on preview features", default_value = "false")]
18-
preview: bool,
1917
}
2018

2119
impl DevArgs {
2220
pub fn run(&self, defaults: crate::RuntimeCliDefaults) -> Result<()> {
23-
if !self.preview {
24-
log::warn!(
25-
r#"Development mode is a preview feature.
26-
27-
Please run with --preview, like so:
28-
29-
{} dev --preview
30-
31-
Please provide feedback and let us know if you run into any issues:
32-
33-
- join our Discord at https://docs.boundaryml.com/discord, or
34-
- comment on https://github.com/BoundaryML/baml/issues/892
35-
36-
We expect to stabilize this feature over the next few weeks, but we need
37-
your feedback to do so.
38-
39-
Thanks for trying out BAML!
40-
"#,
41-
if matches!(
42-
std::env::var("npm_lifecycle_event").ok().as_deref(),
43-
Some("npx")
44-
) {
45-
"npx @boundaryml/baml"
46-
} else {
47-
"baml-cli"
48-
}
49-
);
50-
anyhow::bail!("--preview is not set")
51-
}
5221
baml_log::info!("Starting BAML development server on port {}", self.port);
5322

5423
let t = BamlRuntime::get_tokio_singleton()?;
@@ -75,21 +44,6 @@ Thanks for trying out BAML!
7544

7645
// print all events and errors
7746
t.block_on(async {
78-
log::warn!(
79-
r#"Development mode is a preview feature.
80-
81-
Please provide feedback and let us know if you run into any issues:
82-
83-
- join our Discord at https://docs.boundaryml.com/discord, or
84-
- comment on https://github.com/BoundaryML/baml/issues/892
85-
86-
We expect to stabilize this feature over the next few weeks, but we need
87-
your feedback to do so.
88-
89-
Thanks for trying out BAML!
90-
"#
91-
);
92-
9347
for result in rx {
9448
match result {
9549
Ok(events) => {

engine/baml-runtime/src/cli/serve/mod.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ pub struct ServeArgs {
4747
pub from: PathBuf,
4848
#[arg(long, help = "port to expose BAML on", default_value = "2024")]
4949
port: u16,
50-
#[arg(long, help = "turn on preview features", default_value = "false")]
51-
preview: bool,
5250
#[arg(
5351
long,
5452
help = "Generate baml_client without checking for version mismatch",
@@ -64,51 +62,6 @@ pub struct BamlOptions {
6462

6563
impl ServeArgs {
6664
pub fn run(&self) -> Result<()> {
67-
if !self.preview {
68-
log::warn!(
69-
r#"BAML-over-HTTP API is a preview feature.
70-
71-
Please run with --preview, like so:
72-
73-
{} serve --preview
74-
75-
Please provide feedback and let us know if you run into any issues:
76-
77-
- join our Discord at https://docs.boundaryml.com/discord, or
78-
- comment on https://github.com/BoundaryML/baml/issues/892
79-
80-
We expect to stabilize this feature over the next few weeks, but we need
81-
your feedback to do so.
82-
83-
Thanks for trying out BAML!
84-
"#,
85-
if matches!(
86-
std::env::var("npm_lifecycle_event").ok().as_deref(),
87-
Some("npx")
88-
) {
89-
"npx @boundaryml/baml"
90-
} else {
91-
"baml-cli"
92-
}
93-
);
94-
anyhow::bail!("--preview is not set")
95-
}
96-
97-
log::warn!(
98-
r#"BAML-over-HTTP is a preview feature.
99-
100-
Please provide feedback and let us know if you run into any issues:
101-
102-
- join our Discord at https://docs.boundaryml.com/discord, or
103-
- comment on https://github.com/BoundaryML/baml/issues/892
104-
105-
We expect to stabilize this feature over the next few weeks, but we need
106-
your feedback to do so.
107-
108-
Thanks for trying out BAML!
109-
"#
110-
);
111-
11265
let t: Arc<tokio::runtime::Runtime> = BamlRuntime::get_tokio_singleton()?;
11366

11467
let (server, tcp_listener) = t.block_on(Server::new(self.from.clone(), self.port))?;
@@ -229,7 +182,7 @@ impl Server {
229182
};
230183

231184
if !password.starts_with("sk-baml") {
232-
log::warn!("We recommend using BAML_PASSWORD=sk-baml-... so that static analysis tools can detect if you accidentally commit and push your password.")
185+
baml_log::warn!("We recommend using BAML_PASSWORD=sk-baml-... so that static analysis tools can detect if you accidentally commit and push your password.")
233186
}
234187

235188
if let Some(XBamlApiKey(baml_api_key)) = baml_api_key {

fern/03-reference/baml-cli/dev.mdx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
The `dev` command starts a development server that watches your BAML source files for changes and automatically reloads the BAML runtime. This feature is designed to streamline the development process by providing real-time updates as you modify your BAML configurations.
2-
3-
4-
<Warning>
5-
**Warning: Preview Feature**
6-
7-
1. You must include the `--preview` flag when running the `dev` command.
8-
2. Be aware that this feature is still being stabilized and may change in future releases.
9-
</Warning>
1+
The `dev` command starts a development server that watches your BAML source
2+
files for changes and automatically reloads the BAML runtime. This feature is
3+
designed to streamline the development process by providing real-time updates as
4+
you modify your BAML configurations.
105

116
## Usage
127

138
```
14-
baml-cli dev [OPTIONS] --preview
9+
baml-cli dev [OPTIONS]
1510
```
1611

1712
## Details

fern/03-reference/baml-cli/serve.mdx

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
The `serve` command starts a BAML-over-HTTP API server that exposes your BAML functions via HTTP endpoints. This feature allows you to interact with your BAML functions through a RESTful API interface.
2-
3-
<Warning>
4-
**Warning: Preview Feature**
5-
6-
1. You must include the `--preview` flag when running the `dev` command.
7-
2. Be aware that this feature is still being stabilized and may change in future releases.
8-
</Warning>
1+
The `serve` command starts a BAML-over-HTTP API server that exposes your BAML
2+
functions via HTTP endpoints. This feature allows you to interact with your BAML
3+
functions through a RESTful API interface.
94

105
## Usage
116

127
```
13-
baml-cli serve [OPTIONS] --preview
8+
baml-cli serve [OPTIONS]
149
```
1510

1611
<Tip>
17-
If you're actively developing, you can use the `dev` command to include hotreload functionality:
12+
If you're actively developing, you can use the `dev` command to include
13+
hot-reload functionality:
1814
```
19-
baml-cli dev [OPTIONS] --preview
15+
baml-cli dev [OPTIONS]
2016
```
2117

2218
[See more](./dev)
@@ -29,7 +25,6 @@ baml-cli dev [OPTIONS] --preview
2925
| `--from <PATH>` | Path to the `baml_src` directory | `./baml_src` |
3026
| `--port <PORT>` | Port to expose BAML on | `2024` |
3127
| `--no-version-check` | Generate `baml_client` without checking for version mismatch | `false` |
32-
| `--preview` | Enable the preview feature | |
3328

3429
## Description
3530

@@ -41,14 +36,43 @@ The `serve` command performs the following actions:
4136
## Endpoints
4237

4338

44-
- `POST /call/:function_name`: Call a BAML function
39+
`POST /call/:function_name`: Call a BAML function
40+
41+
```bash curl
42+
curl \
43+
-X POST \
44+
"http://localhost:2024/call/MyFunctionName" \
45+
-H "Content-Type: application/json" \
46+
-d '{"arg1": "value1", "arg2": "value2"}'
47+
```
48+
49+
`POST /stream/:function_name`: Stream results from a BAML function
50+
51+
```bash curl
52+
curl \
53+
-X POST \
54+
"http://localhost:2024/stream/MyFunctionName" \
55+
-H "Content-Type: application/json" \
56+
-d '{"arg1": "value1", "arg2": "value2"}'
57+
```
4558

4659
**Debugging**
4760
- `GET /docs`: Interactive API documentation (Swagger UI)
4861
- `GET /openapi.json`: OpenAPI specification for the BAML functions
4962
- `GET /_debug/ping`: Health check endpoint
5063
- `GET /_debug/status`: Server status and authentication check
5164

65+
## Stability
66+
67+
`baml-cli serve` is currently in Tier 2 stability. This means that the CLI and
68+
the HTTP APIs are stable, but there are a number of features which are
69+
not yet available:
70+
71+
- the [TypeBuilder API](/ref/baml_client/type-builder)
72+
- the [Collector API](/guide/baml-advanced/collector-track-tokens)
73+
- the [Modular API](/guide/baml-advanced/modular-api)
74+
- custom trace annotations for [Boundary Studio](/guide/boundary-cloud/observability/tracking-usage)
75+
5276
## Authentication
5377

5478
We support the header: `x-baml-api-key`
@@ -78,12 +102,19 @@ To test the server, you can use the following `curl` commands:
78102

79103
2. Call a function:
80104
```bash
81-
curl -X POST http://localhost:2024/call/MyFunctionName -d '{"arg1": "value1", "arg2": "value2"}'
105+
curl -X POST \
106+
http://localhost:2024/call/MyFunctionName \
107+
-H "Content-Type: application/json" \
108+
-d '{"arg1": "value1", "arg2": "value2"}'
82109
```
83110

84111
```bash API Key
85-
curl -X POST http://localhost:2024/call/MyFunctionName -H "x-baml-api-key: ${BAML_PASSWORD}" -d '{"arg1": "value1", "arg2": "value2"}'
86-
```
112+
curl -X POST \
113+
http://localhost:2024/call/MyFunctionName \
114+
-H "Content-Type: application/json" \
115+
-H "x-baml-api-key: ${BAML_PASSWORD}" \
116+
-d '{"arg1": "value1", "arg2": "value2"}'
117+
```
87118

88119
3. Access the API documentation:
89120
Open `http://localhost:2024/docs` in your web browser.

integ-tests/python/tests/test_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ async def test_streaming():
628628
last_msg_time = start_time
629629
first_msg_time = start_time + 10
630630
async for msg in stream:
631+
print("stream event", msg)
631632
msgs.append(str(msg))
632633
if len(msgs) == 1:
633634
first_msg_time = asyncio.get_event_loop().time()

integ-tests/python/uv.lock

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/build

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ case "$_path" in
194194
command="${command} && uv run baml-cli generate --from ${_repo_root}/integ-tests/baml_src"
195195
if [ "$_test_mode" -eq 1 ]; then
196196
#command="${command} && BAML_LOG=trace infisical run --env=test -- uv run python baml_example_tracing.py"
197-
# command="${command} && BAML_LOG=debug,baml_runtime=trace infisical run --env=test -- uv run pytest -s tests/test_functions.py::test_should_work_with_image_url"
198-
command="${command} && BAML_LOG=info infisical run --env=test -- uv run pytest"
197+
# command="${command} && BAML_LOG=debug,baml_runtime=trace infisical run --env=test -- uv run pytest -s tests/test_functions.py::test_streaming"
198+
command="${command} && BAML_LOG=debug,baml_runtime=trace uv run pytest -s tests/test_functions.py::test_streaming"
199+
# command="${command} && BAML_LOG=info infisical run --env=test -- uv run pytest"
199200
fi
200201
if [ "$_watch_mode" -eq 1 ]; then
201202
npx nodemon \

0 commit comments

Comments
 (0)