mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-09 10:55:27 +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),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user