Skip to content

Commit

Permalink
Fix error in playground (#1202)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->



> [!IMPORTANT]
> Improve error handling in `run_test()` in `lib.rs` by adding specific
cases for different `LLMResponse` errors and enhancing error messages.
> 
>   - **Behavior**:
> - Improve error handling in `run_test()` in `lib.rs` by adding
specific cases for `LLMResponse::InternalFailure`,
`LLMResponse::UserFailure`, and `LLMResponse::LLMFailure`.
> - Enhance error messages for `LLMResponse::LLMFailure` to include
error code, message, and request options.
>   - **Formatting**:
> - Reformat method calls in `get_test_params_and_constraints()` and
`get_test_params()` for better readability.
> 
> <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 6b4a1e5. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
aaronvg authored Nov 27, 2024
1 parent c6fb306 commit ce4f397
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions engine/baml-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ impl BamlRuntime {
ctx: &RuntimeContext,
strict: bool,
) -> Result<(BamlMap<String, BamlValue>, Vec<Constraint>)> {
let params = self.inner.get_test_params(function_name, test_name, ctx, strict)?;
let params = self
.inner
.get_test_params(function_name, test_name, ctx, strict)?;
let constraints = self
.inner
.get_test_constraints(function_name, test_name, &ctx)?;
Expand All @@ -205,7 +207,8 @@ impl BamlRuntime {
ctx: &RuntimeContext,
strict: bool,
) -> Result<BamlMap<String, BamlValue>> {
let (params, _) = self.get_test_params_and_constraints(function_name, test_name, ctx, strict)?;
let (params, _) =
self.get_test_params_and_constraints(function_name, test_name, ctx, strict)?;
Ok(params)
}

Expand Down Expand Up @@ -243,7 +246,14 @@ impl BamlRuntime {
.context("Expected non-empty event chain")?;
let complete_resp = match llm_resp {
LLMResponse::Success(complete_llm_response) => Ok(complete_llm_response),
_ => Err(anyhow::anyhow!("LLM Response was not successful")),
LLMResponse::InternalFailure(e) => Err(anyhow::anyhow!("{}", e)),
LLMResponse::UserFailure(e) => Err(anyhow::anyhow!("{}", e)),
LLMResponse::LLMFailure(e) => Err(anyhow::anyhow!(
"{} {}\n\nRequest options: {}",
e.code.to_string(),
e.message,
serde_json::to_string(&e.request_options).unwrap_or_default()
)),
}?;
let test_constraints_result = if constraints.is_empty() {
TestConstraintsResult::empty()
Expand Down

0 comments on commit ce4f397

Please sign in to comment.