diff --git a/src/gateway/chat/model-routing.ts b/src/gateway/chat/model-routing.ts index 29f367a..d71e321 100644 --- a/src/gateway/chat/model-routing.ts +++ b/src/gateway/chat/model-routing.ts @@ -12,18 +12,21 @@ import { getConfig } from '../../config/config'; export interface RoutingConfig { enabled: boolean; + /** hard_model이 속한 provider. 활성 provider와 다르면 라우팅하지 않는다(다른 백엔드에 모델 이름을 보내면 오류). 비어 있으면 'ollama'로 본다(옛 설정 호환). */ + provider: string; hard_model: string; min_chars: number; extra_patterns: string[]; } -const DEFAULTS: RoutingConfig = { enabled: false, hard_model: '', min_chars: 1500, extra_patterns: [] }; +const DEFAULTS: RoutingConfig = { enabled: false, provider: 'ollama', hard_model: '', min_chars: 1500, extra_patterns: [] }; export function getRoutingConfig(): RoutingConfig { try { const r = (getConfig().getConfig() as any)?.models?.routing || {}; return { enabled: r.enabled === true, + provider: String(r.provider || DEFAULTS.provider).trim() || 'ollama', hard_model: String(r.hard_model || DEFAULTS.hard_model).trim(), min_chars: Number(r.min_chars) > 0 ? Number(r.min_chars) : DEFAULTS.min_chars, extra_patterns: Array.isArray(r.extra_patterns) ? r.extra_patterns.map(String) : [], @@ -47,11 +50,11 @@ export interface RouteDecision { model?: string; reason?: string } export function decideRoute(message: string, opts: { skip?: boolean; hasImages?: boolean } = {}): RouteDecision { const cfg = getRoutingConfig(); if (!cfg.enabled || !cfg.hard_model || opts.skip || opts.hasImages) return {}; - // hard_model은 Ollama 모델 이름이다. 활성 provider가 Ollama 계열이 아니면(OpenAI/Anthropic/Gemini 등) - // 그 이름을 다른 백엔드에 보내면 모델 없음 오류가 나므로 라우팅하지 않는다. + // hard_model은 routing.provider 소속 모델 이름이다. 활성 provider가 다르면(예: 설정은 ollama용인데 지금은 + // anthropic) 그 이름을 엉뚱한 백엔드에 보내 "모델 없음" 오류가 나므로 라우팅하지 않는다. try { - const prov = String(((getConfig().getConfig() as any)?.llm?.provider) || 'ollama'); - if (prov !== 'ollama') return {}; + const active = String(((getConfig().getConfig() as any)?.llm?.provider) || 'ollama'); + if (active !== cfg.provider) return {}; } catch { /* 설정을 못 읽으면 기본(ollama)으로 간주 */ } const text = String(message || ''); for (const p of HARD_PATTERNS) if (p.re.test(text)) return { model: cfg.hard_model, reason: p.reason }; diff --git a/src/gateway/routes/settings.ts b/src/gateway/routes/settings.ts index d700438..1235b05 100644 --- a/src/gateway/routes/settings.ts +++ b/src/gateway/routes/settings.ts @@ -197,6 +197,8 @@ export function registerSettingsRoutes(app: Express): void { const r = ((cm.getConfig() as any).models?.routing) || {}; res.json({ enabled: r.enabled === true, + provider: String(r.provider || 'ollama'), + active_provider: String(((cm.getConfig() as any).llm?.provider) || 'ollama'), hard_model: String(r.hard_model || ''), min_chars: Number(r.min_chars) > 0 ? Number(r.min_chars) : 1500, extra_patterns: Array.isArray(r.extra_patterns) ? r.extra_patterns.map(String) : [], @@ -215,6 +217,8 @@ export function registerSettingsRoutes(app: Express): void { } const routing = { enabled: b.enabled === undefined ? prev.enabled === true : b.enabled === true, + // 저장하는 시점의 활성 provider를 hard_model의 소속으로 기록한다(명시하면 그 값) + provider: String(b.provider || ((cm.getConfig() as any).llm?.provider) || 'ollama'), hard_model: b.hard_model === undefined ? String(prev.hard_model || '') : String(b.hard_model).trim().slice(0, 120), min_chars: Number(b.min_chars) > 0 ? Math.min(Number(b.min_chars), 100000) : (Number(prev.min_chars) > 0 ? Number(prev.min_chars) : 1500), extra_patterns: extra, diff --git a/web-ui/html/index.html b/web-ui/html/index.html index 5796dc3..f759b73 100644 --- a/web-ui/html/index.html +++ b/web-ui/html/index.html @@ -1118,6 +1118,7 @@