fix: persist token counts and fix agentic insight_id mapping

- Add prompt_eval_count and eval_count columns to photo_insights so
  token usage from llama-swap/Ollama is stored and returned by the API
- Fix agentic generator return: was (prompt_eval_count, eval_count),
  handler destructured first element as insight_id — now returns
  (insight_id, prompt_eval_count, eval_count)
- Wire prompt_eval_count/eval_count from DB into PhotoInsightResponse
  instead of hardcoded None

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cameron Cordes
2026-05-27 13:47:57 -04:00
parent 449ce1fda1
commit 9654d256f4
6 changed files with 31 additions and 9 deletions
+10 -2
View File
@@ -1439,6 +1439,8 @@ impl InsightGenerator {
min_p,
system_prompt: custom_system_prompt.clone(),
persona_id: None,
prompt_eval_count: None,
eval_count: None,
};
let mut dao = self.insight_dao.lock().expect("Unable to lock InsightDao");
@@ -3808,7 +3810,7 @@ Return ONLY the summary, nothing else."#,
fewshot_source_ids: Vec<i32>,
user_id: i32,
persona_id: String,
) -> Result<(Option<i32>, Option<i32>)> {
) -> Result<(Option<i32>, Option<i32>, Option<i32>)> {
let tracer = global_tracer();
let current_cx = opentelemetry::Context::current();
let mut span = tracer.start_with_context("ai.insight.generate_agentic", &current_cx);
@@ -4190,6 +4192,8 @@ Return ONLY the summary, nothing else."#,
min_p,
system_prompt: custom_system_prompt.clone(),
persona_id: Some(persona_id.clone()),
prompt_eval_count: last_prompt_eval_count,
eval_count: last_eval_count,
};
let stored = {
@@ -4227,7 +4231,11 @@ Return ONLY the summary, nothing else."#,
}
}
Ok((last_prompt_eval_count, last_eval_count))
Ok((
Some(stored_insight.id),
last_prompt_eval_count,
last_eval_count,
))
}
/// Reverse geocode GPS coordinates to human-readable place names