From c6580da88948b42bd9373388d717e344b4610046 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 2 Aug 2024 16:07:43 -0400 Subject: [PATCH] assistant: Don't unwrap built-in step resolution prompt (#15704) This PR removes some `unwrap`s while loading the built-in step resolution prompt. While these `unwrap`s are safe today, they are relying on some implicit contracts that might change in the future. We're using this in a context where it's easy to propagate an error upwards, so we may as well avoid the `unwrap`s entirely and use a `Result`. Release Notes: - N/A --- crates/assistant/src/context.rs | 2 +- crates/assistant/src/prompt_library.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/assistant/src/context.rs b/crates/assistant/src/context.rs index f14cf4776a..0cc7e6661f 100644 --- a/crates/assistant/src/context.rs +++ b/crates/assistant/src/context.rs @@ -1407,7 +1407,7 @@ impl Context { async move { let prompt_store = cx.update(|cx| PromptStore::global(cx))?.await?; - let mut prompt = prompt_store.step_resolution_prompt(); + let mut prompt = prompt_store.step_resolution_prompt()?; prompt.push_str(&step_text); request.messages.push(LanguageModelRequestMessage { diff --git a/crates/assistant/src/prompt_library.rs b/crates/assistant/src/prompt_library.rs index a121a5b316..769db54225 100644 --- a/crates/assistant/src/prompt_library.rs +++ b/crates/assistant/src/prompt_library.rs @@ -1505,15 +1505,15 @@ impl PromptStore { self.metadata_cache.read().metadata.first().cloned() } - pub fn step_resolution_prompt(&self) -> String { - String::from_utf8( + pub fn step_resolution_prompt(&self) -> Result { + let path = "prompts/step_resolution.md"; + + Ok(String::from_utf8( Assets - .load("prompts/step_resolution.md") - .unwrap() - .unwrap() + .load(path)? + .ok_or_else(|| anyhow!("{path} not found"))? .to_vec(), - ) - .unwrap() + )?) } }