mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-08 10:25:28 +08:00
feat: implement history split functionality to optimize context usage and add corresponding UI settings
This commit is contained in:
48
webui/src/features/settings/HistorySplitSection.jsx
Normal file
48
webui/src/features/settings/HistorySplitSection.jsx
Normal file
@@ -0,0 +1,48 @@
|
||||
export default function HistorySplitSection({ t, form, setForm }) {
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl p-5 space-y-4">
|
||||
<div className="space-y-1">
|
||||
<h3 className="font-semibold">{t('settings.historySplitTitle')}</h3>
|
||||
<p className="text-sm text-muted-foreground">{t('settings.historySplitDesc')}</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<label className="flex items-start gap-3 rounded-lg border border-border bg-background/60 p-4">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(form.history_split?.enabled ?? true)}
|
||||
onChange={(e) => setForm((prev) => ({
|
||||
...prev,
|
||||
history_split: {
|
||||
...prev.history_split,
|
||||
enabled: e.target.checked,
|
||||
},
|
||||
}))}
|
||||
className="mt-1 h-4 w-4 rounded border-border"
|
||||
/>
|
||||
<div className="space-y-1">
|
||||
<span className="text-sm font-medium block">{t('settings.historySplitEnabled')}</span>
|
||||
<span className="text-xs text-muted-foreground block">{t('settings.historySplitEnabledDesc')}</span>
|
||||
</div>
|
||||
</label>
|
||||
<label className="text-sm space-y-2">
|
||||
<span className="text-muted-foreground">{t('settings.historySplitTriggerAfterTurns')}</span>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={1000}
|
||||
value={form.history_split.trigger_after_turns}
|
||||
onChange={(e) => setForm((prev) => ({
|
||||
...prev,
|
||||
history_split: {
|
||||
...prev.history_split,
|
||||
trigger_after_turns: Number(e.target.value || 1),
|
||||
},
|
||||
}))}
|
||||
className="w-full bg-background border border-border rounded-lg px-3 py-2"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">{t('settings.historySplitTriggerHelp')}</p>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { useSettingsForm } from './useSettingsForm'
|
||||
import SecuritySection from './SecuritySection'
|
||||
import RuntimeSection from './RuntimeSection'
|
||||
import BehaviorSection from './BehaviorSection'
|
||||
import HistorySplitSection from './HistorySplitSection'
|
||||
import CompatibilitySection from './CompatibilitySection'
|
||||
import AutoDeleteSection from './AutoDeleteSection'
|
||||
import ModelSection from './ModelSection'
|
||||
@@ -95,6 +96,8 @@ export default function SettingsContainer({ onRefresh, onMessage, authFetch, onF
|
||||
|
||||
<BehaviorSection t={t} form={form} setForm={setForm} />
|
||||
|
||||
<HistorySplitSection t={t} form={form} setForm={setForm} />
|
||||
|
||||
<CompatibilitySection t={t} form={form} setForm={setForm} />
|
||||
|
||||
<AutoDeleteSection t={t} form={form} setForm={setForm} />
|
||||
|
||||
@@ -17,6 +17,7 @@ const DEFAULT_FORM = {
|
||||
responses: { store_ttl_seconds: 900 },
|
||||
embeddings: { provider: '' },
|
||||
auto_delete: { mode: 'none' },
|
||||
history_split: { enabled: true, trigger_after_turns: 1 },
|
||||
claude_mapping_text: '{\n "fast": "deepseek-chat",\n "slow": "deepseek-reasoner"\n}',
|
||||
model_aliases_text: '{}',
|
||||
}
|
||||
@@ -70,6 +71,10 @@ function fromServerForm(data) {
|
||||
auto_delete: {
|
||||
mode: normalizeAutoDeleteMode(data.auto_delete),
|
||||
},
|
||||
history_split: {
|
||||
enabled: data.history_split?.enabled ?? true,
|
||||
trigger_after_turns: Number(data.history_split?.trigger_after_turns || 1),
|
||||
},
|
||||
claude_mapping_text: JSON.stringify(data.claude_mapping || {}, null, 2),
|
||||
model_aliases_text: JSON.stringify(data.model_aliases || {}, null, 2),
|
||||
}
|
||||
@@ -90,6 +95,10 @@ function toServerPayload(form) {
|
||||
responses: { store_ttl_seconds: Number(form.responses.store_ttl_seconds) },
|
||||
embeddings: { provider: String(form.embeddings.provider || '').trim() },
|
||||
auto_delete: { mode: normalizeAutoDeleteMode(form.auto_delete) },
|
||||
history_split: {
|
||||
enabled: Boolean(form.history_split?.enabled ?? true),
|
||||
trigger_after_turns: Number(form.history_split?.trigger_after_turns || 1),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -379,6 +379,12 @@
|
||||
"behaviorTitle": "Behavior",
|
||||
"responsesTTL": "Responses store TTL (seconds)",
|
||||
"embeddingsProvider": "Embeddings provider",
|
||||
"historySplitTitle": "History Split",
|
||||
"historySplitDesc": "Pack earlier turns into an attached HISTORY.txt so the model reads the file first and then continues from the latest user request.",
|
||||
"historySplitEnabled": "Enable history split",
|
||||
"historySplitEnabledDesc": "Enabled by default. Turning this off falls back to normal full-context requests.",
|
||||
"historySplitTriggerAfterTurns": "Trigger threshold (user turns)",
|
||||
"historySplitTriggerHelp": "Default is 1, which means history split starts from the second turn.",
|
||||
"compatibilityTitle": "Compatibility",
|
||||
"compatibilityDesc": "Compatibility controls that keep stream output closer to the wire format or safer for the web UI.",
|
||||
"stripReferenceMarkers": "Strip [reference:N] markers",
|
||||
|
||||
@@ -379,6 +379,12 @@
|
||||
"behaviorTitle": "行为设置",
|
||||
"responsesTTL": "Responses 缓存 TTL(秒)",
|
||||
"embeddingsProvider": "Embeddings Provider",
|
||||
"historySplitTitle": "历史拆分",
|
||||
"historySplitDesc": "将更早的对话整理成 HISTORY.txt 上传,让模型优先读取历史文件,再结合最新一轮继续回答。",
|
||||
"historySplitEnabled": "启用历史拆分",
|
||||
"historySplitEnabledDesc": "默认开启。关闭后会恢复为普通的完整上下文提交。",
|
||||
"historySplitTriggerAfterTurns": "触发阈值(用户回合数)",
|
||||
"historySplitTriggerHelp": "默认值为 1,表示从第二轮开始拆分历史。",
|
||||
"compatibilityTitle": "兼容性设置",
|
||||
"compatibilityDesc": "用于控制输出格式兼容性,避免把模型原始流里的标记直接暴露到前端。",
|
||||
"stripReferenceMarkers": "移除 [reference:N] 标记",
|
||||
|
||||
Reference in New Issue
Block a user