fixed the created at and the ordering on the get

This commit is contained in:
dal 2025-03-19 14:03:59 -06:00
parent da170c28a3
commit ff8a443e42
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
3 changed files with 9 additions and 4 deletions

View File

@ -82,7 +82,7 @@ pub async fn get_chat_handler(chat_id: &Uuid, user_id: &Uuid) -> Result<ChatWith
.inner_join(users::table.on(messages::created_by.eq(users::id))) .inner_join(users::table.on(messages::created_by.eq(users::id)))
.filter(messages::chat_id.eq(chat_id)) .filter(messages::chat_id.eq(chat_id))
.filter(messages::deleted_at.is_null()) .filter(messages::deleted_at.is_null())
.order_by(messages::created_at.desc()) .order_by(messages::created_at.asc())
.select(( .select((
messages::id, messages::id,
messages::request_message, messages::request_message,
@ -154,6 +154,7 @@ pub async fn get_chat_handler(chat_id: &Uuid, user_id: &Uuid) -> Result<ChatWith
response_messages, response_messages,
reasoning, reasoning,
Some(msg.final_reasoning_message), Some(msg.final_reasoning_message),
msg.created_at,
) )
}) })
.collect(); .collect();

View File

@ -350,6 +350,7 @@ pub async fn post_chat_handler(
response_messages.clone(), response_messages.clone(),
reasoning_messages.clone(), reasoning_messages.clone(),
Some(format!("Reasoned for {} seconds", reasoning_duration).to_string()), Some(format!("Reasoned for {} seconds", reasoning_duration).to_string()),
Utc::now(),
); );
chat_with_messages.update_message(message); chat_with_messages.update_message(message);
@ -1854,6 +1855,7 @@ async fn initialize_chat(
Vec::new(), Vec::new(),
Vec::new(), Vec::new(),
None, None,
Utc::now(),
); );
// Add message to existing chat // Add message to existing chat
@ -1889,6 +1891,7 @@ async fn initialize_chat(
Vec::new(), Vec::new(),
Vec::new(), Vec::new(),
None, None,
Utc::now(),
); );
let mut chat_with_messages = ChatWithMessages::new( let mut chat_with_messages = ChatWithMessages::new(

View File

@ -15,7 +15,7 @@ pub struct ChatMessage {
pub reasoning_message_ids: Vec<String>, pub reasoning_message_ids: Vec<String>,
#[serde(default)] #[serde(default)]
pub reasoning_messages: HashMap<String, Value>, pub reasoning_messages: HashMap<String, Value>,
pub created_at: String, pub created_at: chrono::DateTime<chrono::Utc>,
pub final_reasoning_message: Option<String>, pub final_reasoning_message: Option<String>,
} }
@ -46,7 +46,7 @@ impl ChatMessage {
response_messages: HashMap::new(), response_messages: HashMap::new(),
reasoning_message_ids: Vec::new(), reasoning_message_ids: Vec::new(),
reasoning_messages: HashMap::new(), reasoning_messages: HashMap::new(),
created_at: Utc::now().to_rfc3339(), created_at: Utc::now(),
final_reasoning_message: None, final_reasoning_message: None,
} }
} }
@ -57,6 +57,7 @@ impl ChatMessage {
response_messages: Vec<Value>, response_messages: Vec<Value>,
reasoning_messages: Vec<Value>, reasoning_messages: Vec<Value>,
final_reasoning_message: Option<String>, final_reasoning_message: Option<String>,
created_at: chrono::DateTime<chrono::Utc>,
) -> Self { ) -> Self {
let response_message_ids: Vec<String> = response_messages let response_message_ids: Vec<String> = response_messages
.iter() .iter()
@ -91,7 +92,7 @@ impl ChatMessage {
response_messages: response_messages_map, response_messages: response_messages_map,
reasoning_message_ids, reasoning_message_ids,
reasoning_messages: reasoning_messages_map, reasoning_messages: reasoning_messages_map,
created_at: Utc::now().to_rfc3339(), created_at,
final_reasoning_message, final_reasoning_message,
} }
} }