refactor: unified LLM config - CHAT_URL/VISION_URL/SUMMARY_URL with env var overrides
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::core::config;
|
||||
|
||||
/// A tool/function definition for Gemma4 function calling
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ToolDef {
|
||||
@@ -75,18 +77,24 @@ pub enum LlmResponse {
|
||||
ToolCalls(Vec<ToolCall>),
|
||||
}
|
||||
|
||||
/// Get the LLM chat URL with fallback chain
|
||||
/// Get the LLM chat URL from centralized config
|
||||
pub fn llm_chat_url() -> String {
|
||||
std::env::var("MOMENTRY_LLM_URL")
|
||||
.or_else(|_| std::env::var("MOMENTRY_LLM_SUMMARY_URL"))
|
||||
.unwrap_or_else(|_| "http://localhost:8082/v1/chat/completions".to_string())
|
||||
config::llm::CHAT_URL.clone()
|
||||
}
|
||||
|
||||
/// Get the LLM model name
|
||||
/// Get the LLM model name from centralized config
|
||||
pub fn llm_model() -> String {
|
||||
std::env::var("MOMENTRY_LLM_MODEL")
|
||||
.or_else(|_| std::env::var("MOMENTRY_LLM_SUMMARY_MODEL"))
|
||||
.unwrap_or_else(|_| "google_gemma-4-26B-A4B-it-Q5_K_M.gguf".to_string())
|
||||
config::llm::CHAT_MODEL.clone()
|
||||
}
|
||||
|
||||
/// Get the vision LLM URL
|
||||
pub fn llm_vision_url() -> String {
|
||||
config::llm::VISION_URL.clone()
|
||||
}
|
||||
|
||||
/// Get the vision LLM model name
|
||||
pub fn llm_vision_model() -> String {
|
||||
config::llm::VISION_MODEL.clone()
|
||||
}
|
||||
|
||||
/// Build a tool definition JSON for function calling
|
||||
@@ -113,7 +121,9 @@ pub async fn call_llm(
|
||||
timeout_secs: u64,
|
||||
) -> anyhow::Result<LlmResponse> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(timeout_secs))
|
||||
.timeout(std::time::Duration::from_secs(
|
||||
if timeout_secs > 0 { timeout_secs } else { *config::llm::CHAT_TIMEOUT_SECS },
|
||||
))
|
||||
.build()?;
|
||||
|
||||
let req = ChatRequest {
|
||||
|
||||
Reference in New Issue
Block a user