use serde::{Deserialize, Serialize}; use std::collections::HashMap; use uuid::Uuid; pub mod app; pub mod settings; pub mod state; pub mod storage; #[derive(PartialEq, Clone, Debug, Default, Deserialize, Serialize)] pub struct Chats(HashMap); impl Chats { pub fn get_chat(&self, id: impl Into) -> Option<&Chat> { self.0.get(&id.into()) } pub fn get_chats(&self) -> &HashMap { &self.0 } pub fn write_chat(&mut self, uuid: impl Into, chat: Chat) { let _ = self.0.insert(uuid.into(), chat); } pub fn create_chat(&self) -> (Uuid, Chat) { let mut uuid = Uuid::new_v4(); let chat = Chat::default(); // collision check, even if it isn't really likely, who knows! loop { if self.0.contains_key(&uuid) { uuid = Uuid::new_v4(); } else { break; } } // self.write_chat(uuid, chat.clone()); (uuid, chat) } } #[derive(Default, PartialEq, Clone, Debug, Deserialize, Serialize)] pub struct Chat { pub model_id: Option, pub summary: Option, pub messages: Vec, pub streamed_message: Option, #[serde(skip_serializing)] #[serde(default)] pub is_locked: bool, } #[derive(PartialEq, Clone, Debug, Deserialize, Serialize)] pub struct Message { pub author: MessageAuthor, pub thought_process: String, pub content: String, } /// An id for a model, contains both the provider id and the model string. #[derive(Eq, Hash, PartialEq, Clone, Debug, Deserialize, Serialize)] pub struct ModelId { pub provider: Uuid, pub model: String, } impl ModelId { pub fn new(provider: Uuid, model: impl Into) -> Self { Self { provider, model: model.into(), } } } impl Chat { #[allow(dead_code)] // Rust is complaining too much pub fn new( model: impl Into>, summary: impl Into>, messages: Vec, ) -> Self { Self { model_id: model.into(), summary: summary.into(), messages, streamed_message: None, is_locked: false, } } } #[derive(PartialEq, Clone, Debug, Deserialize, Serialize)] pub enum MessageAuthor { System, Assistant, User, /// This is an openai-thing, idk if we want this Developer, }