refactor: unified LLM config - CHAT_URL/VISION_URL/SUMMARY_URL with env var overrides

This commit is contained in:
Accusys
2026-05-22 15:47:17 +08:00
parent a78b5bc12b
commit bd82028f34
4 changed files with 72 additions and 42 deletions

View File

@@ -41,10 +41,10 @@ async fn translate_text(
req.target_language, req.text
);
// Call Gemma4 via llama.cpp (port 8082, OpenAI-compatible API)
// Call LLM via configurable endpoint
let client = Client::new();
let llm_url = "http://localhost:8082/v1/chat/completions";
let model = "google_gemma-4-26B-A4B-it-Q5_K_M.gguf".to_string();
let llm_url = crate::core::config::llm::CHAT_URL.as_str();
let model = crate::core::config::llm::CHAT_MODEL.as_str();
let body = serde_json::json!({
"model": model,
@@ -71,20 +71,15 @@ async fn translate_text(
)
})?;
let translated_text = llm_resp
.get("choices")
.and_then(|c| c.as_array())
.and_then(|c| c.first())
.and_then(|c| c.get("message"))
.and_then(|m| m.get("content"))
.and_then(|v| v.as_str())
.unwrap_or("Translation failed")
let translated_text = llm_resp["choices"][0]["message"]["content"]
.as_str()
.unwrap_or("")
.to_string();
Ok(Json(TranslationResponse {
success: true,
translated_text,
source_language_detected: req.source_language.unwrap_or("unknown".to_string()),
model_used: model,
source_language_detected: req.source_language.unwrap_or_else(|| "auto".to_string()),
model_used: model.to_string(),
}))
}

View File

@@ -96,27 +96,11 @@ struct SceneSummaryResult {
// ── LLM Endpoint ──
fn llm_base_url() -> String {
let v = std::env::var("MOMENTRY_LLM_URL");
if v.is_ok() {
return v.unwrap();
}
let v = std::env::var("MOMENTRY_LLM_SUMMARY_URL");
if v.is_ok() {
return v.unwrap();
}
"http://localhost:8082/v1/chat/completions".to_string()
crate::core::config::llm::SUMMARY_URL.clone()
}
fn llm_model() -> String {
let v = std::env::var("MOMENTRY_LLM_MODEL");
if v.is_ok() {
return v.unwrap();
}
let v = std::env::var("MOMENTRY_LLM_SUMMARY_MODEL");
if v.is_ok() {
return v.unwrap();
}
"google_gemma-4-26B-A4B-it-Q5_K_M.gguf".to_string()
crate::core::config::llm::SUMMARY_MODEL.clone()
}
// ── Data Fetching ──