fix: use content instead of reasoning_content for VLM
- Gemma4 returns both content and reasoning_content - reasoning_content is the thinking process, not the final answer - content contains the actual scene description - Changed priority: content first, reasoning_content as fallback Fixes: Scene VLM generated 0 descriptions issue Root cause: Using reasoning_content (thinking) instead of content (answer)
This commit is contained in:
@@ -493,7 +493,12 @@ impl SceneVlmProcessor {
|
||||
let vlm_url = crate::core::config::llm::VISION_URL.clone();
|
||||
let vlm_model = crate::core::config::llm::VISION_MODEL.clone();
|
||||
|
||||
tracing::debug!("[VLM API] Calling {} with model {} (language: {})", vlm_url, vlm_model, language);
|
||||
tracing::debug!(
|
||||
"[VLM API] Calling {} with model {} (language: {})",
|
||||
vlm_url,
|
||||
vlm_model,
|
||||
language
|
||||
);
|
||||
|
||||
// Language-specific prompts
|
||||
let (prompt, max_tokens) = match language {
|
||||
@@ -566,13 +571,23 @@ impl SceneVlmProcessor {
|
||||
.and_then(|c| c.get("message"))
|
||||
.context("Invalid VLM API response structure")?;
|
||||
|
||||
// Try reasoning_content first (Gemma4), fall back to content
|
||||
let content = message
|
||||
.get("reasoning_content")
|
||||
// Try content first (final answer), fall back to reasoning_content if content is empty
|
||||
let content = match message
|
||||
.get("content")
|
||||
.and_then(|c| c.as_str())
|
||||
.or_else(|| message.get("content").and_then(|c| c.as_str()))
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
.filter(|s| !s.is_empty())
|
||||
{
|
||||
Some(s) => s.to_string(),
|
||||
None => message
|
||||
.get("reasoning_content")
|
||||
.and_then(|c| c.as_str())
|
||||
.unwrap_or("")
|
||||
.to_string(),
|
||||
};
|
||||
|
||||
if content.is_empty() {
|
||||
anyhow::bail!("VLM returned empty response");
|
||||
}
|
||||
|
||||
if content.is_empty() {
|
||||
tracing::warn!("[VLM API] Empty response for {:?}", image_path);
|
||||
@@ -631,10 +646,12 @@ impl SceneVlmProcessor {
|
||||
scene.vlm_description = Some(description_en.clone());
|
||||
scene.vlm_objects = objects.clone();
|
||||
scene.vlm_tags = tags.clone();
|
||||
|
||||
|
||||
// Generate localized description if needed
|
||||
if preferred_language != "en" {
|
||||
match Self::generate_scene_description(&frame_path, &preferred_language).await {
|
||||
match Self::generate_scene_description(&frame_path, &preferred_language)
|
||||
.await
|
||||
{
|
||||
Ok((description_localized, _, _)) => {
|
||||
scene.vlm_description_localized = Some(description_localized);
|
||||
tracing::info!(
|
||||
@@ -644,16 +661,17 @@ impl SceneVlmProcessor {
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("[Scene VLM] ⚠️ Scene {} localized failed: {}", idx, e);
|
||||
tracing::warn!(
|
||||
"[Scene VLM] ⚠️ Scene {} localized failed: {}",
|
||||
idx,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tracing::info!(
|
||||
"[Scene VLM] ✅ Scene {}: EN only",
|
||||
idx
|
||||
);
|
||||
tracing::info!("[Scene VLM] ✅ Scene {}: EN only", idx);
|
||||
}
|
||||
|
||||
|
||||
scene.vlm_status = VlmStatus::Completed;
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user