feat: Add database table for model context length configuration (#477)

* feat: add database table for model context length configuration

- Add model_context table with provider/model/context_limit fields
- Implement UPSERT endpoint for model context configuration
- Add priority lookup: database > config.yaml > custom_providers > cache
- Add frontend click-to-edit UI in ChatInput with tooltip
- Add i18n support for context editing dialog (all 8 locales)
- Use context_limit field consistently across frontend and backend

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: use useMessage() composable instead of window.$message in ChatInput

- Remove incorrect NMessage import (not a component)
- Use useMessage() composable from naive-ui
- Replace window.$message?.xxx() with message.xxx()
- Fixes TypeScript build errors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-05-06 15:05:44 +08:00
committed by GitHub
parent f338aeea18
commit 479e1feef6
14 changed files with 406 additions and 3 deletions
@@ -0,0 +1,41 @@
import { request } from '../client'
export interface ModelContext {
id: number
provider: string
model: string
context_limit: number
}
/**
* 根据 provider 和 model 查询模型上下文配置
*/
export async function getModelContext(provider: string, model: string): Promise<ModelContext | null> {
try {
const res = await request<{ data: ModelContext }>(
`/api/hermes/model-context?provider=${encodeURIComponent(provider)}&model=${encodeURIComponent(model)}`
)
return res.data
} catch (err: any) {
if (err.status === 404) return null
throw err
}
}
/**
* 设置模型上下文配置(UPSERT:存在则更新,不存在则插入)
*/
export async function setModelContext(
provider: string,
model: string,
contextLimit: number
): Promise<ModelContext> {
const res = await request<{ success: boolean; data: ModelContext }>(
`/api/hermes/model-context/${encodeURIComponent(provider)}/${encodeURIComponent(model)}`,
{
method: 'PUT',
body: JSON.stringify({ provider, model, context_limit: contextLimit }),
}
)
return res.data
}