diff --git a/swiftide-core/src/chat_completion/traits.rs b/swiftide-core/src/chat_completion/traits.rs index b0fff668..a9105afb 100644 --- a/swiftide-core/src/chat_completion/traits.rs +++ b/swiftide-core/src/chat_completion/traits.rs @@ -56,7 +56,7 @@ where LLM: ChatCompletion + Clone + 'static, { fn from(llm: &LLM) -> Self { - Box::new(llm.clone()) + Box::new(llm.clone()) as Box } } @@ -85,7 +85,7 @@ pub trait Tool: Send + Sync + DynClone { where Self: Sized + 'a, { - Box::new(self) + Box::new(self) as Box } } diff --git a/swiftide-core/src/prompt.rs b/swiftide-core/src/prompt.rs index e6782730..0987a566 100644 --- a/swiftide-core/src/prompt.rs +++ b/swiftide-core/src/prompt.rs @@ -76,6 +76,8 @@ impl Prompt { /// Renders a prompt /// + /// If no context is provided, the prompt will be rendered as is. + /// /// # Errors /// /// See `Template::render` @@ -83,7 +85,13 @@ impl Prompt { if let Some(context) = &self.context { self.template.render(context).await } else { - self.template.render(&tera::Context::default()).await + match &self.template { + Template::CompiledTemplate(_) => { + self.template.render(&tera::Context::default()).await + } + Template::String(string) => Ok(string.clone()), + Template::Static(string) => Ok((*string).to_string()), + } } } } @@ -215,4 +223,11 @@ mod test { "hello swiftide" ); } + + #[tokio::test] + async fn test_assume_rendered_unless_context_methods_called() { + let prompt = Prompt::from("hello {{world}}"); + + assert_eq!(prompt.render().await.unwrap(), "hello {{world}}"); + } }