mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-19 23:41:22 +02:00
chat history added to context and patching text content
This commit is contained in:
@@ -35,3 +35,28 @@ impl Message {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MessageRole {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
MessageRole::User => write!(f, "User"),
|
||||
MessageRole::AI => write!(f, "AI"),
|
||||
MessageRole::System => write!(f, "System"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Message {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}: {}", self.role, self.content)
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to format a vector of messages
|
||||
pub fn format_history(history: &[Message]) -> String {
|
||||
history
|
||||
.iter()
|
||||
.map(|msg| format!("{}", msg))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use surrealdb::opt::PatchOp;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::stored_object;
|
||||
use crate::{error::AppError, storage::db::SurrealDbClient, stored_object};
|
||||
|
||||
use super::file_info::FileInfo;
|
||||
|
||||
@@ -35,4 +36,24 @@ impl TextContent {
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn patch(
|
||||
id: &str,
|
||||
instructions: &str,
|
||||
category: &str,
|
||||
text: &str,
|
||||
db: &SurrealDbClient,
|
||||
) -> Result<(), AppError> {
|
||||
let now = Utc::now();
|
||||
|
||||
let _res: Option<Self> = db
|
||||
.update((Self::table_name(), id))
|
||||
.patch(PatchOp::replace("/instructions", instructions))
|
||||
.patch(PatchOp::replace("/category", category))
|
||||
.patch(PatchOp::replace("/text", text))
|
||||
.patch(PatchOp::replace("/updated_at", now))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user