-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client response type validation and support for LLM clients (#1473)
- Introduce `UnresolvedResponseType` and `ResponseType` enums in `clientspec.rs` - Add `ensure_client_response_type()` method in `helpers.rs` to validate client response types - Update OpenAI client to support custom response type configuration - Add integration test for client response type validation - Add test file for validating invalid response format in BAML configuration <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Add client response type validation and support for LLM clients, including enums, validation methods, client updates, tests, and documentation. > > - **Behavior**: > - Introduce `UnresolvedResponseType` and `ResponseType` enums in `clientspec.rs`. > - Add `ensure_client_response_type()` method in `helpers.rs` to validate client response types. > - Update OpenAI client in `openai.rs` to support custom response type configuration. > - **Tests**: > - Add integration test `test_client_response_type` in `test_functions.py` for client response type validation. > - Add `bad_response_format.baml` test file for invalid response format validation. > - **Documentation**: > - Add `client-response-type.mdx` snippet and include it in `azure.mdx`, `openai-generic.mdx`, and `openai.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 5dc801d. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information
Showing
11 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
engine/baml-lib/baml/tests/validation_files/client/bad_response_format.baml
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,30 @@ | ||
client<llm> MyClient { | ||
provider openai | ||
options { | ||
model "gpt-4o" | ||
client_response_type "invalid" | ||
} | ||
} | ||
|
||
client<llm> MyClient2 { | ||
provider openai | ||
options { | ||
model "gpt-4o" | ||
client_response_type "openai" | ||
} | ||
} | ||
|
||
client<llm> MyClient3 { | ||
provider openai | ||
options { | ||
model "gpt-4o" | ||
client_response_type "anthropic" | ||
} | ||
} | ||
|
||
// error: client_response_type must be one of "openai", "anthropic", "google", or "vertex". Got: invalid | ||
// --> client/bad_response_format.baml:5 | ||
// | | ||
// 4 | model "gpt-4o" | ||
// 5 | client_response_type "invalid" | ||
// | |
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
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,13 @@ | ||
<ParamField path="client_response_type" type="openai | anthropic | google | vertex" default="openai"> | ||
<Warning> | ||
Please let [us know on Discord](https://www.boundaryml.com/discord) if you have this use case! This is in alpha and we'd like to make sure we continue to cover your use cases. | ||
</Warning> | ||
|
||
The type of response to return from the client. | ||
|
||
Sometimes you may expect a different response format than the provider default. | ||
For example, using Azure you may be proxying to an endpoint that returns a different format than the OpenAI default. | ||
|
||
**Default: `openai`** | ||
</ParamField> | ||
|
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