From da8eb2693110304d0dc5e64fe3431932f12581bb Mon Sep 17 00:00:00 2001 From: dal Date: Thu, 13 Feb 2025 16:36:04 -0700 Subject: [PATCH] silent on parsing errors since we will have a ton with the optimistic parsing. --- .../post_thread/agent_message_transformer.rs | 71 ++++++------------- .../post_thread/agent_thread.rs | 20 +++++- 2 files changed, 39 insertions(+), 52 deletions(-) diff --git a/api/src/routes/ws/threads_and_messages/post_thread/agent_message_transformer.rs b/api/src/routes/ws/threads_and_messages/post_thread/agent_message_transformer.rs index 2654a823e..4d6ecd6c7 100644 --- a/api/src/routes/ws/threads_and_messages/post_thread/agent_message_transformer.rs +++ b/api/src/routes/ws/threads_and_messages/post_thread/agent_message_transformer.rs @@ -312,9 +312,7 @@ pub fn transform_message( .into_iter() .map(BusterContainer::ChatMessage) .collect(), - Err(e) => { - return Err(e); - } + Err(_) => vec![], // Silently ignore errors by returning empty vec }; return Ok((messages, ThreadEvent::GeneratingResponseMessage)); @@ -333,15 +331,13 @@ pub fn transform_message( .into_iter() .map(BusterContainer::ReasoningMessage) .collect(), - Err(e) => { - return Err(e); - } + Err(_) => vec![], // Silently ignore errors by returning empty vec }; return Ok((messages, ThreadEvent::GeneratingReasoningMessage)); } - Err(anyhow::anyhow!("Assistant message missing required fields")) + Ok((vec![], ThreadEvent::GeneratingResponseMessage)) // Return empty vec instead of error } Message::Tool { id, @@ -363,17 +359,15 @@ pub fn transform_message( .into_iter() .map(BusterContainer::ReasoningMessage) .collect(), - Err(e) => { - return Err(e); - } + Err(_) => vec![], // Silently ignore errors by returning empty vec }; return Ok((messages, ThreadEvent::GeneratingReasoningMessage)); } - Err(anyhow::anyhow!("Tool message missing name field")) + Ok((vec![], ThreadEvent::GeneratingReasoningMessage)) // Return empty vec instead of error } - _ => Err(anyhow::anyhow!("Unsupported message type")), + _ => Ok((vec![], ThreadEvent::GeneratingResponseMessage)), // Return empty vec instead of error } } @@ -534,28 +528,17 @@ fn tool_data_catalog_search( if let Some(progress) = progress { let data_catalog_result = match serde_json::from_str::(&content) { Ok(result) => result, - Err(e) => { - return Err(anyhow::anyhow!( - "Failed to parse data catalog search result: {}", - e - )); - } + Err(_) => return Ok(vec![]), // Silently ignore parsing errors }; let duration = (data_catalog_result.duration.clone() as f64 / 1000.0 * 10.0).round() / 10.0; let result_count = data_catalog_result.results.len(); let query_params = data_catalog_result.query_params.clone(); - let thought_pill_containters = - match proccess_data_catalog_search_results(data_catalog_result) { - Ok(object) => object, - Err(e) => { - return Err(anyhow::anyhow!( - "Failed to process data catalog search results: {}", - e - )); - } - }; + let thought_pill_containters = match proccess_data_catalog_search_results(data_catalog_result) { + Ok(object) => object, + Err(_) => return Ok(vec![]), // Silently ignore processing errors + }; let buster_thought = if result_count > 0 { BusterThreadMessage::Thought(BusterThought { @@ -741,9 +724,7 @@ fn tool_file_search( if let Some(progress) = progress { let file_search_result = match serde_json::from_str::(&content) { Ok(result) => result, - Err(e) => { - return Err(anyhow::anyhow!("Failed to parse file search result: {}", e)); - } + Err(_) => return Ok(vec![]), // Silently ignore parsing errors }; let query_params = file_search_result.query_params.clone(); @@ -752,12 +733,7 @@ fn tool_file_search( let thought_pill_containers = match process_file_search_results(file_search_result) { Ok(containers) => containers, - Err(e) => { - return Err(anyhow::anyhow!( - "Failed to process file search results: {}", - e - )); - } + Err(_) => return Ok(vec![]), // Silently ignore processing errors }; let buster_thought = if result_count > 0 { @@ -873,9 +849,7 @@ fn tool_open_files( if let Some(progress) = progress { let open_files_result = match serde_json::from_str::(&content) { Ok(result) => result, - Err(e) => { - return Err(anyhow::anyhow!("Failed to parse open files result: {}", e)); - } + Err(_) => return Ok(vec![]), // Silently ignore parsing errors }; let duration = (open_files_result.duration as f64 / 1000.0 * 10.0).round() / 10.0; @@ -953,12 +927,10 @@ fn process_assistant_create_file(tool_call: &ToolCall) -> Result Ok(vec![message]), + None => Ok(vec![]) // Return empty vec instead of error when waiting for file data } - - // If we couldn't parse a message, return an error - Err(anyhow::anyhow!("Still waiting for file data")) } fn assistant_modify_file( @@ -1019,7 +991,10 @@ fn tool_create_file( match progress { MessageProgress::Complete => { // Parse the content to get file information using CreateFilesOutput - let create_files_result = serde_json::from_str::(&content)?; + let create_files_result = match serde_json::from_str::(&content) { + Ok(result) => result, + Err(_) => return Ok(vec![]), // Silently ignore parsing errors + }; let mut messages = Vec::new(); for file in create_files_result.files { @@ -1045,10 +1020,6 @@ fn tool_create_file( })); } - if messages.is_empty() { - return Err(anyhow::anyhow!("No valid files found in response")); - } - Ok(messages) } _ => Err(anyhow::anyhow!("Tool create file only supports complete.")), diff --git a/api/src/routes/ws/threads_and_messages/post_thread/agent_thread.rs b/api/src/routes/ws/threads_and_messages/post_thread/agent_thread.rs index 0b17acd20..0cf6f1db5 100644 --- a/api/src/routes/ws/threads_and_messages/post_thread/agent_thread.rs +++ b/api/src/routes/ws/threads_and_messages/post_thread/agent_thread.rs @@ -247,11 +247,27 @@ impl AgentThreadHandler { if let Ok(msg) = msg_result { match transform_message(chat_id, message_id, msg) { Ok((transformed_messages, event)) => { + // Skip empty messages + let non_empty_messages: Vec<_> = transformed_messages + .into_iter() + .filter(|msg| match msg { + BusterContainer::ChatMessage(chat) => chat.response_message.message.is_some() || chat.response_message.message_chunk.is_some(), + BusterContainer::ReasoningMessage(reasoning) => match &reasoning.reasoning { + ReasoningMessage::Thought(thought) => thought.thoughts.is_some(), + ReasoningMessage::File(file) => file.file.is_some(), + }, + }) + .collect(); + + if non_empty_messages.is_empty() { + continue; + } + // Store transformed messages for later database insertion - all_transformed_messages.extend(transformed_messages.clone()); + all_transformed_messages.extend(non_empty_messages.clone()); // Send websocket messages as before - for transformed in transformed_messages { + for transformed in non_empty_messages { let response = WsResponseMessage::new_no_user( WsRoutes::Threads(ThreadRoute::Post), WsEvent::Threads(event.clone()),