Fetch real model context window from server for session bar
GET /api/model-context?model=<name> 엔드포인트 추가. Claude → 200k 고정, Ollama → /api/show 쿼리 후 model_info 또는 num_ctx 파라미터에서 실제 컨텍스트 크기 추출. 클라이언트: 모델 변경 및 초기 부팅 시 자동 fetch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+22
-8
@@ -3893,14 +3893,25 @@ function setCodeSbTab(tab) {
|
||||
}
|
||||
|
||||
|
||||
function _codeAiCtxMax() {
|
||||
const m = (codeAiModel || '').toLowerCase();
|
||||
if (!m || m.includes('claude')) return 200000;
|
||||
// Common Ollama context windows
|
||||
if (m.includes('llama3') || m.includes('llama-3') || m.includes('qwen')) return 128000;
|
||||
if (m.includes('mistral') || m.includes('mixtral')) return 32000;
|
||||
if (m.includes('gemma')) return 8192;
|
||||
return 32000; // safe default for unknown local models
|
||||
let _codeAiCtxMaxCached = 200000; // default until server responds
|
||||
let _codeAiCtxMaxFetchedFor = ''; // model name the cache is valid for
|
||||
|
||||
function _codeAiCtxMax() { return _codeAiCtxMaxCached; }
|
||||
|
||||
async function _fetchModelCtxMax(model) {
|
||||
const key = model || '';
|
||||
if (key === _codeAiCtxMaxFetchedFor) return; // already fetched for this model
|
||||
_codeAiCtxMaxFetchedFor = key;
|
||||
try {
|
||||
const url = '/api/model-context' + (key ? `?model=${encodeURIComponent(key)}` : '');
|
||||
const r = await fetch(url, { headers: authHeaders() });
|
||||
if (!r.ok) return;
|
||||
const d = await r.json();
|
||||
if (d.contextWindow) {
|
||||
_codeAiCtxMaxCached = d.contextWindow;
|
||||
updateSessionPanel();
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
function updateSessionPanel() {
|
||||
@@ -4143,6 +4154,8 @@ function csbModelChanged() {
|
||||
codeAiModel = sel ? sel.value : '';
|
||||
localStorage.setItem('codeAiModel', codeAiModel);
|
||||
updateCodeAiLabel();
|
||||
_codeAiCtxMaxFetchedFor = ''; // invalidate cache so next fetch runs
|
||||
_fetchModelCtxMax(codeAiModel);
|
||||
}
|
||||
|
||||
function csbFontSize(val) {
|
||||
@@ -4460,6 +4473,7 @@ function setupCodeVResize() {
|
||||
try { const inp = document.getElementById('csb-termpath'); if (inp && localTermPath) inp.value = localTermPath; } catch (e) {}
|
||||
try { await restoreLocalDirHandle(); } catch (e) {}
|
||||
try { updateSessionPanel(); } catch (e) {}
|
||||
try { _fetchModelCtxMax(codeAiModel); } catch (e) {}
|
||||
try { codeSbRefresh(); } catch (e) {}
|
||||
try { companionConnect(); } catch (e) {}
|
||||
// 히스토리 없으면 세션 목록 표시
|
||||
|
||||
Reference in New Issue
Block a user