file unique id

This commit is contained in:
dal 2025-03-05 14:51:13 -07:00
parent 070a5c7455
commit 97656868d3
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 9 additions and 15 deletions

View File

@ -1182,16 +1182,8 @@ fn transform_assistant_tool_message(
let mut updated_files = std::collections::HashMap::new(); let mut updated_files = std::collections::HashMap::new();
for (file_id, file_content) in file.files.iter() { for (file_id, file_content) in file.files.iter() {
let temp_file_id = if file.message_type == "files" { // Use the same temporary ID that was generated in the streaming parser
use std::collections::hash_map::DefaultHasher; // This ensures consistency with the IDs generated earlier
use std::hash::{Hash, Hasher};
let mut hasher = DefaultHasher::new();
file_content.file_name.hash(&mut hasher);
format!("temp_{}", hasher.finish())
} else {
file_id.clone()
};
let chunk_id = format!("{}_{}", file.id, file_content.file_name); let chunk_id = format!("{}_{}", file.id, file_content.file_name);
if let Some(chunk) = &file_content.file.text_chunk { if let Some(chunk) = &file_content.file.text_chunk {
@ -1201,8 +1193,9 @@ fn transform_assistant_tool_message(
let mut updated_content = file_content.clone(); let mut updated_content = file_content.clone();
updated_content.file.text_chunk = Some(delta); updated_content.file.text_chunk = Some(delta);
updated_content.file.text = None; updated_content.file.text = None;
updated_content.id = temp_file_id.clone(); // Keep the original ID which should already be the temp ID
updated_files.insert(temp_file_id, updated_content); updated_content.id = file_id.clone();
updated_files.insert(file_id.clone(), updated_content);
has_updates = true; has_updates = true;
} }
} }

View File

@ -260,12 +260,13 @@ impl StreamingParser {
.and_then(Value::as_str) .and_then(Value::as_str)
.unwrap_or(""); .unwrap_or("");
// Generate a consistent UUID based on the file name
let file_id = Uuid::new_v4().to_string(); let file_id = Uuid::new_v4().to_string();
let buster_file = BusterFile { let buster_file = BusterFile {
id: file_id.clone(), id: file_id.clone(),
file_type: file_type.clone(), file_type: file_type.clone(),
file_name: name.to_string(), file_name: name.clone().to_string(),
version_number: 1, version_number: 1,
version_id: Uuid::new_v4().to_string(), version_id: Uuid::new_v4().to_string(),
status: "loading".to_string(), status: "loading".to_string(),
@ -277,8 +278,8 @@ impl StreamingParser {
metadata: None, metadata: None,
}; };
file_ids.push(file_id.clone()); file_ids.push(name.clone().to_string());
files_map.insert(file_id, buster_file); files_map.insert(name.clone().to_string(), buster_file);
} }
} }
} }