Merge branch 'evals' of https://github.com/buster-so/buster into evals

This commit is contained in:
Nate Kelley 2025-03-13 15:35:00 -06:00
commit b70a992312
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,30 @@
use anyhow::Result;
use diesel::prelude::*;
use diesel_async::RunQueryDsl;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use uuid::Uuid;
use database::{pool::get_pg_pool, schema::messages};
#[derive(Debug, Serialize, Deserialize)]
pub struct GetRawLlmMessagesRequest {
pub chat_id: Uuid,
}
pub async fn get_raw_llm_messages_handler(chat_id: Uuid) -> Result<Value> {
let pool = get_pg_pool();
let mut conn = pool.get().await?;
// Get messages for the chat, ordered by creation time
let raw_llm_messages: Value = messages::table
.filter(messages::chat_id.eq(chat_id))
.filter(messages::deleted_at.is_null())
.order_by(messages::created_at.desc())
.select(messages::raw_llm_messages)
.order_by(messages::created_at.desc())
.first::<Value>(&mut conn)
.await?;
Ok(raw_llm_messages)
}

View File

@ -1,4 +1,5 @@
pub mod get_chat_handler;
pub mod get_raw_llm_messages_handler;
pub mod post_chat_handler;
pub mod update_chats_handler;
pub mod delete_chats_handler;
@ -8,6 +9,7 @@ pub mod context_loaders;
pub mod list_chats_handler;
pub use get_chat_handler::get_chat_handler;
pub use get_raw_llm_messages_handler::get_raw_llm_messages_handler;
pub use post_chat_handler::post_chat_handler;
pub use update_chats_handler::update_chats_handler;
pub use delete_chats_handler::delete_chats_handler;

View File

@ -0,0 +1,21 @@
use axum::{
extract::{Path, State},
Extension, Json,
http::StatusCode,
response::IntoResponse,
};
use handlers::chats::get_raw_llm_messages_handler;
use middleware::AuthenticatedUser;
use serde_json::Value;
use uuid::Uuid;
use crate::routes::rest::ApiResponse;
pub async fn get_chat_raw_llm_messages(
Extension(user): Extension<AuthenticatedUser>,
Path(chat_id): Path<Uuid>,
) -> Result<ApiResponse<Value>, (StatusCode, &'static str)> {
match get_raw_llm_messages_handler(chat_id).await {
Ok(response) => Ok(ApiResponse::JsonData(response)),
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, "Failed to get raw LLM messages")),
}
}

View File

@ -5,12 +5,14 @@ use axum::{
mod delete_chats;
mod get_chat;
mod get_chat_raw_llm_messages;
mod list_chats;
mod post_chat;
mod update_chats;
pub use delete_chats::delete_chats_route;
pub use get_chat::get_chat_route;
pub use get_chat_raw_llm_messages::get_chat_raw_llm_messages;
pub use list_chats::list_chats_route;
pub use post_chat::post_chat_route;
pub use update_chats::update_chats_route;
@ -22,4 +24,5 @@ pub fn router() -> Router {
.route("/", put(update_chats_route))
.route("/", delete(delete_chats_route))
.route("/:id", get(get_chat_route))
.route("/:id/raw_llm_messages", get(get_chat_raw_llm_messages))
}