mirror of https://github.com/buster-so/buster.git
silent on parsing errors since we will have a ton with the optimistic parsing.
This commit is contained in:
parent
eac2529f29
commit
da8eb26931
|
@ -312,9 +312,7 @@ pub fn transform_message(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(BusterContainer::ChatMessage)
|
.map(BusterContainer::ChatMessage)
|
||||||
.collect(),
|
.collect(),
|
||||||
Err(e) => {
|
Err(_) => vec![], // Silently ignore errors by returning empty vec
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok((messages, ThreadEvent::GeneratingResponseMessage));
|
return Ok((messages, ThreadEvent::GeneratingResponseMessage));
|
||||||
|
@ -333,15 +331,13 @@ pub fn transform_message(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(BusterContainer::ReasoningMessage)
|
.map(BusterContainer::ReasoningMessage)
|
||||||
.collect(),
|
.collect(),
|
||||||
Err(e) => {
|
Err(_) => vec![], // Silently ignore errors by returning empty vec
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok((messages, ThreadEvent::GeneratingReasoningMessage));
|
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 {
|
Message::Tool {
|
||||||
id,
|
id,
|
||||||
|
@ -363,17 +359,15 @@ pub fn transform_message(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(BusterContainer::ReasoningMessage)
|
.map(BusterContainer::ReasoningMessage)
|
||||||
.collect(),
|
.collect(),
|
||||||
Err(e) => {
|
Err(_) => vec![], // Silently ignore errors by returning empty vec
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok((messages, ThreadEvent::GeneratingReasoningMessage));
|
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 {
|
if let Some(progress) = progress {
|
||||||
let data_catalog_result = match serde_json::from_str::<SearchDataCatalogOutput>(&content) {
|
let data_catalog_result = match serde_json::from_str::<SearchDataCatalogOutput>(&content) {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(e) => {
|
Err(_) => return Ok(vec![]), // Silently ignore parsing errors
|
||||||
return Err(anyhow::anyhow!(
|
|
||||||
"Failed to parse data catalog search result: {}",
|
|
||||||
e
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let duration = (data_catalog_result.duration.clone() as f64 / 1000.0 * 10.0).round() / 10.0;
|
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 result_count = data_catalog_result.results.len();
|
||||||
let query_params = data_catalog_result.query_params.clone();
|
let query_params = data_catalog_result.query_params.clone();
|
||||||
|
|
||||||
let thought_pill_containters =
|
let thought_pill_containters = match proccess_data_catalog_search_results(data_catalog_result) {
|
||||||
match proccess_data_catalog_search_results(data_catalog_result) {
|
Ok(object) => object,
|
||||||
Ok(object) => object,
|
Err(_) => return Ok(vec![]), // Silently ignore processing errors
|
||||||
Err(e) => {
|
};
|
||||||
return Err(anyhow::anyhow!(
|
|
||||||
"Failed to process data catalog search results: {}",
|
|
||||||
e
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let buster_thought = if result_count > 0 {
|
let buster_thought = if result_count > 0 {
|
||||||
BusterThreadMessage::Thought(BusterThought {
|
BusterThreadMessage::Thought(BusterThought {
|
||||||
|
@ -741,9 +724,7 @@ fn tool_file_search(
|
||||||
if let Some(progress) = progress {
|
if let Some(progress) = progress {
|
||||||
let file_search_result = match serde_json::from_str::<SearchFilesOutput>(&content) {
|
let file_search_result = match serde_json::from_str::<SearchFilesOutput>(&content) {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(e) => {
|
Err(_) => return Ok(vec![]), // Silently ignore parsing errors
|
||||||
return Err(anyhow::anyhow!("Failed to parse file search result: {}", e));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let query_params = file_search_result.query_params.clone();
|
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) {
|
let thought_pill_containers = match process_file_search_results(file_search_result) {
|
||||||
Ok(containers) => containers,
|
Ok(containers) => containers,
|
||||||
Err(e) => {
|
Err(_) => return Ok(vec![]), // Silently ignore processing errors
|
||||||
return Err(anyhow::anyhow!(
|
|
||||||
"Failed to process file search results: {}",
|
|
||||||
e
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let buster_thought = if result_count > 0 {
|
let buster_thought = if result_count > 0 {
|
||||||
|
@ -873,9 +849,7 @@ fn tool_open_files(
|
||||||
if let Some(progress) = progress {
|
if let Some(progress) = progress {
|
||||||
let open_files_result = match serde_json::from_str::<OpenFilesOutput>(&content) {
|
let open_files_result = match serde_json::from_str::<OpenFilesOutput>(&content) {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(e) => {
|
Err(_) => return Ok(vec![]), // Silently ignore parsing errors
|
||||||
return Err(anyhow::anyhow!("Failed to parse open files result: {}", e));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let duration = (open_files_result.duration as f64 / 1000.0 * 10.0).round() / 10.0;
|
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<Vec<BusterThrea
|
||||||
let mut parser = StreamingParser::new();
|
let mut parser = StreamingParser::new();
|
||||||
|
|
||||||
// Process the arguments from the tool call
|
// Process the arguments from the tool call
|
||||||
if let Some(message) = parser.process_chunk(&tool_call.function.arguments)? {
|
match parser.process_chunk(&tool_call.function.arguments)? {
|
||||||
return Ok(vec![message]);
|
Some(message) => 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(
|
fn assistant_modify_file(
|
||||||
|
@ -1019,7 +991,10 @@ fn tool_create_file(
|
||||||
match progress {
|
match progress {
|
||||||
MessageProgress::Complete => {
|
MessageProgress::Complete => {
|
||||||
// Parse the content to get file information using CreateFilesOutput
|
// Parse the content to get file information using CreateFilesOutput
|
||||||
let create_files_result = serde_json::from_str::<CreateFilesOutput>(&content)?;
|
let create_files_result = match serde_json::from_str::<CreateFilesOutput>(&content) {
|
||||||
|
Ok(result) => result,
|
||||||
|
Err(_) => return Ok(vec![]), // Silently ignore parsing errors
|
||||||
|
};
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
|
|
||||||
for file in create_files_result.files {
|
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)
|
Ok(messages)
|
||||||
}
|
}
|
||||||
_ => Err(anyhow::anyhow!("Tool create file only supports complete.")),
|
_ => Err(anyhow::anyhow!("Tool create file only supports complete.")),
|
||||||
|
|
|
@ -247,11 +247,27 @@ impl AgentThreadHandler {
|
||||||
if let Ok(msg) = msg_result {
|
if let Ok(msg) = msg_result {
|
||||||
match transform_message(chat_id, message_id, msg) {
|
match transform_message(chat_id, message_id, msg) {
|
||||||
Ok((transformed_messages, event)) => {
|
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
|
// 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
|
// Send websocket messages as before
|
||||||
for transformed in transformed_messages {
|
for transformed in non_empty_messages {
|
||||||
let response = WsResponseMessage::new_no_user(
|
let response = WsResponseMessage::new_no_user(
|
||||||
WsRoutes::Threads(ThreadRoute::Post),
|
WsRoutes::Threads(ThreadRoute::Post),
|
||||||
WsEvent::Threads(event.clone()),
|
WsEvent::Threads(event.clone()),
|
||||||
|
|
Loading…
Reference in New Issue