mirror of https://github.com/buster-so/buster.git
final touches on chat restoration
This commit is contained in:
parent
3c9c014ede
commit
2c659955ed
|
@ -13,8 +13,8 @@ use serde::{Deserialize, Serialize};
|
|||
use serde_json::{json, Value};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::chats::types::ChatWithMessages;
|
||||
use crate::chats::get_chat_handler::get_chat_handler;
|
||||
use crate::chats::types::ChatWithMessages;
|
||||
// Import public handler types directly
|
||||
use crate::dashboards::{update_dashboard_handler, DashboardUpdateRequest};
|
||||
use crate::metrics::{update_metric_handler, UpdateMetricRequest};
|
||||
|
@ -62,16 +62,17 @@ pub async fn restore_chat_handler(
|
|||
};
|
||||
|
||||
// Call the metric update handler through the public module function
|
||||
let updated_metric = update_metric_handler(&request.asset_id, user, metric_request).await?;
|
||||
let updated_metric =
|
||||
update_metric_handler(&request.asset_id, user, metric_request).await?;
|
||||
|
||||
// Return the file information
|
||||
(
|
||||
"metric".to_string(),
|
||||
updated_metric.name,
|
||||
updated_metric.id,
|
||||
updated_metric.versions.len() as i32 // Get version number from versions length
|
||||
updated_metric.versions.len() as i32, // Get version number from versions length
|
||||
)
|
||||
},
|
||||
}
|
||||
AssetType::DashboardFile => {
|
||||
// Create a dashboard update request with only the restore_to_version parameter
|
||||
let dashboard_request = DashboardUpdateRequest {
|
||||
|
@ -80,21 +81,23 @@ pub async fn restore_chat_handler(
|
|||
};
|
||||
|
||||
// Call the dashboard update handler through the public module function
|
||||
let updated_dashboard = update_dashboard_handler(
|
||||
request.asset_id,
|
||||
dashboard_request,
|
||||
user
|
||||
).await?;
|
||||
let updated_dashboard =
|
||||
update_dashboard_handler(request.asset_id, dashboard_request, user).await?;
|
||||
|
||||
// Return the file information
|
||||
(
|
||||
"dashboard".to_string(),
|
||||
updated_dashboard.dashboard.name,
|
||||
updated_dashboard.dashboard.id,
|
||||
updated_dashboard.dashboard.version_number
|
||||
updated_dashboard.dashboard.version_number,
|
||||
)
|
||||
},
|
||||
_ => return Err(anyhow!("Unsupported asset type for restoration: {:?}", request.asset_type)),
|
||||
}
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"Unsupported asset type for restoration: {:?}",
|
||||
request.asset_type
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
// Step 2: Get the most recent message to copy raw_llm_messages
|
||||
|
@ -162,14 +165,21 @@ pub async fn restore_chat_handler(
|
|||
// Create restoration message text response
|
||||
let restoration_text = format!(
|
||||
"Version {} was created by restoring version {}",
|
||||
version_number,
|
||||
request.version_number
|
||||
version_number, request.version_number
|
||||
);
|
||||
|
||||
// Create file response message for the restored asset
|
||||
|
||||
// Create response messages array with both text and file response
|
||||
let response_messages = json!([
|
||||
// Text response message
|
||||
{
|
||||
"id": format!("chatcmpl-{}", Uuid::new_v4().to_string().replace("-", "")),
|
||||
"type": "text",
|
||||
"message": restoration_text,
|
||||
"message_chunk": null,
|
||||
"is_final_message": true
|
||||
},
|
||||
// File response message
|
||||
{
|
||||
"id": version_id.to_string(),
|
||||
|
@ -186,14 +196,6 @@ pub async fn restore_chat_handler(
|
|||
"version_id": version_id,
|
||||
"version_number": version_number,
|
||||
"filter_version_id": null
|
||||
},
|
||||
// Text response message
|
||||
{
|
||||
"id": format!("chatcmpl-{}", Uuid::new_v4().to_string().replace("-", "")),
|
||||
"type": "text",
|
||||
"message": restoration_text,
|
||||
"message_chunk": null,
|
||||
"is_final_message": true
|
||||
}
|
||||
]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue