feat: add Vision LLM integration (CLIP + Qwen3-VL cascade)

- Add Qwen3-VL dynamic management (start/stop/status CLI)
- Add CLIP + Qwen3-VL cascade detection strategy
- Add Vision CLI commands (vision start/stop/status, detect)
- Add cascade_vision processor module
- Add clip processor module
- Add qwen_vl_manager module

Changes:
- scripts/start_qwen3vl.sh, stop_qwen3vl.sh: Qwen3-VL management scripts
- src/core/vision/: Qwen3-VL manager module
- src/core/processor/cascade_vision.rs: CLIP + Qwen3-VL cascade logic
- src/core/processor/clip.rs: CLIP classification and detection
- src/api/clip_api.rs: CLIP API endpoints
- src/cli/vision.rs: Vision CLI implementation
- src/cli/args.rs: Add Vision and Detect commands
- src/main.rs: Integrate Vision CLI
- src/core/mod.rs: Add vision module
- src/core/processor/mod.rs: Add cascade_vision module
This commit is contained in:
Accusys
2026-06-13 16:25:52 +08:00
parent 834b0d4865
commit 17e4e15860
37 changed files with 2185 additions and 294 deletions
+3 -6
View File
@@ -1,10 +1,10 @@
use anyhow::Result;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::time::Duration;
use tracing::{debug, error, warn};
use crate::core::config;
use crate::core::llm::function_calling::LLM_CLIENT;
#[derive(Debug, Serialize)]
struct ChatRequest {
@@ -39,10 +39,6 @@ pub async fn generate_5w1h_summary(scene_text: &str) -> Result<String> {
return Ok("LLM Disabled".to_string());
}
let client = Client::builder()
.timeout(Duration::from_secs(*config::llm::SUMMARY_TIMEOUT_SECS))
.build()?;
let prompt = format!(
r#"Analyze the following video scene transcript and provide a concise 5W1H+ summary in JSON format.
Focus on: Who, What, Where, When, Why, How, and Key Objects/Actions.
@@ -82,9 +78,10 @@ pub async fn generate_5w1h_summary(scene_text: &str) -> Result<String> {
debug!("Calling LLM for summary: {}", *config::llm::SUMMARY_URL);
let res = client
let res = LLM_CLIENT
.post(&*config::llm::SUMMARY_URL)
.json(&req)
.timeout(Duration::from_secs(*config::llm::SUMMARY_TIMEOUT_SECS))
.send()
.await?;
+24 -12
View File
@@ -1,8 +1,18 @@
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use crate::core::config;
/// Shared HTTP client with connection pooling for all LLM calls
pub static LLM_CLIENT: Lazy<reqwest::Client> = Lazy::new(|| {
reqwest::Client::builder()
.pool_max_idle_per_host(32)
.pool_idle_timeout(std::time::Duration::from_secs(300))
.build()
.expect("Failed to create shared LLM HTTP client")
});
/// A tool/function definition for Gemma4 function calling
#[derive(Debug, Clone, Serialize)]
pub struct ToolDef {
@@ -126,11 +136,11 @@ pub async fn call_llm_vision(
"stream": false,
});
let client = reqwest::Client::builder()
let res = LLM_CLIENT
.post(&llm_vision_url())
.json(&req)
.timeout(std::time::Duration::from_secs(timeout_secs))
.build()?;
let res = client.post(&llm_vision_url()).json(&req).send().await?;
.send().await?;
if !res.status().is_success() {
let text = res.text().await.unwrap_or_default();
anyhow::bail!("Vision LLM API error: {}", text);
@@ -182,13 +192,11 @@ pub async fn call_llm(
max_tokens: u32,
timeout_secs: u64,
) -> anyhow::Result<LlmResponse> {
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(if timeout_secs > 0 {
timeout_secs
} else {
*config::llm::CHAT_TIMEOUT_SECS
}))
.build()?;
let timeout = if timeout_secs > 0 {
timeout_secs
} else {
*config::llm::CHAT_TIMEOUT_SECS
};
let req = ChatRequest {
model: llm_model(),
@@ -199,7 +207,11 @@ pub async fn call_llm(
tools,
};
let res = client.post(&llm_chat_url()).json(&req).send().await?;
let res = LLM_CLIENT
.post(&llm_chat_url())
.json(&req)
.timeout(std::time::Duration::from_secs(timeout))
.send().await?;
if !res.status().is_success() {
let text = res.text().await.unwrap_or_default();
+21 -10
View File
@@ -1,12 +1,12 @@
use std::collections::HashSet;
use anyhow::Result;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::time::Duration;
use tracing::{debug, warn};
use crate::core::config;
use crate::core::llm::function_calling::LLM_CLIENT;
#[derive(Debug, Serialize)]
struct ChatRequest {
@@ -38,7 +38,10 @@ struct RerankResponse {
ranked: Vec<usize>,
}
pub async fn rerank_search_results(query: &str, candidates: &[(usize, &str)]) -> Result<Vec<usize>> {
pub async fn rerank_search_results(
query: &str,
candidates: &[(usize, &str)],
) -> Result<Vec<usize>> {
if candidates.is_empty() {
return Ok(vec![]);
}
@@ -67,10 +70,6 @@ Include every chunk number exactly once. Only respond with the JSON."#,
query, chunks_text
);
let client = Client::builder()
.timeout(Duration::from_secs(15))
.build()?;
let req = ChatRequest {
model: config::llm::CHAT_MODEL.clone(),
messages: vec![
@@ -88,11 +87,16 @@ Include every chunk number exactly once. Only respond with the JSON."#,
stream: false,
};
debug!("LLM rerank: {} candidates for query '{}'", candidates.len(), query);
debug!(
"LLM rerank: {} candidates for query '{}'",
candidates.len(),
query
);
let res = client
let res = LLM_CLIENT
.post(&*config::llm::CHAT_URL)
.json(&req)
.timeout(Duration::from_secs(15))
.send()
.await?;
@@ -116,7 +120,11 @@ Include every chunk number exactly once. Only respond with the JSON."#,
// Strip markdown code fences if present
let content = if content.starts_with("```") {
let lines: Vec<&str> = content.lines().collect();
let start = if lines.first().map(|l| l.contains("```")).unwrap_or(false) { 1 } else { 0 };
let start = if lines.first().map(|l| l.contains("```")).unwrap_or(false) {
1
} else {
0
};
let end = if lines.last().map(|l| l.contains("```")).unwrap_or(false) {
lines.len().saturating_sub(1)
} else {
@@ -163,6 +171,9 @@ Include every chunk number exactly once. Only respond with the JSON."#,
}
}
warn!("LLM rerank: could not parse response — content: {}", &content[..content.len().min(200)]);
warn!(
"LLM rerank: could not parse response — content: {}",
&content[..content.len().min(200)]
);
Ok(candidates.iter().map(|(idx, _)| *idx).collect())
}