Something went wrong. Try again.
A rust frontend for LLM's using the openai api.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103use 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<Uuid, Chat>);
impl Chats { pub fn get_chat(&self, id: impl Into<Uuid>) -> Option<&Chat> { self.0.get(&id.into()) }
pub fn get_chats(&self) -> &HashMap<Uuid, Chat> { &self.0 }
pub fn write_chat(&mut self, uuid: impl Into<Uuid>, 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<ModelId>, pub summary: Option<String>, pub messages: Vec<Message>, pub streamed_message: Option<Message>, #[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<String>) -> Self { Self { provider, model: model.into(), } }}
impl Chat { #[allow(dead_code)] // Rust is complaining too much pub fn new( model: impl Into<Option<ModelId>>, summary: impl Into<Option<String>>, messages: Vec<Message>, ) -> 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,}