refactor: rewrite model-context to use js-yaml, add context_length to provider form (#177)
* fix: context-length API returns 200K instead of actual model context Two bugs cause the /api/hermes/sessions/context-length endpoint to always return DEFAULT_CONTEXT_LENGTH (200K): 1. getModelContextLength ignores config.yaml model.context_length The function only checks models_dev_cache.json (which doesn't exist in default installations) and falls back to the hardcoded 200K default, completely ignoring the user's explicit model.context_length setting in config.yaml. 2. getDefaultModel regex fails when api_key/base_url come before default The regex /^model:\s*\n\s+default:\s*(.+)$/m assumes 'default' is the first child key under 'model:', but when api_key or base_url appear first in the YAML, the match fails. This causes getModelContextLength to short-circuit to DEFAULT_CONTEXT_LENGTH before even reaching the cache lookup. Fix: - Add getDefaultModelRobust() that extracts the entire model: block first, then searches for default: within it - Add getConfigContextLength() that reads model.context_length from config.yaml as a fallback (matching hermes-agent priority) - Update getModelContextLength() resolution order: 1. models_dev_cache.json (existing) 2. config.yaml model.context_length (new) 3. DEFAULT_CONTEXT_LENGTH (existing fallback) Closes #169 * refactor: rewrite model-context to use js-yaml, add context_length to provider form - Replace fragile regex-based YAML parsing with js-yaml for reliable config.yaml reads - Fix context_length resolution priority: config.yaml override > custom_providers > models_dev_cache > 200K default - Add context_length input field when adding custom providers in ProviderFormModal - Backend: persist context_length to custom_providers models.<model>.context_length in config.yaml - Add i18n keys (contextLength, contextLengthPlaceholder) to all 8 locales Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: use NInputNumber instead of NInput type=number for context_length NInput does not support type="number" in Naive UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: devilardis <53129661@qq.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -259,6 +259,8 @@ export default {
|
||||
builtIn: 'Integriert',
|
||||
customType: 'Benutzerdefiniert',
|
||||
provider: 'Anbieter',
|
||||
contextLength: 'Kontextlange',
|
||||
contextLengthPlaceholder: 'z.B. 200000 (optional)',
|
||||
local: 'Lokal ({host})',
|
||||
selectProviderRequired: 'Bitte wahlen Sie einen Anbieter',
|
||||
baseUrlRequired: 'Basis-URL ist erforderlich',
|
||||
|
||||
@@ -284,6 +284,8 @@ export default {
|
||||
builtIn: 'Built-in',
|
||||
customType: 'Custom',
|
||||
provider: 'Provider',
|
||||
contextLength: 'Context Length',
|
||||
contextLengthPlaceholder: 'e.g. 200000 (optional)',
|
||||
local: 'Local ({host})',
|
||||
selectProviderRequired: 'Please select a provider',
|
||||
baseUrlRequired: 'Base URL is required',
|
||||
|
||||
@@ -259,6 +259,8 @@ export default {
|
||||
builtIn: 'Integrado',
|
||||
customType: 'Personalizado',
|
||||
provider: 'Proveedor',
|
||||
contextLength: 'Longitud del contexto',
|
||||
contextLengthPlaceholder: 'ej. 200000 (opcional)',
|
||||
local: 'Local ({host})',
|
||||
selectProviderRequired: 'Por favor, selecciona un proveedor',
|
||||
baseUrlRequired: 'La URL base es obligatoria',
|
||||
|
||||
@@ -259,6 +259,8 @@ export default {
|
||||
builtIn: 'Integre',
|
||||
customType: 'Personnalise',
|
||||
provider: 'Fournisseur',
|
||||
contextLength: 'Longueur du contexte',
|
||||
contextLengthPlaceholder: 'ex. 200000 (facultatif)',
|
||||
local: 'Local ({host})',
|
||||
selectProviderRequired: 'Veuillez selectionner un fournisseur',
|
||||
baseUrlRequired: 'L\'URL de base est requise',
|
||||
|
||||
@@ -259,6 +259,8 @@ export default {
|
||||
builtIn: '組み込み',
|
||||
customType: 'カスタム',
|
||||
provider: 'プロバイダー',
|
||||
contextLength: 'コンテキスト長',
|
||||
contextLengthPlaceholder: '例: 200000(任意)',
|
||||
local: 'ローカル ({host})',
|
||||
selectProviderRequired: 'プロバイダーを選択してください',
|
||||
baseUrlRequired: 'ベース URL は必須です',
|
||||
|
||||
@@ -259,6 +259,8 @@ export default {
|
||||
builtIn: '내장',
|
||||
customType: '사용자 지정',
|
||||
provider: 'Provider',
|
||||
contextLength: '컨텍스트 길이',
|
||||
contextLengthPlaceholder: '예: 200000 (선택사항)',
|
||||
local: '로컬 ({host})',
|
||||
selectProviderRequired: 'Provider를 선택해 주세요',
|
||||
baseUrlRequired: 'Base URL을 입력해 주세요',
|
||||
|
||||
@@ -259,6 +259,8 @@ export default {
|
||||
builtIn: 'Integrado',
|
||||
customType: 'Personalizado',
|
||||
provider: 'Provedor',
|
||||
contextLength: 'Tamanho do contexto',
|
||||
contextLengthPlaceholder: 'ex: 200000 (opcional)',
|
||||
local: 'Local ({host})',
|
||||
selectProviderRequired: 'Por favor, selecione um provedor',
|
||||
baseUrlRequired: 'A URL base e obrigatoria',
|
||||
|
||||
@@ -284,6 +284,8 @@ export default {
|
||||
builtIn: '内置',
|
||||
customType: '自定义',
|
||||
provider: 'Provider',
|
||||
contextLength: '上下文长度',
|
||||
contextLengthPlaceholder: '例如 200000(可选)',
|
||||
local: '本地 ({host})',
|
||||
selectProviderRequired: '请选择 Provider',
|
||||
baseUrlRequired: 'Base URL 为必填项',
|
||||
|
||||
Reference in New Issue
Block a user