feat: Introduce conversation configuration management and localization updates

- Added new ConversationConfig interface and API endpoints for retrieving and updating conversation settings.
- Enhanced AgentSettings.vue to include UI for configuring conversation parameters such as prompt, context template, temperature, and max tokens.
- Updated localization files in English and Chinese to include new strings for conversation settings.
- Implemented logic to load and save conversation configuration for tenants, ensuring defaults are applied when no specific configuration exists.
This commit is contained in:
wizardchen
2025-11-17 15:33:43 +08:00
parent a886106917
commit 1f5e445eaa
14 changed files with 913 additions and 175 deletions
+15
View File
@@ -38,6 +38,13 @@ export interface AgentConfig {
available_placeholders?: PlaceholderDefinition[] // GET 响应中包含,POST/PUT 不需要
}
export interface ConversationConfig {
prompt: string
context_template: string
temperature: number
max_tokens: number
}
export function getSystemInfo(): Promise<{ data: SystemInfo }> {
return get('/api/v1/system/info')
}
@@ -49,3 +56,11 @@ export function getAgentConfig(): Promise<{ data: AgentConfig }> {
export function updateAgentConfig(config: AgentConfig): Promise<{ data: AgentConfig }> {
return put('/api/v1/tenants/kv/agent-config', config)
}
export function getConversationConfig(): Promise<{ data: ConversationConfig }> {
return get('/api/v1/tenants/kv/conversation-config')
}
export function updateConversationConfig(config: ConversationConfig): Promise<{ data: ConversationConfig }> {
return put('/api/v1/tenants/kv/conversation-config', config)
}
+30
View File
@@ -132,6 +132,7 @@ export default {
title: 'Settings',
modelConfig: 'Model Settings',
agentConfig: 'Agent Settings',
conversationConfig: 'Conversation Settings',
webSearchConfig: 'Web Search',
mcpService: 'MCP Service',
systemSettings: 'System Settings',
@@ -1333,6 +1334,35 @@ export default {
autoDisabled: 'Agent configuration incomplete. Agent mode has been disabled automatically'
}
},
conversationSettings: {
description: 'Configure default behavior and parameters for conversation modes, including Prompt settings for Agent mode and normal mode',
agentMode: 'Agent Mode',
normalMode: 'Normal Mode',
contextTemplate: {
label: 'Retrieval Result Summary Prompt',
desc: 'Prompt template for generating answers based on retrieval results in normal mode',
placeholder: 'Enter the prompt template for retrieval result summary...'
},
systemPrompt: {
label: 'System Prompt',
desc: 'System-level prompt for normal mode conversations',
placeholder: 'Enter the system prompt...'
},
temperature: {
label: 'Temperature',
desc: 'Controls randomness in outputs. 0 is most deterministic; 1 is most random'
},
maxTokens: {
label: 'Max Tokens',
desc: 'Maximum number of tokens to generate in the response'
},
toasts: {
contextTemplateSaved: 'Retrieval result summary prompt saved',
systemPromptSaved: 'System prompt saved',
temperatureSaved: 'Temperature saved',
maxTokensSaved: 'Max tokens saved'
}
},
// New: MCP Settings
mcpSettings: {
title: 'MCP Services',
+30
View File
@@ -223,6 +223,7 @@ export default {
title: "设置",
modelConfig: "模型配置",
agentConfig: "Agent配置",
conversationConfig: "对话设置",
webSearchConfig: "网络搜索",
mcpService: "MCP服务",
systemSettings: "系统设置",
@@ -1337,6 +1338,35 @@ export default {
autoDisabled: "Agent 配置不完整,已自动关闭 Agent 模式",
},
},
conversationSettings: {
description: "配置对话模式的默认行为和参数,包括Agent模式和普通模式的Prompt设置",
agentMode: "Agent模式",
normalMode: "普通模式",
contextTemplate: {
label: "总结Prompt",
desc: "用于普通模式下基于检索结果生成回答的Prompt模板",
placeholder: "请输入检索结果总结的Prompt模板...",
},
systemPrompt: {
label: "系统Prompt",
desc: "用于普通模式对话的系统级Prompt",
placeholder: "请输入系统Prompt...",
},
temperature: {
label: "温度参数",
desc: "控制模型输出的随机性,0最确定,1最随机",
},
maxTokens: {
label: "最大Token数",
desc: "生成回答的最大Token数量",
},
toasts: {
contextTemplateSaved: "总结Prompt已保存",
systemPromptSaved: "系统Prompt已保存",
temperatureSaved: "温度参数已保存",
maxTokensSaved: "最大Token数已保存",
},
},
// 新增:MCP 设置
mcpSettings: {
title: "MCP 服务管理",
+305 -91
View File
@@ -1,11 +1,16 @@
<template>
<div class="agent-settings">
<div class="section-header">
<h2>{{ $t('agentSettings.title') }}</h2>
<p class="section-description">{{ $t('agentSettings.description') }}</p>
<!-- Agent 状态显示 -->
<div class="agent-status-row">
<h2>{{ $t('settings.conversationConfig') }}</h2>
<p class="section-description">{{ $t('conversationSettings.description') }}</p>
</div>
<t-tabs v-model="activeTab" class="conversation-tabs">
<!-- Agent 模式设置 Tab -->
<t-tab-panel value="agent" :label="$t('conversationSettings.agentMode')">
<div class="tab-content">
<!-- Agent 状态显示 -->
<div class="agent-status-row">
<div class="status-label">
<label>{{ $t('agentSettings.status.label') }}</label>
</div>
@@ -34,9 +39,8 @@
</p>
</div>
</div>
</div>
<div class="settings-group">
<div class="settings-group">
<!-- 最大迭代次数 -->
<div class="setting-row">
@@ -270,7 +274,91 @@
</teleport>
</div>
</div>
</div>
</div>
</div>
</t-tab-panel>
<!-- 普通模式设置 Tab -->
<t-tab-panel value="normal" :label="$t('conversationSettings.normalMode')">
<div class="tab-content">
<div class="settings-group">
<!-- System Prompt -->
<div class="setting-row vertical">
<div class="setting-info">
<label>{{ $t('conversationSettings.systemPrompt.label') }}</label>
<p class="desc">{{ $t('conversationSettings.systemPrompt.desc') }}</p>
</div>
<div class="setting-control full-width">
<t-textarea
v-model="localSystemPromptNormal"
:autosize="{ minRows: 10, maxRows: 20 }"
:placeholder="$t('conversationSettings.systemPrompt.placeholder')"
@blur="handleSystemPromptNormalChange"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
</div>
</div>
<!-- Context Template -->
<div class="setting-row vertical">
<div class="setting-info">
<label>{{ $t('conversationSettings.contextTemplate.label') }}</label>
<p class="desc">{{ $t('conversationSettings.contextTemplate.desc') }}</p>
</div>
<div class="setting-control full-width">
<t-textarea
v-model="localContextTemplate"
:autosize="{ minRows: 15, maxRows: 30 }"
:placeholder="$t('conversationSettings.contextTemplate.placeholder')"
@blur="handleContextTemplateChange"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
</div>
</div>
<!-- Temperature -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('conversationSettings.temperature.label') }}</label>
<p class="desc">{{ $t('conversationSettings.temperature.desc') }}</p>
</div>
<div class="setting-control">
<div class="slider-with-value">
<t-slider
v-model="localTemperatureNormal"
:min="0"
:max="1"
:step="0.1"
:marks="{ 0: '0', 0.5: '0.5', 1: '1' }"
@change="handleTemperatureNormalChange"
style="width: 200px;"
/>
<span class="value-display">{{ localTemperatureNormal.toFixed(1) }}</span>
</div>
</div>
</div>
<!-- Max Tokens -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('conversationSettings.maxTokens.label') }}</label>
<p class="desc">{{ $t('conversationSettings.maxTokens.desc') }}</p>
</div>
<div class="setting-control">
<t-input-number
v-model="localMaxTokens"
:min="1"
:max="100000"
:step="100"
@change="handleMaxTokensChange"
style="width: 200px;"
/>
</div>
</div>
</div>
</div>
</t-tab-panel>
</t-tabs>
</div>
</template>
@@ -281,13 +369,16 @@ import { useSettingsStore } from '@/stores/settings'
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
import { listModels, type ModelConfig } from '@/api/model'
import { getAgentConfig, updateAgentConfig, type AgentConfig, type ToolDefinition, type PlaceholderDefinition } from '@/api/system'
import { getAgentConfig, updateAgentConfig, getConversationConfig, updateConversationConfig, type AgentConfig, type ConversationConfig, type ToolDefinition, type PlaceholderDefinition } from '@/api/system'
const settingsStore = useSettingsStore()
const router = useRouter()
const { t } = useI18n()
// 本地状态
// Tab 状态
const activeTab = ref('agent')
// Agent 模式本地状态
const localMaxIterations = ref(5)
const localTemperature = ref(0.7)
const localThinkingModelId = ref('')
@@ -296,6 +387,17 @@ const localAllowedTools = ref<string[]>([])
const localSystemPrompt = ref('')
const localUseCustomSystemPrompt = ref(false)
// 普通模式本地状态
const localContextTemplate = ref('')
const localSystemPromptNormal = ref('')
const localTemperatureNormal = ref(0.3)
const localMaxTokens = ref(2048)
const conversationConfigLoaded = ref(false)
let savedContextTemplate = ''
let savedSystemPromptNormal = ''
let savedTemperatureNormal = 0.3
let savedMaxTokens = 2048
// 计算 Agent 是否就绪
const isAgentReady = computed(() => {
// 必须有思考模型、Rerank 模型 且 至少选择一个工具
@@ -496,6 +598,29 @@ onMounted(async () => {
rerankModelId: config.rerank_model_id,
allowedTools: config.allowed_tools || []
})
// 加载普通模式配置
if (!conversationConfigLoaded.value) {
try {
const convRes = await getConversationConfig()
const convConfig = convRes.data
localContextTemplate.value = convConfig.context_template || ''
savedContextTemplate = convConfig.context_template || ''
localSystemPromptNormal.value = convConfig.prompt || ''
savedSystemPromptNormal = convConfig.prompt || ''
localTemperatureNormal.value = convConfig.temperature || 0.3
savedTemperatureNormal = convConfig.temperature || 0.3
localMaxTokens.value = convConfig.max_tokens || 2048
savedMaxTokens = convConfig.max_tokens || 2048
conversationConfigLoaded.value = true
} catch (error) {
console.error('加载普通模式配置失败:', error)
// 使用默认值
conversationConfigLoaded.value = true
}
}
// 等待下一个 tick,确保所有响应式更新完成
await nextTick()
@@ -1145,6 +1270,95 @@ watch(isAgentReady, (newValue, oldValue) => {
// 注意:配置从"未就绪"变为"就绪"时,不自动启用(让用户自己决定是否启用)
}
})
// 普通模式配置处理函数
const handleContextTemplateChange = async () => {
if (!conversationConfigLoaded.value) return
if (localContextTemplate.value === savedContextTemplate) {
return
}
try {
const config: ConversationConfig = {
prompt: localSystemPromptNormal.value,
context_template: localContextTemplate.value,
temperature: localTemperatureNormal.value,
max_tokens: localMaxTokens.value
}
await updateConversationConfig(config)
savedContextTemplate = localContextTemplate.value
MessagePlugin.success(t('conversationSettings.toasts.contextTemplateSaved'))
} catch (error) {
console.error('保存Context Template失败:', error)
MessagePlugin.error(getErrorMessage(error))
}
}
const handleSystemPromptNormalChange = async () => {
if (!conversationConfigLoaded.value) return
if (localSystemPromptNormal.value === savedSystemPromptNormal) {
return
}
try {
const config: ConversationConfig = {
prompt: localSystemPromptNormal.value,
context_template: localContextTemplate.value,
temperature: localTemperatureNormal.value,
max_tokens: localMaxTokens.value
}
await updateConversationConfig(config)
savedSystemPromptNormal = localSystemPromptNormal.value
MessagePlugin.success(t('conversationSettings.toasts.systemPromptSaved'))
} catch (error) {
console.error('保存System Prompt失败:', error)
MessagePlugin.error(getErrorMessage(error))
}
}
const handleTemperatureNormalChange = async (value: number) => {
if (!conversationConfigLoaded.value) return
try {
const config: ConversationConfig = {
prompt: localSystemPromptNormal.value,
context_template: localContextTemplate.value,
temperature: value,
max_tokens: localMaxTokens.value
}
await updateConversationConfig(config)
savedTemperatureNormal = value
MessagePlugin.success(t('conversationSettings.toasts.temperatureSaved'))
} catch (error) {
console.error('保存Temperature失败:', error)
MessagePlugin.error(getErrorMessage(error))
}
}
const handleMaxTokensChange = async (value: number) => {
if (!conversationConfigLoaded.value) return
try {
const config: ConversationConfig = {
prompt: localSystemPromptNormal.value,
context_template: localContextTemplate.value,
temperature: localTemperatureNormal.value,
max_tokens: value
}
await updateConversationConfig(config)
savedMaxTokens = value
MessagePlugin.success(t('conversationSettings.toasts.maxTokensSaved'))
} catch (error) {
console.error('保存Max Tokens失败:', error)
MessagePlugin.error(getErrorMessage(error))
}
}
</script>
<style lang="less" scoped>
@@ -1152,8 +1366,8 @@ watch(isAgentReady, (newValue, oldValue) => {
width: 100%;
}
.section-header {
margin-bottom: 32px;
h2 {
font-size: 20px;
@@ -1168,97 +1382,97 @@ watch(isAgentReady, (newValue, oldValue) => {
margin: 0 0 20px 0;
line-height: 1.5;
}
}
.agent-status-row {
.agent-status-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 20px 0;
border-bottom: 1px solid #e5e7eb;
margin-top: 8px;
.status-label {
flex: 1;
max-width: 65%;
padding-right: 24px;
label {
font-size: 15px;
font-weight: 500;
color: #333333;
display: block;
margin-bottom: 4px;
}
}
.status-control {
flex-shrink: 0;
min-width: 280px;
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 20px 0;
border-bottom: 1px solid #e5e7eb;
margin-top: 8px;
flex-direction: column;
align-items: flex-end;
gap: 8px;
.status-label {
flex: 1;
max-width: 65%;
padding-right: 24px;
.status-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 12px;
border-radius: 4px;
font-size: 14px;
font-weight: 500;
label {
font-size: 15px;
font-weight: 500;
color: #333333;
display: block;
margin-bottom: 4px;
&.ready {
background: #f0fdf4;
color: #16a34a;
.status-icon {
color: #16a34a;
font-size: 16px;
}
}
&:not(.ready) {
background: #fff7ed;
color: #ea580c;
.status-icon {
color: #ea580c;
font-size: 16px;
}
}
.status-text {
line-height: 1.4;
}
}
.status-control {
flex-shrink: 0;
min-width: 280px;
.status-hint {
font-size: 13px;
color: #666666;
text-align: right;
line-height: 1.5;
max-width: 280px;
}
.status-tip {
margin: 8px 0 0 0;
font-size: 12px;
color: #999999;
text-align: right;
line-height: 1.5;
max-width: 280px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
align-items: flex-start;
gap: 4px;
justify-content: flex-end;
.status-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 12px;
border-radius: 4px;
.tip-icon {
font-size: 14px;
font-weight: 500;
&.ready {
background: #f0fdf4;
color: #16a34a;
.status-icon {
color: #16a34a;
font-size: 16px;
}
}
&:not(.ready) {
background: #fff7ed;
color: #ea580c;
.status-icon {
color: #ea580c;
font-size: 16px;
}
}
.status-text {
line-height: 1.4;
}
}
.status-hint {
font-size: 13px;
color: #666666;
text-align: right;
line-height: 1.5;
max-width: 280px;
}
.status-tip {
margin: 8px 0 0 0;
font-size: 12px;
color: #999999;
text-align: right;
line-height: 1.5;
max-width: 280px;
display: flex;
align-items: flex-start;
gap: 4px;
justify-content: flex-end;
.tip-icon {
font-size: 14px;
color: #999999;
flex-shrink: 0;
margin-top: 2px;
}
flex-shrink: 0;
margin-top: 2px;
}
}
}
+1 -1
View File
@@ -165,7 +165,7 @@ const navItems = computed(() => [
]
},
{ key: 'ollama', icon: 'server', label: 'Ollama' },
{ key: 'agent', icon: 'chat', label: t('settings.agentConfig') },
{ key: 'agent', icon: 'chat', label: t('settings.conversationConfig') },
{ key: 'websearch', icon: 'search', label: t('settings.webSearchConfig') },
{ key: 'mcp', icon: 'tools', label: t('settings.mcpService') },
{ key: 'system', icon: 'info-circle', label: t('settings.systemSettings') },