1- // src/api/handlers/evals.rs - Updated to pass db_pool to runner
1+ // src/api/handlers/evals.rs - Complete fixed version
22use actix_web:: { web, HttpResponse , Result } ;
33use serde:: { Deserialize , Serialize } ;
44use uuid:: Uuid ;
@@ -56,10 +56,10 @@ pub async fn run_eval(
5656 metadata : None ,
5757 } ;
5858
59- // 🆕 Pass db_pool to runner for dynamic judge prompt loading
60- let db_pool_ref = state. db_pool . as_ref ( ) ;
59+ // Extract the pool reference properly for the new Option<Arc<SqlitePool>> structure
60+ let db_pool_ref = state. db_pool . as_ref ( ) . map ( |arc| arc . as_ref ( ) ) ;
6161
62- match runner:: run_eval_with_pool ( & state. config , & eval_config, & state. client , db_pool_ref. as_ref ( ) ) . await {
62+ match runner:: run_eval_with_pool ( & state. config , & eval_config, & state. client , db_pool_ref) . await {
6363 Ok ( result) => {
6464 let status = if let Some ( judge) = & result. judge_result {
6565 match judge. verdict {
@@ -88,14 +88,14 @@ pub async fn run_eval(
8888 } ;
8989
9090 // Save to database
91- if let Some ( pool ) = state. db_pool . as_ref ( ) {
91+ if let Some ( pool_arc ) = state. db_pool . as_ref ( ) {
9292 println ! ( "💾 Saving successful evaluation to database: {}" , eval_id) ;
9393 let api_response = crate :: models:: ApiResponse {
9494 id : eval_id. clone ( ) ,
9595 status : status. to_string ( ) ,
9696 result : crate :: models:: EvalResult :: Success ( result) ,
9797 } ;
98- match crate :: database:: save_evaluation ( pool , & api_response) . await {
98+ match crate :: database:: save_evaluation ( pool_arc , & api_response) . await {
9999 Ok ( _) => println ! ( "✅ Successfully saved evaluation {} to database" , eval_id) ,
100100 Err ( e) => {
101101 eprintln ! ( "❌ Failed to save evaluation to database: {}" , e) ;
@@ -134,7 +134,7 @@ pub async fn run_eval(
134134 } ;
135135
136136 // Save error to database
137- if let Some ( pool ) = state. db_pool . as_ref ( ) {
137+ if let Some ( pool_arc ) = state. db_pool . as_ref ( ) {
138138 println ! ( "💾 Saving error evaluation to database: {}" , eval_id) ;
139139 let api_response = crate :: models:: ApiResponse {
140140 id : eval_id. clone ( ) ,
@@ -143,7 +143,7 @@ pub async fn run_eval(
143143 message : error_string. clone ( ) ,
144144 } ) ,
145145 } ;
146- match crate :: database:: save_evaluation ( pool , & api_response) . await {
146+ match crate :: database:: save_evaluation ( pool_arc , & api_response) . await {
147147 Ok ( _) => println ! ( "✅ Successfully saved error evaluation {} to database" , eval_id) ,
148148 Err ( e) => {
149149 eprintln ! ( "❌ Failed to save error evaluation to database: {}" , e) ;
@@ -170,14 +170,14 @@ pub async fn run_batch(
170170 let batch_id = Uuid :: new_v4 ( ) . to_string ( ) ;
171171 let total = eval_configs. len ( ) ;
172172
173- // 🆕 Pass db_pool to runner for dynamic judge prompt loading
174- let db_pool_ref = state. db_pool . as_ref ( ) ;
173+ // Extract the pool reference properly for the new Option<Arc<SqlitePool>> structure
174+ let db_pool_ref = state. db_pool . as_ref ( ) . map ( |arc| arc . as_ref ( ) ) ;
175175
176176 let results = runner:: run_batch_evals_with_pool (
177177 & state. config ,
178178 eval_configs. into_inner ( ) ,
179179 & state. client ,
180- db_pool_ref. as_ref ( ) ,
180+ db_pool_ref,
181181 ) . await ;
182182
183183 let mut responses = Vec :: new ( ) ;
@@ -233,13 +233,13 @@ pub async fn run_batch(
233233 error : None ,
234234 } ;
235235
236- if let Some ( pool ) = state. db_pool . as_ref ( ) {
236+ if let Some ( pool_arc ) = state. db_pool . as_ref ( ) {
237237 let api_response = crate :: models:: ApiResponse {
238238 id : eval_id,
239239 status : status. to_string ( ) ,
240240 result : crate :: models:: EvalResult :: Success ( eval_result) ,
241241 } ;
242- if let Err ( e) = crate :: database:: save_evaluation ( pool , & api_response) . await {
242+ if let Err ( e) = crate :: database:: save_evaluation ( pool_arc , & api_response) . await {
243243 log:: error!( "Failed to save batch evaluation to database: {}" , e) ;
244244 }
245245 }
@@ -264,15 +264,15 @@ pub async fn run_batch(
264264 error : Some ( error_string. clone ( ) ) ,
265265 } ;
266266
267- if let Some ( pool ) = state. db_pool . as_ref ( ) {
267+ if let Some ( pool_arc ) = state. db_pool . as_ref ( ) {
268268 let api_response = crate :: models:: ApiResponse {
269269 id : eval_id,
270270 status : "error" . to_string ( ) ,
271271 result : crate :: models:: EvalResult :: Error ( crate :: models:: ApiError {
272272 message : error_string,
273273 } ) ,
274274 } ;
275- if let Err ( e) = crate :: database:: save_evaluation ( pool , & api_response) . await {
275+ if let Err ( e) = crate :: database:: save_evaluation ( pool_arc , & api_response) . await {
276276 log:: error!( "Failed to save batch error to database: {}" , e) ;
277277 }
278278 }
@@ -324,8 +324,8 @@ pub struct HistoryResponse {
324324}
325325
326326pub async fn get_history ( state : web:: Data < AppState > ) -> Result < HttpResponse > {
327- if let Some ( pool ) = state. db_pool . as_ref ( ) {
328- match crate :: database:: get_all_evaluations ( pool ) . await {
327+ if let Some ( pool_arc ) = state. db_pool . as_ref ( ) {
328+ match crate :: database:: get_all_evaluations ( pool_arc ) . await {
329329 Ok ( history) => Ok ( HttpResponse :: Ok ( ) . json ( HistoryResponse { results : history } ) ) ,
330330 Err ( e) => {
331331 log:: error!( "Failed to fetch evaluation history: {}" , e) ;
@@ -345,4 +345,4 @@ pub struct ModelsResponse {
345345
346346pub async fn get_models ( state : web:: Data < AppState > ) -> Result < HttpResponse > {
347347 Ok ( HttpResponse :: Ok ( ) . json ( ModelsResponse { models : state. config . models . clone ( ) } ) )
348- }
348+ }
0 commit comments