smartui/commands/
explain_algorithm.rs

1use 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 ExplainAlgorithmCommand<T: GeminiClientTrait> {
12    client: T,
13}
14
15impl<T: GeminiClientTrait> ExplainAlgorithmCommand<T> {
16    pub fn new(client: T) -> Self {
17        Self { client }
18    }
19}
20
21#[async_trait]
22impl<T: GeminiClientTrait + Send + Sync> GenerateContent for ExplainAlgorithmCommand<T> {
23    async fn generate_content(&self, prompt: &str) -> Result<String> {
24        let algorithm_prompt = format!(
25            "Explain the following algorithm in detail:\n\n{}",
26            prompt
27        );
28        
29        self.client.generate_content(algorithm_prompt).await
30    }
31}
32
33pub async fn execute<T: GeminiClientTrait + Send + Sync>(
34    client: T,
35    algorithm: String,
36    tts_manager: Option<&TTSManager>,
37) -> Result<()> {
38    let explain_command = ExplainAlgorithmCommand::new(client);
39    let explanation = explain_command.generate_content(&algorithm).await?;
40    println!("{}", explanation);
41
42    if let Some(tts) = tts_manager {
43        tts.speak(&explanation).await?;
44    }
45
46    Ok(())
47}