From ce4f39737b88d2fcf27851ff8b230eda5a1e714b Mon Sep 17 00:00:00 2001 From: aaronvg Date: Wed, 27 Nov 2024 12:07:54 -0800 Subject: [PATCH] Fix error in playground (#1202) > [!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. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral) for 6b4a1e5b66cd873f4fe30866d1006d11694c1d1d. It will automatically update as commits are pushed. --- engine/baml-runtime/src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/engine/baml-runtime/src/lib.rs b/engine/baml-runtime/src/lib.rs index c33718a28..f4f68259f 100644 --- a/engine/baml-runtime/src/lib.rs +++ b/engine/baml-runtime/src/lib.rs @@ -191,7 +191,9 @@ impl BamlRuntime { ctx: &RuntimeContext, strict: bool, ) -> Result<(BamlMap, Vec)> { - 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)?; @@ -205,7 +207,8 @@ impl BamlRuntime { ctx: &RuntimeContext, strict: bool, ) -> Result> { - 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) } @@ -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()