test_tools.rs

 1use super::*;
 2use anyhow::Result;
 3use gpui::{App, SharedString, Task};
 4
 5/// A tool that echoes its input
 6#[derive(JsonSchema, Serialize, Deserialize)]
 7pub struct EchoToolInput {
 8    /// The text to echo.
 9    text: String,
10}
11
12pub struct EchoTool;
13
14impl AgentTool for EchoTool {
15    type Input = EchoToolInput;
16
17    fn name(&self) -> SharedString {
18        "echo".into()
19    }
20
21    fn run(self: Arc<Self>, input: Self::Input, _cx: &mut App) -> Task<Result<String>> {
22        Task::ready(Ok(input.text))
23    }
24}
25
26/// A tool that waits for a specified delay
27#[derive(JsonSchema, Serialize, Deserialize)]
28pub struct DelayToolInput {
29    /// The delay in milliseconds.
30    ms: u64,
31}
32
33pub struct DelayTool;
34
35impl AgentTool for DelayTool {
36    type Input = DelayToolInput;
37
38    fn name(&self) -> SharedString {
39        "delay".into()
40    }
41
42    fn run(self: Arc<Self>, input: Self::Input, cx: &mut App) -> Task<Result<String>>
43    where
44        Self: Sized,
45    {
46        cx.foreground_executor().spawn(async move {
47            smol::Timer::after(Duration::from_millis(input.ms)).await;
48            Ok("Ding".to_string())
49        })
50    }
51}
52
53/// A tool that takes an object with map from letters to random words starting with that letter.
54/// All fiealds are required! Pass a word for every letter!
55#[derive(JsonSchema, Serialize, Deserialize)]
56pub struct WordListInput {
57    /// Provide a random word that starts with A.
58    a: Option<String>,
59    /// Provide a random word that starts with B.
60    b: Option<String>,
61    /// Provide a random word that starts with C.
62    c: Option<String>,
63    /// Provide a random word that starts with D.
64    d: Option<String>,
65    /// Provide a random word that starts with E.
66    e: Option<String>,
67    /// Provide a random word that starts with F.
68    f: Option<String>,
69    /// Provide a random word that starts with G.
70    g: Option<String>,
71}
72
73pub struct WordListTool;
74
75impl AgentTool for WordListTool {
76    type Input = WordListInput;
77
78    fn name(&self) -> SharedString {
79        "word_list".into()
80    }
81
82    fn run(self: Arc<Self>, _input: Self::Input, _cx: &mut App) -> Task<Result<String>> {
83        Task::ready(Ok("ok".to_string()))
84    }
85}