refactor(api): drop deprecated tenant ConversationConfig field and KV write path
The Tenant.ConversationConfig field was marked deprecated when
CustomAgent (builtin-quick-answer) replaced the per-tenant defaults
path, but the JSONB column, GET/PUT KV handlers, write helpers and
read fall-throughs all stayed wired. This had two concrete failure
modes:
- Input-field.vue silently PUT-ed per-user model picks back into
/tenants/kv/conversation-config, which requires Admin+ — Viewers
and Contributors got a 403 every time they switched chat models.
- The same write also overwrote the tenant-shared default for every
other user, turning a per-user UX into a per-tenant footgun.
Remove the field, the struct, the validate helper, the PUT case and
the two dead Summary helpers in session/helpers.go. KnowledgeSearch
loses its tenant-conversation fallback (one chunk-tool reader); the
global config + hardcoded defaults still cover it. session_agent_qa
already required agents to declare their own rerank_model_id, so no
behaviour change there.
Frontend follows:
- Input-field.vue: per-user 'last selected chat model' moves to
localStorage, no API call.
- AgentEditorModal: defaults for builtin-quick-answer creation now
come from prompt-templates (system/context/rewrite/fallback) and
retrieval-config (top_k / threshold), the two endpoints that
actually own those settings now.
- AgentSettings.vue: orphan settings page with no router/import
referencing it; deleted.
- api/system: getConversationConfig / updateConversationConfig and
the ConversationConfig interface go away.
Net: 137 insertions, 2761 deletions.
This commit is contained in:
@@ -40,28 +40,6 @@ export interface AgentConfig {
|
|||||||
available_placeholders?: PlaceholderDefinition[] // GET 响应中包含,POST/PUT 不需要
|
available_placeholders?: PlaceholderDefinition[] // GET 响应中包含,POST/PUT 不需要
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConversationConfig {
|
|
||||||
prompt: string
|
|
||||||
context_template: string
|
|
||||||
temperature: number
|
|
||||||
max_completion_tokens: number
|
|
||||||
max_rounds: number
|
|
||||||
embedding_top_k: number
|
|
||||||
keyword_threshold: number
|
|
||||||
vector_threshold: number
|
|
||||||
rerank_top_k: number
|
|
||||||
rerank_threshold: number
|
|
||||||
enable_rewrite: boolean
|
|
||||||
fallback_strategy: string
|
|
||||||
fallback_response: string
|
|
||||||
fallback_prompt?: string
|
|
||||||
summary_model_id?: string
|
|
||||||
rerank_model_id?: string
|
|
||||||
rewrite_prompt_system?: string
|
|
||||||
rewrite_prompt_user?: string
|
|
||||||
enable_query_expansion?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PromptTemplate {
|
export interface PromptTemplate {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
@@ -101,14 +79,6 @@ export function updateAgentConfig(config: AgentConfig): Promise<{ data: AgentCon
|
|||||||
return put('/api/v1/tenants/kv/agent-config', config)
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPromptTemplates(): Promise<{ data: PromptTemplatesConfig }> {
|
export function getPromptTemplates(): Promise<{ data: PromptTemplatesConfig }> {
|
||||||
return get('/api/v1/tenants/kv/prompt-templates')
|
return get('/api/v1/tenants/kv/prompt-templates')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { getCaretCoordinates } from '@/utils/caret';
|
|||||||
import { listModels, type ModelConfig } from '@/api/model';
|
import { listModels, type ModelConfig } from '@/api/model';
|
||||||
import { listAgents, type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent';
|
import { listAgents, type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent';
|
||||||
import { listWebSearchProviders, type WebSearchProviderEntity } from '@/api/web-search-provider';
|
import { listWebSearchProviders, type WebSearchProviderEntity } from '@/api/web-search-provider';
|
||||||
import { getConversationConfig, updateConversationConfig, type ConversationConfig } from '@/api/system';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import AttachmentUpload, { type AttachmentFile } from './AttachmentUpload.vue';
|
import AttachmentUpload, { type AttachmentFile } from './AttachmentUpload.vue';
|
||||||
import {
|
import {
|
||||||
@@ -499,7 +498,6 @@ const selectedModelId = computed({
|
|||||||
get: () => settingsStore.conversationModels.selectedChatModelId || '',
|
get: () => settingsStore.conversationModels.selectedChatModelId || '',
|
||||||
set: (val: string) => settingsStore.updateConversationModels({ selectedChatModelId: val })
|
set: (val: string) => settingsStore.updateConversationModels({ selectedChatModelId: val })
|
||||||
});
|
});
|
||||||
const conversationConfig = ref<ConversationConfig | null>(null);
|
|
||||||
const modelsLoading = ref(false);
|
const modelsLoading = ref(false);
|
||||||
const showModelSelector = ref(false);
|
const showModelSelector = ref(false);
|
||||||
const modelButtonRef = ref<HTMLElement>();
|
const modelButtonRef = ref<HTMLElement>();
|
||||||
@@ -685,26 +683,54 @@ const enabledAgents = computed(() =>
|
|||||||
agents.value.filter(a => !disabledOwnAgentIds.value.includes(a.id))
|
agents.value.filter(a => !disabledOwnAgentIds.value.includes(a.id))
|
||||||
);
|
);
|
||||||
|
|
||||||
const loadConversationConfig = async () => {
|
// LAST_CHAT_MODEL_KEY scopes the per-user "last selected chat model"
|
||||||
|
// to localStorage. The previous implementation wrote this back to the
|
||||||
|
// tenant-level KV /tenants/kv/conversation-config — which (a) required
|
||||||
|
// Admin+ to mutate, so a Viewer/Contributor switching models in the
|
||||||
|
// chat input got a 403, and (b) silently overwrote the tenant default
|
||||||
|
// for everyone else. localStorage is per-user-per-browser, which is
|
||||||
|
// what "remember my last pick" actually wants.
|
||||||
|
const LAST_CHAT_MODEL_KEY = 'weknora_last_chat_model_id'
|
||||||
|
|
||||||
|
const readLastChatModelID = (): string => {
|
||||||
try {
|
try {
|
||||||
const response = await getConversationConfig();
|
return localStorage.getItem(LAST_CHAT_MODEL_KEY) || ''
|
||||||
conversationConfig.value = response.data;
|
} catch {
|
||||||
const modelId = response.data?.summary_model_id || '';
|
return ''
|
||||||
|
|
||||||
// 保留当前已选择的模型(如果有),避免覆盖从其他页面传递的模型选择
|
|
||||||
const currentSelectedModel = settingsStore.conversationModels.selectedChatModelId;
|
|
||||||
settingsStore.updateConversationModels({
|
|
||||||
summaryModelId: modelId,
|
|
||||||
selectedChatModelId: currentSelectedModel || modelId, // 优先保留当前选择
|
|
||||||
rerankModelId: response.data?.rerank_model_id || '',
|
|
||||||
});
|
|
||||||
if (!selectedModelId.value) {
|
|
||||||
selectedModelId.value = modelId;
|
|
||||||
}
|
|
||||||
ensureModelSelection();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to load conversation config:', error);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const writeLastChatModelID = (id: string) => {
|
||||||
|
try {
|
||||||
|
if (id) {
|
||||||
|
localStorage.setItem(LAST_CHAT_MODEL_KEY, id)
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem(LAST_CHAT_MODEL_KEY)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// localStorage may be disabled in incognito mode; ignore.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial chat-model selection priority: per-user last pick
|
||||||
|
// (localStorage) > current store value (e.g. carried over from
|
||||||
|
// settings page) > first available model. The tenant-level
|
||||||
|
// conversation-config used to feed summary_model_id/rerank_model_id
|
||||||
|
// into the dropdown, but those fields were removed: per-user last pick
|
||||||
|
// belongs in localStorage, agent-level model belongs on the agent.
|
||||||
|
const initChatModelSelection = () => {
|
||||||
|
const lastPick = readLastChatModelID();
|
||||||
|
const currentSelectedModel = settingsStore.conversationModels.selectedChatModelId;
|
||||||
|
const initialSelection = lastPick || currentSelectedModel || '';
|
||||||
|
settingsStore.updateConversationModels({
|
||||||
|
summaryModelId: initialSelection,
|
||||||
|
selectedChatModelId: initialSelection,
|
||||||
|
rerankModelId: '',
|
||||||
|
});
|
||||||
|
if (!selectedModelId.value) {
|
||||||
|
selectedModelId.value = initialSelection;
|
||||||
|
}
|
||||||
|
ensureModelSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadChatModels = async () => {
|
const loadChatModels = async () => {
|
||||||
@@ -726,8 +752,9 @@ const ensureModelSelection = () => {
|
|||||||
if (selectedModelId.value) {
|
if (selectedModelId.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (conversationConfig.value?.summary_model_id) {
|
const lastPick = readLastChatModelID();
|
||||||
selectedModelId.value = conversationConfig.value.summary_model_id;
|
if (lastPick) {
|
||||||
|
selectedModelId.value = lastPick;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (availableModels.value.length > 0) {
|
if (availableModels.value.length > 0) {
|
||||||
@@ -746,7 +773,7 @@ const handleGoToConversationModels = () => {
|
|||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleModelChange = async (value: string | number | Array<string | number> | undefined) => {
|
const handleModelChange = (value: string | number | Array<string | number> | undefined) => {
|
||||||
const normalized = Array.isArray(value) ? value[0] : value;
|
const normalized = Array.isArray(value) ? value[0] : value;
|
||||||
const val = normalized !== undefined && normalized !== null ? String(normalized) : '';
|
const val = normalized !== undefined && normalized !== null ? String(normalized) : '';
|
||||||
|
|
||||||
@@ -755,40 +782,25 @@ const handleModelChange = async (value: string | number | Array<string | number>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (val === '__add_model__') {
|
if (val === '__add_model__') {
|
||||||
selectedModelId.value = conversationConfig.value?.summary_model_id || '';
|
selectedModelId.value = readLastChatModelID();
|
||||||
handleGoToConversationModels();
|
handleGoToConversationModels();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存到后端
|
// The chat-level model picker now persists per-user-per-browser via
|
||||||
try {
|
// localStorage instead of writing to the tenant-shared KV. This is what
|
||||||
if (conversationConfig.value) {
|
// "remember my last pick" should always have meant — the previous PUT
|
||||||
const updatedConfig = {
|
// /tenants/kv/conversation-config required Admin+, so a Viewer or
|
||||||
...conversationConfig.value,
|
// Contributor switching models from the chat input got a 403.
|
||||||
summary_model_id: val
|
writeLastChatModelID(val);
|
||||||
};
|
selectedModelId.value = val;
|
||||||
const response = await updateConversationConfig(updatedConfig);
|
showModelSelector.value = false;
|
||||||
|
|
||||||
// 更新本地状态
|
settingsStore.updateConversationModels({
|
||||||
conversationConfig.value = response.data;
|
summaryModelId: val,
|
||||||
selectedModelId.value = val;
|
selectedChatModelId: val,
|
||||||
showModelSelector.value = false;
|
rerankModelId: '',
|
||||||
|
});
|
||||||
// 同步到 store
|
|
||||||
settingsStore.updateConversationModels({
|
|
||||||
summaryModelId: val,
|
|
||||||
selectedChatModelId: val,
|
|
||||||
rerankModelId: conversationConfig.value?.rerank_model_id || '',
|
|
||||||
});
|
|
||||||
|
|
||||||
MessagePlugin.success(t('conversationSettings.toasts.chatModelSaved'));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('保存模型配置失败:', error);
|
|
||||||
MessagePlugin.error(t('conversationSettings.toasts.saveFailed'));
|
|
||||||
// 恢复到之前的值
|
|
||||||
selectedModelId.value = conversationConfig.value?.summary_model_id || '';
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectedModel = computed(() => {
|
const selectedModel = computed(() => {
|
||||||
@@ -1411,7 +1423,7 @@ let scrollHandler: (() => void) | null = null;
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadKnowledgeBases();
|
loadKnowledgeBases();
|
||||||
loadWebSearchConfig();
|
loadWebSearchConfig();
|
||||||
loadConversationConfig();
|
initChatModelSelection();
|
||||||
loadChatModels();
|
loadChatModels();
|
||||||
loadAgents();
|
loadAgents();
|
||||||
window.addEventListener(CHAT_FILE_DROP_EVENT, handleChatFileDrop as EventListener);
|
window.addEventListener(CHAT_FILE_DROP_EVENT, handleChatFileDrop as EventListener);
|
||||||
@@ -1725,8 +1737,9 @@ const handleSelectAgent = (agent: CustomAgent, sourceTenantId?: string) => {
|
|||||||
if (agentModel && agentModel.trim() !== '') {
|
if (agentModel && agentModel.trim() !== '') {
|
||||||
selectedModelId.value = agentModel;
|
selectedModelId.value = agentModel;
|
||||||
} else {
|
} else {
|
||||||
if (conversationConfig.value?.summary_model_id) {
|
const lastPick = readLastChatModelID();
|
||||||
selectedModelId.value = conversationConfig.value.summary_model_id;
|
if (lastPick) {
|
||||||
|
selectedModelId.value = lastPick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1430,7 +1430,8 @@ import { listKnowledgeBases } from '@/api/knowledge-base';
|
|||||||
import { listMCPServices, type MCPService } from '@/api/mcp-service';
|
import { listMCPServices, type MCPService } from '@/api/mcp-service';
|
||||||
import { listSkills, type SkillInfo } from '@/api/skill';
|
import { listSkills, type SkillInfo } from '@/api/skill';
|
||||||
import { listWebSearchProviders, type WebSearchProviderEntity } from '@/api/web-search-provider';
|
import { listWebSearchProviders, type WebSearchProviderEntity } from '@/api/web-search-provider';
|
||||||
import { getAgentConfig, getConversationConfig, getStorageEngineStatus, getPromptTemplates, type StorageEngineStatusItem, type PromptTemplate } from '@/api/system';
|
import { getAgentConfig, getStorageEngineStatus, getPromptTemplates, type StorageEngineStatusItem, type PromptTemplate } from '@/api/system';
|
||||||
|
import { getTenantRetrievalConfig } from '@/api/retrieval';
|
||||||
import { useUIStore } from '@/stores/ui';
|
import { useUIStore } from '@/stores/ui';
|
||||||
import { useAuthStore } from '@/stores/auth';
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import { useOrganizationStore } from '@/stores/organization';
|
import { useOrganizationStore } from '@/stores/organization';
|
||||||
@@ -1497,7 +1498,7 @@ const imageStorageOptions = computed(() => {
|
|||||||
|
|
||||||
// 系统默认配置(用于内置智能体显示默认提示词)
|
// 系统默认配置(用于内置智能体显示默认提示词)
|
||||||
const defaultAgentSystemPrompt = ref(''); // Agent 模式的默认系统提示词(来自 agent-config)
|
const defaultAgentSystemPrompt = ref(''); // Agent 模式的默认系统提示词(来自 agent-config)
|
||||||
const defaultNormalSystemPrompt = ref(''); // 普通模式的默认系统提示词(来自 conversation-config)
|
const defaultNormalSystemPrompt = ref(''); // 普通模式默认系统提示词(来自 prompt-templates 的 default 项)
|
||||||
const defaultContextTemplate = ref('');
|
const defaultContextTemplate = ref('');
|
||||||
const defaultRewritePromptSystem = ref('');
|
const defaultRewritePromptSystem = ref('');
|
||||||
const defaultRewritePromptUser = ref('');
|
const defaultRewritePromptUser = ref('');
|
||||||
@@ -2269,7 +2270,7 @@ watch(() => props.visible, async (val) => {
|
|||||||
newFormData.config.system_prompt = defaultAgentSystemPrompt.value;
|
newFormData.config.system_prompt = defaultAgentSystemPrompt.value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 快速问答模式使用 conversation-config 的默认提示词
|
// 快速问答模式:默认提示词来自 prompt-templates 的 default 项
|
||||||
if (defaultNormalSystemPrompt.value) {
|
if (defaultNormalSystemPrompt.value) {
|
||||||
newFormData.config.system_prompt = defaultNormalSystemPrompt.value;
|
newFormData.config.system_prompt = defaultNormalSystemPrompt.value;
|
||||||
}
|
}
|
||||||
@@ -2367,7 +2368,7 @@ const fillBuiltinAgentDefaults = () => {
|
|||||||
config.system_prompt = defaultAgentSystemPrompt.value;
|
config.system_prompt = defaultAgentSystemPrompt.value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 普通模式:使用 conversation-config 的默认系统提示词和上下文模板
|
// 普通模式:默认系统提示词、上下文模板等来自 prompt-templates 的 default 项
|
||||||
if (!config.system_prompt && defaultNormalSystemPrompt.value) {
|
if (!config.system_prompt && defaultNormalSystemPrompt.value) {
|
||||||
config.system_prompt = defaultNormalSystemPrompt.value;
|
config.system_prompt = defaultNormalSystemPrompt.value;
|
||||||
}
|
}
|
||||||
@@ -2643,15 +2644,33 @@ const loadDependencies = async () => {
|
|||||||
console.warn('Failed to load agent type presets', e);
|
console.warn('Failed to load agent type presets', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载 Agent 系统提示词模板(供 applyAgentTypePreset 根据 system_prompt_id 回填正文)
|
// 加载 prompt-templates 用于:
|
||||||
|
// 1. agent_system_prompt 列表(applyAgentTypePreset 通过 system_prompt_id 回填正文)
|
||||||
|
// 2. 普通模式(builtin-quick-answer)创建时的默认 system_prompt / context_template /
|
||||||
|
// rewrite / fallback —— 取每个分类里 default: true 的那条
|
||||||
try {
|
try {
|
||||||
const tmplRes = await getPromptTemplates();
|
const tmplRes = await getPromptTemplates();
|
||||||
const cfg = tmplRes?.data;
|
const cfg = tmplRes?.data;
|
||||||
if (cfg?.agent_system_prompt && Array.isArray(cfg.agent_system_prompt)) {
|
if (cfg?.agent_system_prompt && Array.isArray(cfg.agent_system_prompt)) {
|
||||||
agentSystemPromptTemplates.value = cfg.agent_system_prompt;
|
agentSystemPromptTemplates.value = cfg.agent_system_prompt;
|
||||||
}
|
}
|
||||||
|
const pickDefault = (arr?: PromptTemplate[]): PromptTemplate | undefined =>
|
||||||
|
Array.isArray(arr) ? arr.find(t => t.default) : undefined;
|
||||||
|
const sysPrompt = pickDefault(cfg?.system_prompt);
|
||||||
|
if (sysPrompt?.content) defaultNormalSystemPrompt.value = sysPrompt.content;
|
||||||
|
const ctxTmpl = pickDefault(cfg?.context_template);
|
||||||
|
if (ctxTmpl?.content) defaultContextTemplate.value = ctxTmpl.content;
|
||||||
|
const rewriteTmpl = pickDefault(cfg?.rewrite);
|
||||||
|
if (rewriteTmpl?.content) defaultRewritePromptSystem.value = rewriteTmpl.content;
|
||||||
|
if (rewriteTmpl?.user) defaultRewritePromptUser.value = rewriteTmpl.user;
|
||||||
|
// fallback templates split into fixed-response (default) and model-mode (mode === 'model').
|
||||||
|
const fallbackList = Array.isArray(cfg?.fallback) ? cfg.fallback : [];
|
||||||
|
const fixedFallback = fallbackList.find(t => t.default && t.mode !== 'model');
|
||||||
|
if (fixedFallback?.content) defaultFallbackResponse.value = fixedFallback.content;
|
||||||
|
const modelFallback = fallbackList.find(t => t.mode === 'model' && t.default) || fallbackList.find(t => t.mode === 'model');
|
||||||
|
if (modelFallback?.content) defaultFallbackPrompt.value = modelFallback.content;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to load prompt templates for agent type presets', e);
|
console.warn('Failed to load prompt templates', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载存储引擎可用状态(用于图片存储 provider 选择)
|
// 加载存储引擎可用状态(用于图片存储 provider 选择)
|
||||||
@@ -2685,52 +2704,28 @@ const loadDependencies = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 加载 Agent 模式默认提示词(来自 agent-config,用于 smart-reasoning 模式)
|
// 加载 Agent 模式默认提示词(来自 agent-config,用于 smart-reasoning 模式)
|
||||||
const agentConfig = await getAgentConfig();
|
try {
|
||||||
if (agentConfig.data?.system_prompt) {
|
const agentConfig = await getAgentConfig();
|
||||||
defaultAgentSystemPrompt.value = agentConfig.data.system_prompt;
|
if (agentConfig.data?.system_prompt) {
|
||||||
|
defaultAgentSystemPrompt.value = agentConfig.data.system_prompt;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Failed to load agent config', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载系统默认配置(来自 conversation-config,用于普通模式 quick-answer)
|
// 加载租户检索默认参数(embedding_top_k / 阈值 / rerank top_k 等)。
|
||||||
const conversationConfig = await getConversationConfig();
|
// temperature 与 max_completion_tokens 不在 RetrievalConfig 中,保持组件内
|
||||||
if (conversationConfig.data?.prompt) {
|
// 硬编码默认值(0.7 / 2048);用户在 agent 表单里可逐项调整。
|
||||||
defaultNormalSystemPrompt.value = conversationConfig.data.prompt;
|
try {
|
||||||
}
|
const retrievalRes: any = await getTenantRetrievalConfig();
|
||||||
if (conversationConfig.data?.context_template) {
|
const rc = retrievalRes?.data;
|
||||||
defaultContextTemplate.value = conversationConfig.data.context_template;
|
if (rc?.embedding_top_k) defaultEmbeddingTopK.value = rc.embedding_top_k;
|
||||||
}
|
if (rc?.keyword_threshold !== undefined) defaultKeywordThreshold.value = rc.keyword_threshold;
|
||||||
if (conversationConfig.data?.rewrite_prompt_system) {
|
if (rc?.vector_threshold !== undefined) defaultVectorThreshold.value = rc.vector_threshold;
|
||||||
defaultRewritePromptSystem.value = conversationConfig.data.rewrite_prompt_system;
|
if (rc?.rerank_top_k) defaultRerankTopK.value = rc.rerank_top_k;
|
||||||
}
|
if (rc?.rerank_threshold !== undefined) defaultRerankThreshold.value = rc.rerank_threshold;
|
||||||
if (conversationConfig.data?.rewrite_prompt_user) {
|
} catch (e) {
|
||||||
defaultRewritePromptUser.value = conversationConfig.data.rewrite_prompt_user;
|
console.warn('Failed to load retrieval config', e);
|
||||||
}
|
|
||||||
if (conversationConfig.data?.fallback_prompt) {
|
|
||||||
defaultFallbackPrompt.value = conversationConfig.data.fallback_prompt;
|
|
||||||
}
|
|
||||||
if (conversationConfig.data?.fallback_response) {
|
|
||||||
defaultFallbackResponse.value = conversationConfig.data.fallback_response;
|
|
||||||
}
|
|
||||||
// 加载默认检索参数
|
|
||||||
if (conversationConfig.data?.embedding_top_k) {
|
|
||||||
defaultEmbeddingTopK.value = conversationConfig.data.embedding_top_k;
|
|
||||||
}
|
|
||||||
if (conversationConfig.data?.keyword_threshold !== undefined) {
|
|
||||||
defaultKeywordThreshold.value = conversationConfig.data.keyword_threshold;
|
|
||||||
}
|
|
||||||
if (conversationConfig.data?.vector_threshold !== undefined) {
|
|
||||||
defaultVectorThreshold.value = conversationConfig.data.vector_threshold;
|
|
||||||
}
|
|
||||||
if (conversationConfig.data?.rerank_top_k) {
|
|
||||||
defaultRerankTopK.value = conversationConfig.data.rerank_top_k;
|
|
||||||
}
|
|
||||||
if (conversationConfig.data?.rerank_threshold !== undefined) {
|
|
||||||
defaultRerankThreshold.value = conversationConfig.data.rerank_threshold;
|
|
||||||
}
|
|
||||||
if (conversationConfig.data?.max_completion_tokens) {
|
|
||||||
defaultMaxCompletionTokens.value = conversationConfig.data.max_completion_tokens;
|
|
||||||
}
|
|
||||||
if (conversationConfig.data?.temperature !== undefined) {
|
|
||||||
defaultTemperature.value = conversationConfig.data.temperature;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to load dependencies', e);
|
console.error('Failed to load dependencies', e);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -226,28 +226,13 @@ func (t *KnowledgeSearchTool) Execute(ctx context.Context, args json.RawMessage)
|
|||||||
|
|
||||||
logger.Infof(ctx, "[Tool][KnowledgeSearch] Queries: %v", queries)
|
logger.Infof(ctx, "[Tool][KnowledgeSearch] Queries: %v", queries)
|
||||||
|
|
||||||
// Get search parameters from tenant conversation config, fallback to global config
|
// Search parameters: fall back to global config, then to hardcoded defaults.
|
||||||
|
// We used to read tenant.ConversationConfig here as the first source of
|
||||||
|
// truth, but that field was removed when the chat pipeline moved to
|
||||||
|
// CustomAgent — tenant-level KV settings now live on the agent itself.
|
||||||
var topK int
|
var topK int
|
||||||
var vectorThreshold, keywordThreshold, minScore float64
|
var vectorThreshold, keywordThreshold, minScore float64
|
||||||
|
|
||||||
// Try to get from tenant conversation config
|
|
||||||
if tenantVal := ctx.Value(types.TenantInfoContextKey); tenantVal != nil {
|
|
||||||
if tenant, ok := tenantVal.(*types.Tenant); ok && tenant != nil && tenant.ConversationConfig != nil {
|
|
||||||
cc := tenant.ConversationConfig
|
|
||||||
if cc.EmbeddingTopK > 0 {
|
|
||||||
topK = cc.EmbeddingTopK
|
|
||||||
}
|
|
||||||
if cc.VectorThreshold > 0 {
|
|
||||||
vectorThreshold = cc.VectorThreshold
|
|
||||||
}
|
|
||||||
if cc.KeywordThreshold > 0 {
|
|
||||||
keywordThreshold = cc.KeywordThreshold
|
|
||||||
}
|
|
||||||
// minScore is not in ConversationConfig, use default or config
|
|
||||||
minScore = 0.3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to global config if not set
|
// Fallback to global config if not set
|
||||||
if topK == 0 && t.config != nil {
|
if topK == 0 && t.config != nil {
|
||||||
topK = t.config.Conversation.EmbeddingTopK
|
topK = t.config.Conversation.EmbeddingTopK
|
||||||
|
|||||||
@@ -100,21 +100,19 @@ func (s *sessionService) AgentQA(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if hasKnowledgeSearchTool {
|
if hasKnowledgeSearchTool {
|
||||||
// Resolve rerank model: agent-level first, then fall back to tenant default
|
// Rerank model is resolved purely from the agent config now.
|
||||||
// (ConversationConfig.RerankModelID). This lets users leave rerank empty when
|
// We used to fall back to ConversationConfig.RerankModelID at
|
||||||
// their KB scope currently has no RAG-type KB, while still working correctly
|
// the tenant level, but that path encouraged "leave rerank
|
||||||
// if a RAG-type KB is added later.
|
// blank on the agent and inherit silently" which made debugging
|
||||||
|
// retrieval quality a guessing game across tenant settings vs
|
||||||
|
// agent settings. Forcing the agent to declare its own rerank
|
||||||
|
// model puts the configuration where the user actually edits
|
||||||
|
// the agent. If a Wiki-only agent doesn't need reranking,
|
||||||
|
// agentRequiresRerankModel() below already lets it pass.
|
||||||
rerankModelID := req.CustomAgent.Config.RerankModelID
|
rerankModelID := req.CustomAgent.Config.RerankModelID
|
||||||
if rerankModelID == "" && tenantInfo != nil && tenantInfo.ConversationConfig != nil {
|
|
||||||
rerankModelID = tenantInfo.ConversationConfig.RerankModelID
|
|
||||||
if rerankModelID != "" {
|
|
||||||
logger.Infof(ctx, "Custom agent %s has no rerank model; falling back to tenant default rerank model %s",
|
|
||||||
req.CustomAgent.ID, rerankModelID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if rerankModelID == "" {
|
if rerankModelID == "" {
|
||||||
logger.Warnf(ctx, "No rerank model configured for custom agent %s (and no tenant default), but knowledge_search tool is enabled", req.CustomAgent.ID)
|
logger.Warnf(ctx, "No rerank model configured for custom agent %s, but knowledge_search tool is enabled", req.CustomAgent.ID)
|
||||||
return errors.New("rerank model is not configured: please set rerank_model_id on the agent or configure a tenant default rerank model")
|
return errors.New("rerank model is not configured: please set rerank_model_id on the agent")
|
||||||
}
|
}
|
||||||
|
|
||||||
rerankModel, err = s.modelService.GetRerankModel(ctx, rerankModelID)
|
rerankModel, err = s.modelService.GetRerankModel(ctx, rerankModelID)
|
||||||
|
|||||||
@@ -261,104 +261,10 @@ func getFloat64(m map[string]interface{}, key string) float64 {
|
|||||||
return 0.0
|
return 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
// createDefaultSummaryConfig creates a default summary configuration from config
|
// createDefaultSummaryConfig and fillSummaryConfigDefaults used to build
|
||||||
// It prioritizes tenant-level ConversationConfig, then falls back to config.yaml defaults
|
// per-session SummaryConfig from tenant-level ConversationConfig + config.yaml
|
||||||
func (h *Handler) createDefaultSummaryConfig(ctx context.Context) *types.SummaryConfig {
|
// defaults. Both helpers became unreachable when the chat pipeline moved to
|
||||||
// Try to get tenant from context
|
// CustomAgent (builtin-quick-answer / smart-reasoning) and the tenant-level
|
||||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
// ConversationConfig field was removed; deleting them avoids the only
|
||||||
|
// remaining references to that defunct path.
|
||||||
|
|
||||||
// Initialize with config.yaml defaults
|
|
||||||
cfg := &types.SummaryConfig{
|
|
||||||
MaxTokens: h.config.Conversation.Summary.MaxTokens,
|
|
||||||
TopP: h.config.Conversation.Summary.TopP,
|
|
||||||
TopK: h.config.Conversation.Summary.TopK,
|
|
||||||
FrequencyPenalty: h.config.Conversation.Summary.FrequencyPenalty,
|
|
||||||
PresencePenalty: h.config.Conversation.Summary.PresencePenalty,
|
|
||||||
RepeatPenalty: h.config.Conversation.Summary.RepeatPenalty,
|
|
||||||
Prompt: h.config.Conversation.Summary.Prompt,
|
|
||||||
ContextTemplate: h.config.Conversation.Summary.ContextTemplate,
|
|
||||||
NoMatchPrefix: h.config.Conversation.Summary.NoMatchPrefix,
|
|
||||||
Temperature: h.config.Conversation.Summary.Temperature,
|
|
||||||
Seed: h.config.Conversation.Summary.Seed,
|
|
||||||
MaxCompletionTokens: h.config.Conversation.Summary.MaxCompletionTokens,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override with tenant-level conversation config if available
|
|
||||||
if tenant != nil && tenant.ConversationConfig != nil {
|
|
||||||
// Use custom prompt if provided
|
|
||||||
if tenant.ConversationConfig.Prompt != "" {
|
|
||||||
cfg.Prompt = tenant.ConversationConfig.Prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use custom context template if provided
|
|
||||||
if tenant.ConversationConfig.ContextTemplate != "" {
|
|
||||||
cfg.ContextTemplate = tenant.ConversationConfig.ContextTemplate
|
|
||||||
}
|
|
||||||
if tenant.ConversationConfig.Temperature >= 0 {
|
|
||||||
cfg.Temperature = tenant.ConversationConfig.Temperature
|
|
||||||
}
|
|
||||||
if tenant.ConversationConfig.MaxCompletionTokens > 0 {
|
|
||||||
cfg.MaxCompletionTokens = tenant.ConversationConfig.MaxCompletionTokens
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
// fillSummaryConfigDefaults fills missing fields in summary config with defaults
|
|
||||||
// It prioritizes tenant-level ConversationConfig, then falls back to config.yaml defaults
|
|
||||||
func (h *Handler) fillSummaryConfigDefaults(ctx context.Context, config *types.SummaryConfig) {
|
|
||||||
// Try to get tenant from context
|
|
||||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
|
||||||
|
|
||||||
// Determine default values: tenant config first, then config.yaml
|
|
||||||
var defaultPrompt, defaultContextTemplate, defaultNoMatchPrefix string
|
|
||||||
var defaultTemperature float64
|
|
||||||
var defaultMaxCompletionTokens int
|
|
||||||
|
|
||||||
if tenant != nil && tenant.ConversationConfig != nil {
|
|
||||||
// Use custom prompt if provided
|
|
||||||
if tenant.ConversationConfig.Prompt != "" {
|
|
||||||
defaultPrompt = tenant.ConversationConfig.Prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use custom context template if provided
|
|
||||||
if tenant.ConversationConfig.ContextTemplate != "" {
|
|
||||||
defaultContextTemplate = tenant.ConversationConfig.ContextTemplate
|
|
||||||
}
|
|
||||||
defaultTemperature = tenant.ConversationConfig.Temperature
|
|
||||||
defaultMaxCompletionTokens = tenant.ConversationConfig.MaxCompletionTokens
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back to config.yaml if tenant config is empty
|
|
||||||
if defaultPrompt == "" {
|
|
||||||
defaultPrompt = h.config.Conversation.Summary.Prompt
|
|
||||||
}
|
|
||||||
if defaultContextTemplate == "" {
|
|
||||||
defaultContextTemplate = h.config.Conversation.Summary.ContextTemplate
|
|
||||||
}
|
|
||||||
if defaultTemperature == 0 {
|
|
||||||
defaultTemperature = h.config.Conversation.Summary.Temperature
|
|
||||||
}
|
|
||||||
if defaultMaxCompletionTokens == 0 {
|
|
||||||
defaultMaxCompletionTokens = h.config.Conversation.Summary.MaxCompletionTokens
|
|
||||||
}
|
|
||||||
defaultNoMatchPrefix = h.config.Conversation.Summary.NoMatchPrefix
|
|
||||||
|
|
||||||
// Fill missing fields
|
|
||||||
if config.Prompt == "" {
|
|
||||||
config.Prompt = defaultPrompt
|
|
||||||
}
|
|
||||||
if config.ContextTemplate == "" {
|
|
||||||
config.ContextTemplate = defaultContextTemplate
|
|
||||||
}
|
|
||||||
if config.Temperature < 0 {
|
|
||||||
config.Temperature = defaultTemperature
|
|
||||||
}
|
|
||||||
if config.MaxCompletionTokens == 0 {
|
|
||||||
config.MaxCompletionTokens = defaultMaxCompletionTokens
|
|
||||||
}
|
|
||||||
if config.NoMatchPrefix == "" {
|
|
||||||
config.NoMatchPrefix = defaultNoMatchPrefix
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-143
@@ -576,7 +576,7 @@ func (h *TenantHandler) updateTenantAgentConfigInternal(c *gin.Context) {
|
|||||||
|
|
||||||
// GetTenantKV godoc
|
// GetTenantKV godoc
|
||||||
// @Summary 获取租户KV配置
|
// @Summary 获取租户KV配置
|
||||||
// @Description 获取租户级别的KV配置(支持agent-config、web-search-config、conversation-config)
|
// @Description 获取租户级别的KV配置(支持agent-config、web-search-config 等)
|
||||||
// @Tags 租户管理
|
// @Tags 租户管理
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
@@ -597,9 +597,6 @@ func (h *TenantHandler) GetTenantKV(c *gin.Context) {
|
|||||||
case "web-search-config":
|
case "web-search-config":
|
||||||
h.GetTenantWebSearchConfig(c)
|
h.GetTenantWebSearchConfig(c)
|
||||||
return
|
return
|
||||||
case "conversation-config":
|
|
||||||
h.GetTenantConversationConfig(c)
|
|
||||||
return
|
|
||||||
case "prompt-templates":
|
case "prompt-templates":
|
||||||
h.GetPromptTemplates(c)
|
h.GetPromptTemplates(c)
|
||||||
return
|
return
|
||||||
@@ -624,7 +621,7 @@ func (h *TenantHandler) GetTenantKV(c *gin.Context) {
|
|||||||
|
|
||||||
// UpdateTenantKV godoc
|
// UpdateTenantKV godoc
|
||||||
// @Summary 更新租户KV配置
|
// @Summary 更新租户KV配置
|
||||||
// @Description 更新租户级别的KV配置(支持agent-config、web-search-config、conversation-config)
|
// @Description 更新租户级别的KV配置(支持agent-config、web-search-config 等)
|
||||||
// @Tags 租户管理
|
// @Tags 租户管理
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
@@ -646,9 +643,6 @@ func (h *TenantHandler) UpdateTenantKV(c *gin.Context) {
|
|||||||
case "web-search-config":
|
case "web-search-config":
|
||||||
h.updateTenantWebSearchConfigInternal(c)
|
h.updateTenantWebSearchConfigInternal(c)
|
||||||
return
|
return
|
||||||
case "conversation-config":
|
|
||||||
h.updateTenantConversationInternal(c)
|
|
||||||
return
|
|
||||||
case "parser-engine-config":
|
case "parser-engine-config":
|
||||||
h.updateTenantParserEngineConfigInternal(c)
|
h.updateTenantParserEngineConfigInternal(c)
|
||||||
return
|
return
|
||||||
@@ -860,141 +854,6 @@ func (h *TenantHandler) updateTenantStorageEngineConfigInternal(c *gin.Context)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TenantHandler) buildDefaultConversationConfig() *types.ConversationConfig {
|
|
||||||
return &types.ConversationConfig{
|
|
||||||
Prompt: h.config.Conversation.Summary.Prompt,
|
|
||||||
ContextTemplate: h.config.Conversation.Summary.ContextTemplate,
|
|
||||||
Temperature: h.config.Conversation.Summary.Temperature,
|
|
||||||
MaxCompletionTokens: h.config.Conversation.Summary.MaxCompletionTokens,
|
|
||||||
MaxRounds: h.config.Conversation.MaxRounds,
|
|
||||||
EmbeddingTopK: h.config.Conversation.EmbeddingTopK,
|
|
||||||
KeywordThreshold: h.config.Conversation.KeywordThreshold,
|
|
||||||
VectorThreshold: h.config.Conversation.VectorThreshold,
|
|
||||||
RerankTopK: h.config.Conversation.RerankTopK,
|
|
||||||
RerankThreshold: h.config.Conversation.RerankThreshold,
|
|
||||||
EnableRewrite: h.config.Conversation.EnableRewrite,
|
|
||||||
EnableQueryExpansion: h.config.Conversation.EnableQueryExpansion,
|
|
||||||
FallbackStrategy: h.config.Conversation.FallbackStrategy,
|
|
||||||
FallbackResponse: h.config.Conversation.FallbackResponse,
|
|
||||||
FallbackPrompt: h.config.Conversation.FallbackPrompt,
|
|
||||||
RewritePromptUser: h.config.Conversation.RewritePromptUser,
|
|
||||||
RewritePromptSystem: h.config.Conversation.RewritePromptSystem,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateConversationConfig(req *types.ConversationConfig) error {
|
|
||||||
if req.MaxRounds <= 0 {
|
|
||||||
return errors.NewBadRequestError("max_rounds must be greater than 0")
|
|
||||||
}
|
|
||||||
if req.EmbeddingTopK <= 0 {
|
|
||||||
return errors.NewBadRequestError("embedding_top_k must be greater than 0")
|
|
||||||
}
|
|
||||||
if req.KeywordThreshold < 0 || req.KeywordThreshold > 1 {
|
|
||||||
return errors.NewBadRequestError("keyword_threshold must be between 0 and 1")
|
|
||||||
}
|
|
||||||
if req.VectorThreshold < 0 || req.VectorThreshold > 1 {
|
|
||||||
return errors.NewBadRequestError("vector_threshold must be between 0 and 1")
|
|
||||||
}
|
|
||||||
if req.RerankTopK <= 0 {
|
|
||||||
return errors.NewBadRequestError("rerank_top_k must be greater than 0")
|
|
||||||
}
|
|
||||||
if req.RerankThreshold < -10 || req.RerankThreshold > 10 {
|
|
||||||
return errors.NewBadRequestError("rerank_threshold must be between -10 and 10")
|
|
||||||
}
|
|
||||||
if req.Temperature < 0 || req.Temperature > 2 {
|
|
||||||
return errors.NewBadRequestError("temperature must be between 0 and 2")
|
|
||||||
}
|
|
||||||
if req.MaxCompletionTokens <= 0 || req.MaxCompletionTokens > 100000 {
|
|
||||||
return errors.NewBadRequestError("max_completion_tokens must be between 1 and 100000")
|
|
||||||
}
|
|
||||||
if req.FallbackStrategy != "" &&
|
|
||||||
req.FallbackStrategy != string(types.FallbackStrategyFixed) &&
|
|
||||||
req.FallbackStrategy != string(types.FallbackStrategyModel) {
|
|
||||||
return errors.NewBadRequestError("fallback_strategy is invalid")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTenantConversationConfig godoc
|
|
||||||
// @Summary 获取租户对话配置
|
|
||||||
// @Description 获取租户的全局对话配置(默认应用于普通模式会话)
|
|
||||||
// @Tags 租户管理
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Success 200 {object} map[string]interface{} "对话配置"
|
|
||||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
|
||||||
// @Security Bearer
|
|
||||||
// @Security ApiKeyAuth
|
|
||||||
// @Router /tenants/kv/conversation-config [get]
|
|
||||||
func (h *TenantHandler) GetTenantConversationConfig(c *gin.Context) {
|
|
||||||
ctx := c.Request.Context()
|
|
||||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
|
||||||
if tenant == nil {
|
|
||||||
logger.Error(ctx, "Tenant is empty")
|
|
||||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// If tenant has no conversation config, return defaults from config.yaml
|
|
||||||
var response *types.ConversationConfig
|
|
||||||
logger.Info(ctx, "Tenant has no conversation config, returning defaults")
|
|
||||||
response = h.buildDefaultConversationConfig()
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"success": true,
|
|
||||||
"data": response,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// updateTenantConversationInternal updates the conversation configuration for a tenant
|
|
||||||
// This sets the global conversation configuration for normal mode sessions in this tenant
|
|
||||||
func (h *TenantHandler) updateTenantConversationInternal(c *gin.Context) {
|
|
||||||
ctx := c.Request.Context()
|
|
||||||
logger.Info(ctx, "Start updating tenant conversation config")
|
|
||||||
|
|
||||||
var req types.ConversationConfig
|
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
|
||||||
logger.Error(ctx, "Failed to parse request parameters", err)
|
|
||||||
c.Error(errors.NewValidationError("Invalid request data").WithDetails(err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate configuration
|
|
||||||
if err := validateConversationConfig(&req); err != nil {
|
|
||||||
c.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get existing tenant
|
|
||||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
|
||||||
if tenant == nil {
|
|
||||||
logger.Error(ctx, "Tenant is empty")
|
|
||||||
c.Error(errors.NewBadRequestError("Tenant is empty"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update conversation configuration
|
|
||||||
tenant.ConversationConfig = &req
|
|
||||||
|
|
||||||
updatedTenant, err := h.service.UpdateTenant(ctx, tenant)
|
|
||||||
if err != nil {
|
|
||||||
if appErr, ok := errors.IsAppError(err); ok {
|
|
||||||
logger.Error(ctx, "Failed to update tenant: application error", appErr)
|
|
||||||
c.Error(appErr)
|
|
||||||
} else {
|
|
||||||
logger.ErrorWithFields(ctx, err, nil)
|
|
||||||
c.Error(errors.NewInternalServerError("Failed to update tenant conversation config").WithDetails(err.Error()))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Infof(ctx, "Tenant conversation config updated successfully, Tenant ID: %d", tenant.ID)
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"success": true,
|
|
||||||
"data": updatedTenant.ConversationConfig,
|
|
||||||
"message": "Conversation configuration updated successfully",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPromptTemplates godoc
|
// GetPromptTemplates godoc
|
||||||
// @Summary 获取提示词模板
|
// @Summary 获取提示词模板
|
||||||
// @Description 获取系统配置的提示词模板列表
|
// @Description 获取系统配置的提示词模板列表
|
||||||
|
|||||||
@@ -105,9 +105,6 @@ type Tenant struct {
|
|||||||
ContextConfig *ContextConfig `yaml:"context_config" json:"context_config" gorm:"type:jsonb"`
|
ContextConfig *ContextConfig `yaml:"context_config" json:"context_config" gorm:"type:jsonb"`
|
||||||
// Global WebSearch configuration for this tenant
|
// Global WebSearch configuration for this tenant
|
||||||
WebSearchConfig *WebSearchConfig `yaml:"web_search_config" json:"web_search_config" gorm:"type:jsonb"`
|
WebSearchConfig *WebSearchConfig `yaml:"web_search_config" json:"web_search_config" gorm:"type:jsonb"`
|
||||||
// Deprecated: ConversationConfig is deprecated, use CustomAgent (builtin-quick-answer) config instead.
|
|
||||||
// This field is kept for backward compatibility and will be removed in future versions.
|
|
||||||
ConversationConfig *ConversationConfig `yaml:"conversation_config" json:"conversation_config" gorm:"type:jsonb"`
|
|
||||||
// Parser engine config overrides (MinerU endpoint, API key, etc.). Used when parsing documents; overrides env.
|
// Parser engine config overrides (MinerU endpoint, API key, etc.). Used when parsing documents; overrides env.
|
||||||
ParserEngineConfig *ParserEngineConfig `yaml:"parser_engine_config" json:"parser_engine_config" gorm:"type:jsonb"`
|
ParserEngineConfig *ParserEngineConfig `yaml:"parser_engine_config" json:"parser_engine_config" gorm:"type:jsonb"`
|
||||||
// Credentials config: third-party provider credentials (e.g. WeKnoraCloud AppID/AppSecret)
|
// Credentials config: third-party provider credentials (e.g. WeKnoraCloud AppID/AppSecret)
|
||||||
@@ -203,61 +200,6 @@ func (c *RetrieverEngines) Scan(value interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConversationConfig represents the conversation configuration for normal mode
|
|
||||||
type ConversationConfig struct {
|
|
||||||
// Prompt is the system prompt for normal mode
|
|
||||||
Prompt string `json:"prompt"`
|
|
||||||
// ContextTemplate is the prompt template for summarizing retrieval results
|
|
||||||
ContextTemplate string `json:"context_template"`
|
|
||||||
// Temperature controls the randomness of the model output
|
|
||||||
Temperature float64 `json:"temperature"`
|
|
||||||
// MaxTokens is the maximum number of tokens to generate
|
|
||||||
MaxCompletionTokens int `json:"max_completion_tokens"`
|
|
||||||
|
|
||||||
// Retrieval & strategy parameters
|
|
||||||
MaxRounds int `json:"max_rounds"`
|
|
||||||
EmbeddingTopK int `json:"embedding_top_k"`
|
|
||||||
KeywordThreshold float64 `json:"keyword_threshold"`
|
|
||||||
VectorThreshold float64 `json:"vector_threshold"`
|
|
||||||
RerankTopK int `json:"rerank_top_k"`
|
|
||||||
RerankThreshold float64 `json:"rerank_threshold"`
|
|
||||||
EnableRewrite bool `json:"enable_rewrite"`
|
|
||||||
EnableQueryExpansion bool `json:"enable_query_expansion"`
|
|
||||||
|
|
||||||
// Model configuration
|
|
||||||
SummaryModelID string `json:"summary_model_id"`
|
|
||||||
RerankModelID string `json:"rerank_model_id"`
|
|
||||||
|
|
||||||
// Fallback strategy
|
|
||||||
FallbackStrategy string `json:"fallback_strategy"`
|
|
||||||
FallbackResponse string `json:"fallback_response"`
|
|
||||||
FallbackPrompt string `json:"fallback_prompt"`
|
|
||||||
|
|
||||||
// Rewrite prompts
|
|
||||||
RewritePromptSystem string `json:"rewrite_prompt_system"`
|
|
||||||
RewritePromptUser string `json:"rewrite_prompt_user"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value implements the driver.Valuer interface, used to convert ConversationConfig to database value
|
|
||||||
func (c *ConversationConfig) Value() (driver.Value, error) {
|
|
||||||
if c == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return json.Marshal(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan implements the sql.Scanner interface, used to convert database value to ConversationConfig
|
|
||||||
func (c *ConversationConfig) Scan(value interface{}) error {
|
|
||||||
if value == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
b, ok := value.([]byte)
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return json.Unmarshal(b, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CredentialsConfig holds third-party provider credentials at the tenant level.
|
// CredentialsConfig holds third-party provider credentials at the tenant level.
|
||||||
// Stored as a single JSONB column; each provider is a nested object so new
|
// Stored as a single JSONB column; each provider is a nested object so new
|
||||||
// providers can be added without schema changes.
|
// providers can be added without schema changes.
|
||||||
|
|||||||
Reference in New Issue
Block a user