-
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.
feat: baml-cli serve support client registry (#1000)
## Copying this PR from #986 This adds the option to pass client registry configuration when serving BAML as HTTP, by adding an optional __baml_options__: BamlOptions field to the request body of the POST /call/:msg endpoint. For now, BamlOptions only has one field, client_registry. TODO: - [x] Support sync endpoint - [x] Support streaming endpoint - [x] Make __baml_options__ take a list of clients instead of HashMap with redundant name - [x] __baml_options -> __baml_options__ - Add to generated OpenAPI spec (openapi.rs:364) - [x] Define schemas for BamlOptions - [x] Add field to request body schemas - [x] Document the feature To test: 1. cd engine 1. Create an example baml_src using baml-cli init 1. Start the HTTP server: cargo run --bin baml-runtime -- serve --preview 1. Save the below body payload to body.json, adding a valid OpenAI token 1. In a separate terminal, run a completion: `curl -X POST http://localhost:2024/call/ExtractResume -H 'Content-Type: application/json' -d @body.json` ``` { "resume": "Vaibhav Gupta", "__baml_options__": { "client_registry": { "clients": [ { "name": "OpenAI", "provider": "openai", "retry_policy": null, "options": { "model": "gpt-4o-mini", "api_key": "sk-FILL-IN-VALID-KEY-HERE" } } ], "primary": "OpenAI" } } } ``` <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Adds support for client registry configuration in BAML HTTP serving with updates to server logic, OpenAPI spec, and documentation. > > - **Behavior**: > - Adds `BamlOptions` struct in `serve/mod.rs` to support client registry configuration in HTTP requests. > - Updates `baml_call` and `baml_stream` functions to handle `BamlOptions`. > - Supports both sync and streaming endpoints for client registry. > - **OpenAPI**: > - Updates `openapi.rs` to include `BamlOptions` and `ClientProperty` schemas. > - Adds `__baml_options__` to request body in OpenAPI spec. > - **Client Registry**: > - Modifies `ClientRegistry` in `client_registry/mod.rs` to deserialize from a list of clients. > - Adds `deserialize_clients` function for custom deserialization logic. > - **Documentation**: > - Updates `client-registry.mdx` to document new client registry feature in HTTP requests. > > <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 1633303. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Co-authored-by: Lorenz Ohly <lorenz.ohly@gmail.com>
- Loading branch information
1 parent
da1a5e8
commit abe70bf
Showing
6 changed files
with
452 additions
and
39 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
Oops, something went wrong.