Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Sleep tool in cli (#678)

uuuvn1be4da2e188b
diff --git a/crates/cli/src/interactive/sessions/chat.rs b/crates/cli/src/interactive/sessions/chat.rs
index 3b90c34f5..8633ebbfe 100644
--- a/crates/cli/src/interactive/sessions/chat.rs
+++ b/crates/cli/src/interactive/sessions/chat.rs
@@ -114,6 +114,7 @@ pub async fn ensure_session(
let mut session = engine.chat(model.clone(), ChatConfig::default()).await?;
if session.supports_tool_calls().await {
session.add_tool(get_current_date_time).await?;
+ session.add_tool(sleep).await?;
}
Ok::<_, anyhow::Error>(session)
}
@@ -240,3 +241,16 @@ fn chat_state_mut(state: &mut ApplicationState) -> Option<&mut ChatSessionState>
fn get_current_date_time() -> String {
Local::now().to_rfc3339()
}
+
+/// Sleeps for the given number of seconds before responding, at most 60 seconds.
+#[uzu_tool_function]
+async fn sleep(
+ /// Number of seconds to sleep, at most 60.
+ seconds: f64
+) -> Result<String, String> {
+ if !(0.0..=60.0).contains(&seconds) {
+ return Err(format!("Refusing to sleep for {} seconds, must be between 0 and 60", seconds));
+ }
+ tokio::time::sleep(std::time::Duration::from_secs_f64(seconds)).await;
+ Ok(format!("Slept for {} seconds", seconds))
+}