From 73a98bf48294ab79845129103b4d77c4ac1fde5b Mon Sep 17 00:00:00 2001 From: dal Date: Wed, 16 Apr 2025 15:34:56 -0600 Subject: [PATCH] feedback field --- api/libs/handlers/src/chats/get_chat_handler.rs | 4 ++++ api/libs/handlers/src/chats/post_chat_handler.rs | 4 ++++ .../src/messages/helpers/update_message_handler.rs | 9 +-------- api/libs/handlers/src/messages/types.rs | 5 ++++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/libs/handlers/src/chats/get_chat_handler.rs b/api/libs/handlers/src/chats/get_chat_handler.rs index a3fb8634b..930bcbb72 100644 --- a/api/libs/handlers/src/chats/get_chat_handler.rs +++ b/api/libs/handlers/src/chats/get_chat_handler.rs @@ -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, pub user_attributes: Value, + pub feedback: Option, } #[derive(Queryable)] @@ -122,6 +124,7 @@ pub async fn get_chat_handler( users::id, users::name.nullable(), users::attributes, + messages::feedback.nullable(), )) .load::(&mut conn) .await @@ -275,6 +278,7 @@ pub async fn get_chat_handler( reasoning, msg.final_reasoning_message, msg.created_at, + msg.feedback, ) }) .collect(); diff --git a/api/libs/handlers/src/chats/post_chat_handler.rs b/api/libs/handlers/src/chats/post_chat_handler.rs index e96259301..ac2553281 100644 --- a/api/libs/handlers/src/chats/post_chat_handler.rs +++ b/api/libs/handlers/src/chats/post_chat_handler.rs @@ -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( diff --git a/api/libs/handlers/src/messages/helpers/update_message_handler.rs b/api/libs/handlers/src/messages/helpers/update_message_handler.rs index d87f3e873..3a305e4cf 100644 --- a/api/libs/handlers/src/messages/helpers/update_message_handler.rs +++ b/api/libs/handlers/src/messages/helpers/update_message_handler.rs @@ -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?; diff --git a/api/libs/handlers/src/messages/types.rs b/api/libs/handlers/src/messages/types.rs index afa9b1099..080310aff 100644 --- a/api/libs/handlers/src/messages/types.rs +++ b/api/libs/handlers/src/messages/types.rs @@ -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, pub created_at: chrono::DateTime, pub final_reasoning_message: Option, + pub feedback: Option, } #[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, final_reasoning_message: Option, created_at: chrono::DateTime, + feedback: Option, ) -> Self { let response_message_ids: Vec = response_messages .iter() @@ -97,6 +99,7 @@ impl ChatMessage { reasoning_messages: reasoning_messages_map, created_at, final_reasoning_message, + feedback, } } }