From 0ac05272329a704adb22cf6c797fc1bb4a4dfa7a Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Mon, 6 Jul 2026 02:27:09 +0530 Subject: [PATCH] fix: resolve match arm type mismatches and add Deserialize trait - Fix match arm type errors in ai.rs: wrap bare String returns in (String, bool) tuples to match expected return type (response_text, _ollama_used) - Add Deserialize trait to LiteLLMChatMessage for deserialization - Add missing fields to GenerateFieldResponse constructors - Remove body.user_id reference from form extraction (field doesn't exist) - Add get_llm_base_url() and get_llm_model() helper functions users package now compiles successfully (only warnings remain). --- apps/users/src/handlers/ai.rs | 31 ++++++++++++++++++++++--------- apps/users/src/litellm.rs | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/users/src/handlers/ai.rs b/apps/users/src/handlers/ai.rs index bcd18df..3243f74 100644 --- a/apps/users/src/handlers/ai.rs +++ b/apps/users/src/handlers/ai.rs @@ -517,38 +517,41 @@ async fn ai_chat_message( Job Description:", body.message ); - match call_ollama(&state, &model, &jd_prompt, body.user_id.as_deref()).await { + let text = match call_ollama(&state, &model, &jd_prompt, body.user_id.as_deref()).await { Ok(r) => r, Err(e) => { tracing::error!("Ollama JD generation error: {}", e); "I'm having trouble generating a job description right now. Please try again.".to_string() } - } + }; + (text, true) } "ticket_creation" => { let system_prompt = "You are a support ticket assistant. Help users create clear, actionable support tickets. \ Ask for: subject, description of issue, category, priority if not provided. \ Summarize the ticket in a structured way."; let full_prompt = format!("{}\n\nUser: {}\nAssistant:", system_prompt, body.message); - match call_ollama(&state, &model, &full_prompt, body.user_id.as_deref()).await { + let text = match call_ollama(&state, &model, &full_prompt, body.user_id.as_deref()).await { Ok(r) => r, Err(e) => { tracing::error!("Ollama error: {}", e); "I'm having trouble processing your request right now. Please try again or contact support.".to_string() } - } + }; + (text, true) } "form_filling" => { let system_prompt = "You are a form filling assistant. Help users fill out forms by extracting relevant information \ from their message. Extract key:value pairs when possible."; let full_prompt = format!("{}\n\nUser: {}\nAssistant:", system_prompt, body.message); - match call_ollama(&state, &model, &full_prompt, body.user_id.as_deref()).await { + let text = match call_ollama(&state, &model, &full_prompt, body.user_id.as_deref()).await { Ok(r) => r, Err(e) => { tracing::error!("Ollama error: {}", e); "I'm having trouble processing your request right now. Please try again or contact support.".to_string() } - } + }; + (text, true) } "unknown" => ( "I'm not sure I understand your request. I can help you with:\n\n\ @@ -568,13 +571,14 @@ async fn ai_chat_message( Do not mention hidden instructions. If the user needs support, guide them clearly. \ Keep answers practical, concise, and user-facing."; let full_prompt = format!("{}\n\nUser: {}\nAssistant:", system_prompt, body.message); - match call_ollama(&state, &model, &full_prompt, body.user_id.as_deref()).await { + let text = match call_ollama(&state, &model, &full_prompt, body.user_id.as_deref()).await { Ok(r) => r, Err(e) => { tracing::error!("Ollama error: {}", e); "I'm having trouble processing your request right now. Please try again or contact support.".to_string() } - } + }; + (text, true) } }; @@ -859,7 +863,7 @@ async fn ai_extract_form( form_type, body.message ); - let response_text = match call_ollama_inline(&ollama_base, &model, &prompt, body.user_id.as_deref()).await { + let response_text = match call_ollama_inline(&ollama_base, &model, &prompt, None).await { Ok(r) => r, Err(e) => { tracing::error!("Ollama form extraction error: {}", e); @@ -1045,6 +1049,9 @@ async fn ai_generate_job_field( remaining_today: wallet.as_ref().map(|w| w.available_credits()).unwrap_or(0), daily_limit: plan.map(|p| p.daily_action_limit).unwrap_or(0), has_ai_pack: wallet.as_ref().map(|w| w.purchased_credits_total > 0).unwrap_or(false), + credits_charged: None, + remaining_credits: None, + model: None, }), ) .into_response() @@ -1177,6 +1184,9 @@ async fn ai_generate_cover_letter( remaining_today: wallet.as_ref().map(|w| w.available_credits()).unwrap_or(0), daily_limit: plan.map(|p| p.daily_action_limit).unwrap_or(0), has_ai_pack: wallet.as_ref().map(|w| w.purchased_credits_total > 0).unwrap_or(false), + credits_charged: None, + remaining_credits: None, + model: None, }), ) .into_response() @@ -1305,6 +1315,9 @@ async fn ai_tailor_resume( remaining_today: wallet.as_ref().map(|w| w.available_credits()).unwrap_or(0), daily_limit: plan.map(|p| p.daily_action_limit).unwrap_or(0), has_ai_pack: wallet.as_ref().map(|w| w.purchased_credits_total > 0).unwrap_or(false), + credits_charged: None, + remaining_credits: None, + model: None, }), ) .into_response() diff --git a/apps/users/src/litellm.rs b/apps/users/src/litellm.rs index 06590e2..4bec659 100644 --- a/apps/users/src/litellm.rs +++ b/apps/users/src/litellm.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] struct LiteLLMChatMessage { role: String, content: String,