mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 07:09:20 +08:00
feat: 贯通 context_window 配置并按 token 预算裁剪对话历史
This commit is contained in:
@@ -26,6 +26,8 @@ export namespace AgentVO {
|
||||
configured: boolean;
|
||||
baseUrl?: string | null;
|
||||
model?: string | null;
|
||||
/** 上下文窗口 token;未配置则由 Agent 按模型名估计 */
|
||||
contextWindow?: number | null;
|
||||
apiKeyMasked?: string | null;
|
||||
/** Server 字段;兼容旧 updatedAt */
|
||||
updateTime?: string;
|
||||
@@ -72,6 +74,8 @@ export async function updateAgentLlmSettingsApi(body: {
|
||||
baseUrl: string;
|
||||
model: string;
|
||||
apiKey?: string;
|
||||
/** 正整数写入;0 表示清空为自动估计 */
|
||||
contextWindow?: number | null;
|
||||
}) {
|
||||
return requestClient.put<AgentVO.LlmSettings>(
|
||||
'/company/agent-llm-settings',
|
||||
|
||||
@@ -82,6 +82,8 @@ const llmForm = ref({
|
||||
apiKey: '',
|
||||
apiKeyMasked: '' as string | null,
|
||||
configured: false,
|
||||
/** 空字符串=自动估计;数字字符串=显式窗口 */
|
||||
contextWindow: '' as string,
|
||||
});
|
||||
const messagePaneRef = ref<HTMLElement | null>(null);
|
||||
let abort: AbortController | null = null;
|
||||
@@ -239,6 +241,10 @@ async function openSettings() {
|
||||
apiKey: '',
|
||||
apiKeyMasked: s.apiKeyMasked || null,
|
||||
configured: !!s.configured,
|
||||
contextWindow:
|
||||
s.contextWindow != null && s.contextWindow > 0
|
||||
? String(s.contextWindow)
|
||||
: '',
|
||||
};
|
||||
memories.value = mem.items || [];
|
||||
} catch (e: any) {
|
||||
@@ -263,14 +269,31 @@ async function saveSettings() {
|
||||
}
|
||||
savingSettings.value = true;
|
||||
try {
|
||||
const cwRaw = llmForm.value.contextWindow.trim();
|
||||
let contextWindow: number | undefined;
|
||||
if (cwRaw === '') {
|
||||
contextWindow = 0; // 清空为自动估计
|
||||
} else {
|
||||
const n = Number(cwRaw);
|
||||
if (!Number.isFinite(n) || n < 0) {
|
||||
message.warning('上下文窗口请填写正整数,或留空自动估计');
|
||||
return;
|
||||
}
|
||||
contextWindow = Math.floor(n);
|
||||
}
|
||||
const s = await updateAgentLlmSettingsApi({
|
||||
baseUrl: llmForm.value.baseUrl.trim(),
|
||||
model: llmForm.value.model.trim(),
|
||||
apiKey: llmForm.value.apiKey.trim() || undefined,
|
||||
contextWindow,
|
||||
});
|
||||
llmForm.value.configured = s.configured;
|
||||
llmForm.value.apiKeyMasked = s.apiKeyMasked || null;
|
||||
llmForm.value.apiKey = '';
|
||||
llmForm.value.contextWindow =
|
||||
s.contextWindow != null && s.contextWindow > 0
|
||||
? String(s.contextWindow)
|
||||
: '';
|
||||
message.success('模型配置已保存');
|
||||
settingsOpen.value = false;
|
||||
} catch (e: any) {
|
||||
@@ -571,6 +594,8 @@ void refreshSessions();
|
||||
<p class="text-muted-foreground mb-3 text-sm">
|
||||
各租户自行填写 Base URL、API Key 与模型名。Key
|
||||
加密落库(MySQL),Agent 经内部接口/Redis 注入;界面仅显示掩码。
|
||||
上下文窗口多数厂商不会在 API 里返回,需按模型文档填写;留空则由
|
||||
Agent 按模型名估计。
|
||||
</p>
|
||||
<Form layout="vertical">
|
||||
<FormItem label="Base URL" required>
|
||||
@@ -582,6 +607,12 @@ void refreshSessions();
|
||||
<FormItem label="Model" required>
|
||||
<Input v-model:value="llmForm.model" placeholder="deepseek-chat" />
|
||||
</FormItem>
|
||||
<FormItem label="上下文窗口(token)">
|
||||
<Input
|
||||
v-model:value="llmForm.contextWindow"
|
||||
placeholder="留空=按模型名自动估计,例如 128000"
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
:label="
|
||||
llmForm.configured
|
||||
@@ -599,7 +630,7 @@ void refreshSessions();
|
||||
<div class="mt-4 border-t border-border pt-3">
|
||||
<div class="mb-2 text-sm font-medium">我的记忆</div>
|
||||
<p class="text-muted-foreground mb-2 text-xs">
|
||||
对话中发送「记住:…」可写入;助手会注入最近条目。
|
||||
对话中发送「记住:…」可写入;助手按需检索,不会默认注入全部记忆。
|
||||
</p>
|
||||
<div v-if="memories.length === 0" class="text-muted-foreground text-xs">
|
||||
暂无记忆
|
||||
|
||||
Reference in New Issue
Block a user