rusty_gemini/
chat.rs

1use crate::{content::Content, error::GeminiError, model::GenerativeModel, GeminiResponse};
2
3#[derive(Debug)]
4pub struct ChatSession {
5    pub(crate) model: GenerativeModel,
6    pub history: Vec<Content>,
7}
8
9impl ChatSession {
10    pub async fn send_message(&mut self, content: Content) -> Result<GeminiResponse, GeminiError> {
11        self.history.push(content);
12        let response = self.model.generate_content(self.history.clone()).await;
13        if let Ok(ref response) = response {
14            self.history.push(response.candidates[0].content.clone());
15        }
16        response
17    }
18    // pub async fn send_message_streamed(&mut self, content: Content) -> GeminiResponse {
19    //     self.history.push(content);
20    //     self.model.generate_content(self.history.clone()).await
21    // }
22}