mirror of https://github.com/buster-so/buster.git
feedback field
This commit is contained in:
parent
67f90048da
commit
73a98bf482
|
@ -1,5 +1,6 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use chrono::{DateTime, Utc};
|
||||
use database::enums::MessageFeedback;
|
||||
use diesel::prelude::Queryable;
|
||||
use diesel::{ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
@ -41,6 +42,7 @@ pub struct MessageWithUser {
|
|||
pub user_id: Uuid,
|
||||
pub user_name: Option<String>,
|
||||
pub user_attributes: Value,
|
||||
pub feedback: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Queryable)]
|
||||
|
@ -122,6 +124,7 @@ pub async fn get_chat_handler(
|
|||
users::id,
|
||||
users::name.nullable(),
|
||||
users::attributes,
|
||||
messages::feedback.nullable(),
|
||||
))
|
||||
.load::<MessageWithUser>(&mut conn)
|
||||
.await
|
||||
|
@ -275,6 +278,7 @@ pub async fn get_chat_handler(
|
|||
reasoning,
|
||||
msg.final_reasoning_message,
|
||||
msg.created_at,
|
||||
msg.feedback,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -298,6 +298,7 @@ pub async fn post_chat_handler(
|
|||
vec![],
|
||||
None,
|
||||
message.created_at,
|
||||
None
|
||||
);
|
||||
|
||||
chat_with_messages.add_message(chat_message);
|
||||
|
@ -817,6 +818,7 @@ pub async fn post_chat_handler(
|
|||
reasoning_messages.clone(),
|
||||
Some(formatted_final_reasoning_duration.clone()), // Use formatted reasoning duration
|
||||
Utc::now(),
|
||||
None,
|
||||
);
|
||||
|
||||
chat_with_messages.update_message(final_message);
|
||||
|
@ -2442,6 +2444,7 @@ async fn initialize_chat(
|
|||
Vec::new(),
|
||||
None,
|
||||
Utc::now(),
|
||||
None,
|
||||
);
|
||||
|
||||
// Add message to existing chat
|
||||
|
@ -2481,6 +2484,7 @@ async fn initialize_chat(
|
|||
Vec::new(),
|
||||
None,
|
||||
Utc::now(),
|
||||
None,
|
||||
);
|
||||
|
||||
let mut chat_with_messages = ChatWithMessages::new(
|
||||
|
|
|
@ -4,11 +4,8 @@ use database::{pool::get_pg_pool, schema::messages};
|
|||
use diesel::prelude::*;
|
||||
use diesel_async::RunQueryDsl;
|
||||
use middleware::AuthenticatedUser;
|
||||
use std::str::FromStr;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::messages::types::MessageFeedback;
|
||||
|
||||
/// Update a message with new properties
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -47,15 +44,11 @@ pub async fn update_message_handler(
|
|||
|
||||
// Add feedback if provided
|
||||
if let Some(fb_str) = feedback {
|
||||
// Validate feedback value
|
||||
let feedback = MessageFeedback::from_str(&fb_str)
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
|
||||
// Update the feedback column directly
|
||||
update_statement
|
||||
.set((
|
||||
messages::updated_at.eq(Utc::now()),
|
||||
messages::feedback.eq(feedback.to_string())
|
||||
messages::feedback.eq(fb_str)
|
||||
))
|
||||
.execute(&mut conn)
|
||||
.await?;
|
||||
|
|
|
@ -6,7 +6,6 @@ use serde_json::Value;
|
|||
use uuid::Uuid;
|
||||
|
||||
pub mod message_feedback;
|
||||
pub use message_feedback::MessageFeedback;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ChatMessage {
|
||||
|
@ -20,6 +19,7 @@ pub struct ChatMessage {
|
|||
pub reasoning_messages: HashMap<String, Value>,
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
pub final_reasoning_message: Option<String>,
|
||||
pub feedback: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
@ -51,6 +51,7 @@ impl ChatMessage {
|
|||
reasoning_messages: HashMap::new(),
|
||||
created_at: Utc::now(),
|
||||
final_reasoning_message: None,
|
||||
feedback: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +62,7 @@ impl ChatMessage {
|
|||
reasoning_messages: Vec<Value>,
|
||||
final_reasoning_message: Option<String>,
|
||||
created_at: chrono::DateTime<chrono::Utc>,
|
||||
feedback: Option<String>,
|
||||
) -> Self {
|
||||
let response_message_ids: Vec<String> = response_messages
|
||||
.iter()
|
||||
|
@ -97,6 +99,7 @@ impl ChatMessage {
|
|||
reasoning_messages: reasoning_messages_map,
|
||||
created_at,
|
||||
final_reasoning_message,
|
||||
feedback,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue