-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorder schema-files, expand on LLMModel
- Loading branch information
Showing
12 changed files
with
220 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
lumni/src/apps/builtin/llm/prompt/src/chat/conversation/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
mod model; | ||
mod cache; | ||
|
||
pub use model::LLMModel; | ||
pub use cache::ConversationCache; | ||
|
||
use super::PromptRole; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct ModelIdentifier(pub String); | ||
|
||
impl ModelIdentifier { | ||
pub fn new(provider: &str, name: &str) -> Self { | ||
ModelIdentifier(format!("{}::{}", provider, name)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct ModelServerName(pub String); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct ConversationId(pub i64); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct MessageId(pub i64); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct AttachmentId(pub i64); | ||
|
||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Conversation { | ||
pub id: ConversationId, | ||
pub name: String, | ||
pub info: serde_json::Value, | ||
pub model_identifier: ModelIdentifier, | ||
pub model_server: ModelServerName, | ||
pub parent_conversation_id: Option<ConversationId>, | ||
pub fork_message_id: Option<MessageId>, // New field | ||
pub completion_options: Option<serde_json::Value>, | ||
pub created_at: i64, | ||
pub updated_at: i64, | ||
pub is_deleted: bool, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Message { | ||
pub id: MessageId, | ||
pub conversation_id: ConversationId, | ||
pub role: PromptRole, | ||
pub message_type: String, | ||
pub content: String, | ||
pub has_attachments: bool, | ||
pub token_length: Option<i64>, | ||
pub previous_message_id: Option<MessageId>, | ||
pub created_at: i64, | ||
pub is_deleted: bool, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub enum AttachmentData { | ||
Uri(String), | ||
Data(Vec<u8>), | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Attachment { | ||
pub attachment_id: AttachmentId, | ||
pub message_id: MessageId, | ||
pub conversation_id: ConversationId, | ||
pub data: AttachmentData, // file_uri or file_data | ||
pub file_type: String, | ||
pub metadata: Option<serde_json::Value>, | ||
pub created_at: i64, | ||
pub is_deleted: bool, | ||
} |
115 changes: 115 additions & 0 deletions
115
lumni/src/apps/builtin/llm/prompt/src/chat/conversation/model.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use super::ModelIdentifier; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct LLMModel { | ||
pub identifier: ModelIdentifier, | ||
pub info: Option<serde_json::Value>, | ||
pub config: Option<serde_json::Value>, | ||
pub context_window_size: Option<i64>, | ||
pub input_token_limit: Option<i64>, | ||
} | ||
|
||
impl LLMModel { | ||
pub fn new(identifier: ModelIdentifier) -> Self { | ||
LLMModel { | ||
identifier, | ||
info: None, | ||
config: None, | ||
context_window_size: None, | ||
input_token_limit: None, | ||
} | ||
} | ||
|
||
pub fn identifier(&self) -> &ModelIdentifier { | ||
&self.identifier | ||
} | ||
|
||
pub fn info(&self) -> Option<&serde_json::Value> { | ||
self.info.as_ref() | ||
} | ||
|
||
pub fn config(&self) -> Option<&serde_json::Value> { | ||
self.config.as_ref() | ||
} | ||
|
||
pub fn context_window_size(&self) -> Option<i64> { | ||
self.context_window_size | ||
} | ||
|
||
pub fn input_token_limit(&self) -> Option<i64> { | ||
self.input_token_limit | ||
} | ||
|
||
pub fn set_info(&mut self, info: serde_json::Value) -> &mut Self { | ||
self.info = Some(info); | ||
self | ||
} | ||
|
||
pub fn set_config(&mut self, config: serde_json::Value) -> &mut Self { | ||
self.config = Some(config); | ||
self | ||
} | ||
|
||
pub fn set_context_window_size(&mut self, size: i64) -> &mut Self { | ||
self.context_window_size = Some(size); | ||
self | ||
} | ||
|
||
pub fn set_input_token_limit(&mut self, limit: i64) -> &mut Self { | ||
self.input_token_limit = Some(limit); | ||
self | ||
} | ||
|
||
pub fn set_config_value(&mut self, key: &str, value: serde_json::Value) -> &mut Self { | ||
if let Some(config) = self.config.as_mut() { | ||
if let serde_json::Value::Object(map) = config { | ||
map.insert(key.to_string(), value); | ||
} | ||
} else { | ||
let mut map = serde_json::Map::new(); | ||
map.insert(key.to_string(), value); | ||
self.config = Some(serde_json::Value::Object(map)); | ||
} | ||
self | ||
} | ||
|
||
pub fn get_config_value(&self, key: &str) -> Option<&serde_json::Value> { | ||
self.config.as_ref().and_then(|config| { | ||
if let serde_json::Value::Object(map) = config { | ||
map.get(key) | ||
} else { | ||
None | ||
} | ||
}) | ||
} | ||
|
||
pub fn set_size(&mut self, size: usize) -> &mut Self { | ||
// model size in bytes | ||
self.set_config_value("size", serde_json::Value::Number(size.into())) | ||
} | ||
|
||
pub fn get_size(&self) -> Option<usize> { | ||
self.get_config_value("size") | ||
.and_then(|v| v.as_u64()) | ||
.map(|v| v as usize) | ||
} | ||
|
||
pub fn set_family(&mut self, family: &str) -> &mut Self { | ||
self.set_config_value("family", serde_json::Value::String(family.to_string())) | ||
} | ||
|
||
pub fn get_family(&self) -> Option<&str> { | ||
self.get_config_value("family") | ||
.and_then(|v| v.as_str()) | ||
} | ||
|
||
pub fn set_description(&mut self, description: &str) -> &mut Self { | ||
self.set_config_value("description", serde_json::Value::String(description.to_string())) | ||
} | ||
|
||
pub fn get_description(&self) -> Option<&str> { | ||
self.get_config_value("description") | ||
.and_then(|v| v.as_str()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
mod connector; | ||
mod display; | ||
mod reader; | ||
mod schema; | ||
mod store; | ||
|
||
pub use reader::ConversationReader; | ||
pub use schema::{ConversationCache, ConversationId, Model, ModelIdentifier, ModelServerName, Message, MessageId}; | ||
pub use super::conversation; | ||
pub use store::ConversationDatabaseStore; | ||
|
||
pub use super::PromptRole; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.