smartui/commands/
find_command.rs1use crate::error::Result;
2use crate::gemini::GeminiClientTrait;
3use crate::tts::TTSManager;
4use async_trait::async_trait;
5
6#[async_trait]
7pub trait GenerateContent {
8 async fn generate_content(&self, prompt: &str) -> Result<String>;
9}
10
11pub struct FindCommandCommand<T: GeminiClientTrait> {
12 client: T,
13}
14
15impl<T: GeminiClientTrait> FindCommandCommand<T> {
16 pub fn new(client: T) -> Self {
17 Self { client }
18 }
19}
20
21#[async_trait]
22impl<T: GeminiClientTrait + Send + Sync> GenerateContent for FindCommandCommand<T> {
23 async fn generate_content(&self, prompt: &str) -> Result<String> {
24 let command_prompt = format!(
25 "Find a command for the following task:\n\n{}",
26 prompt
27 );
28
29 self.client.generate_content(command_prompt).await
30 }
31}
32
33pub async fn execute<T: GeminiClientTrait + Send + Sync>(
34 client: T,
35 task: String,
36 tts_manager: Option<&TTSManager>,
37) -> Result<()> {
38 let find_command = FindCommandCommand::new(client);
39 let command = find_command.generate_content(&task).await?;
40 println!("{}", command);
41
42 if let Some(tts) = tts_manager {
43 tts.speak(&command).await?;
44 }
45
46 Ok(())
47}