feat: OpenAI 모델 목록 조회 라우트 추가, LM Studio thinking 비활성화 스위치

프론트엔드가 예전부터 호출하던 POST /api/openai/models가 백엔드에 구현이
안 되어 있어 항상 404였던 버그 수정 - OpenAICompatAdapter로 실제 OpenAI
API에 모델 목록을 조회하도록 구현.

지서버(LM Studio)의 gemma-4-26b-a4b가 응답당 완성 토큰을 2.5배 더 많이
쓰는 것을 벤치마크로 확인(322 vs 132 토큰/응답, thinking 오버헤드로 추정) -
chat_template_kwargs.enable_thinking=false를 기본 적용하되, 복잡한 질문에서
품질이 떨어질 수 있어 설정 화면(모델 → LM Studio)에 체크박스로 켜고 끌 수
있게 구현. 기본값은 비활성화(현재 상태 유지).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5 committed 2026-08-07 12:57:22 +09:00
1 parent ae6e347339
commit b001cd9318
6 files changed
+47 -1

No files matched your search

+24
View File
@@ -3943,6 +3943,7 @@ app.post('/api/open-path', requireGatewayAuth, async (req, res) => {
// trigger the OpenAI OAuth flow.
import { getProvider, resetProvider, buildProviderForLLM, getModelForRole } from '../providers/factory';
import { OpenAICompatAdapter } from '../providers/openai-compat-adapter';
import { getGoogleUsageToday } from '../providers/google-usage';
import { buildWebhookRouter, resolveHookConfig } from './channels/webhook-handler';
import { getMCPManager } from './infra/mcp-manager';
@@ -4004,6 +4005,29 @@ app.post('/api/models/test', async (req, res) => {
}
});
// POST /api/openai/models — list models for a (possibly not-yet-saved) OpenAI API key,
// used by the Settings → Models → OpenAI panel to populate the model dropdown before the
// key is saved via /api/settings/provider. The frontend has called this since the OpenAI
// provider was added, but the route was never implemented (always 404'd until now).
app.post('/api/openai/models', async (req, res) => {
try {
let apiKey = String(req.body?.api_key || '').trim();
if (apiKey === '••••••••') {
apiKey = ((getConfig().getConfig() as any)?.llm?.providers?.openai?.api_key) || '';
}
if (!apiKey) { res.json({ success: false, models: [], error: 'API 키가 필요합니다' }); return; }
const adapter = new OpenAICompatAdapter({ endpoint: 'https://api.openai.com', apiKey, providerId: 'openai' });
const models = await adapter.listModels();
res.json({
success: models.length > 0,
models: models.map(m => m.name),
error: models.length ? undefined : '모델 목록을 가져오지 못했습니다 (키를 확인하세요)',
});
} catch (err: any) {
res.json({ success: false, models: [], error: err.message });
}
});
registerMusicRoutes(app);
// ── Guitar Pro tab search/download (guitarprotabs.org proxy) ─────────────────
+3
View File
@@ -162,6 +162,9 @@ function buildProvider(id: ProviderID, providers: any): LLMProvider {
endpoint: cfg.endpoint || 'http://localhost:1234',
apiKey: cfg.api_key, // LM Studio has optional key support
providerId: 'lm_studio',
// Off by default (measured 2.5x completion-token bloat on gemma-4-26b-a4b, 2026-08-07)
// — only re-enabled if the user explicitly unchecks the Settings toggle.
disableThinking: cfg.disable_thinking !== false,
});
}
+13
View File
@@ -20,6 +20,8 @@ export interface OpenAICompatConfig {
/** Called just before each request to get a fresh token (OAuth providers). */
getToken?: () => Promise<string>;
providerId: ProviderID;
/** Send chat_template_kwargs.enable_thinking=false (llama.cpp/LM Studio switch). */
disableThinking?: boolean;
}
export class OpenAICompatAdapter implements LLMProvider {
@@ -110,6 +112,17 @@ export class OpenAICompatAdapter implements LLMProvider {
body.tools = options!.tools;
body.tool_choice = options?.tool_choice || 'auto';
}
// gemma-4-26b-a4b (and other Gemma 4 checkpoints) think by default under LM Studio's
// llama.cpp backend, and measured completion tokens ran ~2.5x higher than the same
// conversations answered directly (322 vs 132 tokens/response, 2026-08-07 benchmark) —
// the extra generation is the dominant cause of LM Studio being slower than Ollama Cloud,
// not raw GPU throughput. chat_template_kwargs.enable_thinking=false is llama.cpp/LM
// Studio's documented switch for this; harmless to send even for non-thinking models.
// Toggleable (Settings → Models → LM Studio) since disabling it may hurt quality on
// genuinely hard questions — this is a speed/quality trade, not a strict win.
if (this.config.disableThinking) {
body.chat_template_kwargs = { ...(body.chat_template_kwargs || {}), enable_thinking: false };
}
const data = await this.post('/v1/chat/completions', body);
const choice = data.choices?.[0];
+4
View File
@@ -1075,6 +1075,10 @@
<input id="settings-lmstudio-endpoint" type="text" placeholder="http://localhost:1234" style="width:100%;border:1px solid var(--line);border-radius:10px;padding:8px;font-size:12px;font-family:'IBM Plex Mono',monospace" />
<label style="display:block;font-size:12px;color:var(--muted);margin:10px 0 6px">모델 이름</label>
<input id="settings-lmstudio-model" type="text" placeholder="e.g. qwen2.5-7b-instruct" style="width:100%;border:1px solid var(--line);border-radius:10px;padding:8px;font-size:12px;font-family:'IBM Plex Mono',monospace" />
<label style="display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted);margin-top:10px;cursor:pointer">
<input id="settings-lmstudio-disable-thinking" type="checkbox" checked />
생각(thinking) 비활성화 — 답변 전 내부 추론 토큰을 끔 (Gemma 4 등 일부 모델에서 속도 개선, 대신 복잡한 질문 품질은 낮아질 수 있음)
</label>
<div style="display:flex;gap:8px;margin-top:8px">
<button class="btn btn-sm" onclick="refreshProviderModels()" style="background:#fff;border:1px solid var(--line);color:var(--text)">모델 감지</button>
<button class="btn btn-sm" onclick="testProviderConnection()" style="background:#fff;border:1px solid var(--line);color:var(--text)">테스트</button>
+1
View File
@@ -713,6 +713,7 @@ async function saveSettings() {
v('settings-llamacpp-model', pc.llama_cpp?.model);
v('settings-lmstudio-endpoint', pc.lm_studio?.endpoint);
v('settings-lmstudio-model', pc.lm_studio?.model);
{ const cb = document.getElementById('settings-lmstudio-disable-thinking'); if (cb) cb.checked = pc.lm_studio?.disable_thinking !== false; }
const savedPrimary = pc[prov]?.model || data?.models_primary || '';
if (savedPrimary) { const el = document.getElementById('settings-primary-model'); if (el) el.value = savedPrimary; }
_modelSettingsLoaded = true;
+2 -1
View File
@@ -330,6 +330,7 @@ async function loadModelSettings() {
v('settings-llamacpp-model', pc.llama_cpp?.model);
v('settings-lmstudio-endpoint', pc.lm_studio?.endpoint);
v('settings-lmstudio-model', pc.lm_studio?.model);
{ const cb = document.getElementById('settings-lmstudio-disable-thinking'); if (cb) cb.checked = pc.lm_studio?.disable_thinking !== false; }
v('settings-openai-key', pc.openai?.api_key);
v('settings-anthropic-key', pc.anthropic?.api_key);
if (pc.anthropic?.model) { const s = document.getElementById('settings-anthropic-model'); if (s) s.value = pc.anthropic.model; }
@@ -451,7 +452,7 @@ function buildProviderPayload() {
const providers = {};
providers.ollama = { endpoint: document.getElementById('settings-ollama-endpoint')?.value || 'http://localhost:11434', model: document.getElementById('settings-primary-model')?.value || '' };
providers.llama_cpp = { endpoint: document.getElementById('settings-llamacpp-endpoint')?.value || 'http://localhost:8080', model: document.getElementById('settings-llamacpp-model')?.value || '' };
providers.lm_studio = { endpoint: document.getElementById('settings-lmstudio-endpoint')?.value || 'http://localhost:1234', model: document.getElementById('settings-lmstudio-model')?.value || '' };
providers.lm_studio = { endpoint: document.getElementById('settings-lmstudio-endpoint')?.value || 'http://localhost:1234', model: document.getElementById('settings-lmstudio-model')?.value || '', disable_thinking: !!document.getElementById('settings-lmstudio-disable-thinking')?.checked };
providers.openai = { api_key: document.getElementById('settings-openai-key')?.value || '', model: document.getElementById('settings-openai-model')?.value || 'gpt-4o' };
providers.openai_codex = { model: document.getElementById('settings-codex-model')?.value || 'gpt-5.3-codex' };
providers.anthropic = { api_key: document.getElementById('settings-anthropic-key')?.value || '', model: document.getElementById('settings-anthropic-model')?.value || 'claude-sonnet-4-6' };