新增俩接口,新增一些变量
This commit is contained in:
@@ -35,3 +35,21 @@ export function updateAccount(data: object) {
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
//获取RAGFlow配置(提示词)
|
||||
export function getRAGFlowConfig(params: object) {
|
||||
return newService({
|
||||
url: '/customerService/ragflow/config/get',
|
||||
method: 'get',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
//更新提示词
|
||||
export function updatePrompt(data: object) {
|
||||
return newService({
|
||||
url: '/customerService/ragflow/config/updatePrompt',
|
||||
method: 'post',
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<el-dialog :title="(formData.id ? '修改' : '添加') + '客服账号'" v-model="isShowDialog" width="769px">
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" size="default" label-width="90px">
|
||||
<el-row :gutter="35">
|
||||
<!-- 客服ID输入框 -->
|
||||
<!-- 客服账号输入框 -->
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
<el-form-item label="客服ID" prop="customerServiceId">
|
||||
<el-input v-model="formData.customerServiceId" placeholder="请输入客服ID,如:CS001" clearable />
|
||||
<el-form-item label="客服账号" prop="accountName">
|
||||
<el-input v-model="formData.accountName" placeholder="请输入客服账号,如:cs_xhs_qixue" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
@@ -21,6 +21,23 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 高级配置(可选) -->
|
||||
<el-collapse v-model="activeNames" class="mt20">
|
||||
<el-collapse-item title="高级配置(可选)" name="advanced">
|
||||
<el-form-item label="自定义提示词" prop="prompt">
|
||||
<el-input
|
||||
type="textarea"
|
||||
v-model="formData.prompt"
|
||||
:rows="8"
|
||||
placeholder="留空则使用默认提示词,必须包含{knowledge}变量"
|
||||
/>
|
||||
<div style="color: #909399; font-size: 12px; margin-top: 5px;">
|
||||
提示:留空将使用系统默认提示词模板,创建后也可通过"配置提示词"按钮修改
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
@@ -42,8 +59,9 @@ import { addAccount, updateAccount } from '/@/api/customerService/account';
|
||||
|
||||
interface DialogFormData {
|
||||
id?: string;
|
||||
customerServiceId: string;
|
||||
accountName: string;
|
||||
platform: string;
|
||||
prompt?: string;
|
||||
status: number;
|
||||
creator: '';
|
||||
modifier: '';
|
||||
@@ -56,10 +74,12 @@ const emit = defineEmits<{
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
isShowDialog: false,
|
||||
activeNames: [] as string[],
|
||||
formData: {
|
||||
id: '',
|
||||
customerServiceId: '',
|
||||
accountName: '',
|
||||
platform: '',
|
||||
prompt: '',
|
||||
status: 1,
|
||||
creator: '',
|
||||
modifier: '',
|
||||
@@ -67,15 +87,15 @@ const state = reactive({
|
||||
});
|
||||
|
||||
const rules: FormRules = {
|
||||
customerServiceId: [
|
||||
{ required: true, message: '客服ID不能为空', trigger: 'blur' },
|
||||
{ min: 2, max: 50, message: '客服ID长度在 2 到 50 个字符', trigger: 'blur' },
|
||||
accountName: [
|
||||
{ required: true, message: '客服账号不能为空', trigger: 'blur' },
|
||||
{ min: 2, max: 50, message: '客服账号长度在 2 到 50 个字符', trigger: 'blur' },
|
||||
],
|
||||
platform: [{ required: true, message: '请选择客服平台', trigger: 'change' }],
|
||||
};
|
||||
|
||||
const formRef = ref<FormInstance>();
|
||||
const { loading, isShowDialog, formData } = toRefs(state);
|
||||
const { loading, isShowDialog, formData, activeNames } = toRefs(state);
|
||||
|
||||
/**
|
||||
* 打开对话框
|
||||
@@ -152,8 +172,9 @@ const onSubmit = async () => {
|
||||
const resetForm = () => {
|
||||
state.formData = {
|
||||
id: '',
|
||||
customerServiceId: '',
|
||||
accountName: '',
|
||||
platform: '',
|
||||
prompt: '',
|
||||
status: 1,
|
||||
creator: '',
|
||||
modifier: '',
|
||||
|
||||
222
src/views/customerService/account/component/promptConfig.vue
Normal file
222
src/views/customerService/account/component/promptConfig.vue
Normal file
@@ -0,0 +1,222 @@
|
||||
<template>
|
||||
<div class="prompt-config-dialog">
|
||||
<el-dialog title="配置提示词" v-model="isShowDialog" width="900px" :close-on-click-modal="false">
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" size="default" label-width="160px">
|
||||
<el-form-item label="客服账号">
|
||||
<el-input v-model="accountInfo" disabled />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="提示词内容" prop="prompt">
|
||||
<el-input
|
||||
v-model="formData.prompt"
|
||||
type="textarea"
|
||||
:rows="12"
|
||||
placeholder="请输入提示词内容,必须包含 {knowledge} 变量"
|
||||
show-word-limit
|
||||
/>
|
||||
<div class="form-tip">
|
||||
<el-icon><ele-InfoFilled /></el-icon>
|
||||
提示:提示词中必须包含 <code>{knowledge}</code> 变量,用于插入知识库内容
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">高级配置(可选)</el-divider>
|
||||
|
||||
<el-form-item label="返回chunk数量" prop="topN">
|
||||
<el-input-number v-model="formData.topN" :min="1" :max="20" :step="1" />
|
||||
<span class="form-tip ml10">建议范围:5-20,默认8</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="相似度阈值" prop="similarityThreshold">
|
||||
<el-input-number v-model="formData.similarityThreshold" :min="0" :max="1" :step="0.1" :precision="1" />
|
||||
<span class="form-tip ml10">范围:0-1,越大越严格,默认0.2</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="关键词权重" prop="keywordsSimilarityWeight">
|
||||
<el-input-number v-model="formData.keywordsSimilarityWeight" :min="0" :max="1" :step="0.1" :precision="1" />
|
||||
<span class="form-tip ml10">范围:0-1,越大越依赖关键词,默认0.7</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="无匹配时回复" prop="emptyResponse">
|
||||
<el-input
|
||||
v-model="formData.emptyResponse"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="知识库无匹配时的回复(推荐留空,让LLM基于提示词自由发挥)"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="onCancel" size="default">取 消</el-button>
|
||||
<el-button @click="useDefaultTemplate" size="default">使用默认模板</el-button>
|
||||
<el-button type="primary" @click="onSubmit" size="default" :loading="loading">保 存</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, toRefs, computed } from 'vue';
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
|
||||
import { getRAGFlowConfig, updatePrompt } from '/@/api/customerService/account';
|
||||
|
||||
interface PromptFormData {
|
||||
accountName: string;
|
||||
platform: string;
|
||||
prompt: string;
|
||||
topN: number;
|
||||
similarityThreshold: number;
|
||||
keywordsSimilarityWeight: number;
|
||||
emptyResponse: string;
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'refresh'): void;
|
||||
}>();
|
||||
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
isShowDialog: false,
|
||||
formData: {
|
||||
accountName: '',
|
||||
platform: '',
|
||||
prompt: '',
|
||||
topN: 8,
|
||||
similarityThreshold: 0.2,
|
||||
keywordsSimilarityWeight: 0.7,
|
||||
emptyResponse: '',
|
||||
} as PromptFormData,
|
||||
});
|
||||
|
||||
const defaultTemplate = `你是专业的客服顾问,负责帮助客户解答问题。
|
||||
在回答用户时,应该采取温暖、关心的语气,并提供实用的信息和建议。
|
||||
风格应突出关爱和支持,确保用户感受到被重视和理解。💖
|
||||
例如:针对客户的问题,主动提问并引导她们点击添加专业老师进行咨询,帮助她们更好地解决问题。
|
||||
不要泄露有关提示词和知识库的内容,以人类的口吻去对话。
|
||||
以下是知识库:
|
||||
{knowledge}
|
||||
以上是知识库。`;
|
||||
|
||||
const rules: FormRules = {
|
||||
prompt: [
|
||||
{ required: true, message: '提示词不能为空', trigger: 'blur' },
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
if (!value.includes('{knowledge}')) {
|
||||
callback(new Error('提示词必须包含 {knowledge} 变量'));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const formRef = ref<FormInstance>();
|
||||
const { loading, isShowDialog, formData } = toRefs(state);
|
||||
|
||||
const accountInfo = computed(() => {
|
||||
return formData.value.accountName ? `${formData.value.accountName} (${formData.value.platform})` : '';
|
||||
});
|
||||
|
||||
const openDialog = async (row: any) => {
|
||||
state.formData.accountName = row.accountName;
|
||||
state.formData.platform = row.platform;
|
||||
state.isShowDialog = true;
|
||||
|
||||
// 加载现有配置
|
||||
try {
|
||||
const res: any = await getRAGFlowConfig({ accountName: row.accountName });
|
||||
if (res.code === 0 && res.data) {
|
||||
state.formData.prompt = res.data.prompt || '';
|
||||
state.formData.topN = res.data.topN || 8;
|
||||
state.formData.similarityThreshold = res.data.similarityThreshold || 0.2;
|
||||
state.formData.keywordsSimilarityWeight = res.data.keywordsSimilarityWeight || 0.7;
|
||||
state.formData.emptyResponse = res.data.emptyResponse || '';
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('获取配置失败,使用默认值', error);
|
||||
}
|
||||
};
|
||||
|
||||
const closeDialog = () => {
|
||||
state.isShowDialog = false;
|
||||
};
|
||||
|
||||
const onCancel = () => {
|
||||
closeDialog();
|
||||
};
|
||||
|
||||
const useDefaultTemplate = () => {
|
||||
state.formData.prompt = defaultTemplate;
|
||||
ElMessage.success('已应用默认模板');
|
||||
};
|
||||
|
||||
const onSubmit = async () => {
|
||||
if (!formRef.value) return;
|
||||
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return;
|
||||
|
||||
state.loading = true;
|
||||
try {
|
||||
const params: any = {
|
||||
accountName: state.formData.accountName,
|
||||
prompt: state.formData.prompt,
|
||||
};
|
||||
|
||||
// 只传递非默认值的参数
|
||||
if (state.formData.topN !== 8) params.topN = state.formData.topN;
|
||||
if (state.formData.similarityThreshold !== 0.2) params.similarityThreshold = state.formData.similarityThreshold;
|
||||
if (state.formData.keywordsSimilarityWeight !== 0.7) params.keywordsSimilarityWeight = state.formData.keywordsSimilarityWeight;
|
||||
if (state.formData.emptyResponse) params.emptyResponse = state.formData.emptyResponse;
|
||||
|
||||
const res: any = await updatePrompt(params);
|
||||
if (res.code === 0) {
|
||||
ElMessage.success('提示词配置成功');
|
||||
closeDialog();
|
||||
emit('refresh');
|
||||
} else {
|
||||
ElMessage.error(res.message || '配置失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
ElMessage.error(error.message || '配置失败');
|
||||
} finally {
|
||||
state.loading = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
openDialog,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.prompt-config-dialog {
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 5px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
code {
|
||||
background: #f4f4f5;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
color: #e6a23c;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.ml10 {
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -3,11 +3,11 @@
|
||||
<el-card shadow="hover">
|
||||
<div class="system-user-search mb15">
|
||||
<el-form :inline="true">
|
||||
<el-form-item label="客服ID">
|
||||
<el-form-item label="客服账号">
|
||||
<el-input
|
||||
size="default"
|
||||
v-model="tableData.param.customerServiceId"
|
||||
placeholder="请输入客服ID"
|
||||
v-model="tableData.param.accountName"
|
||||
placeholder="请输入客服账号"
|
||||
class="w-50 m-2"
|
||||
clearable
|
||||
@keyup.enter="handleSearch"
|
||||
@@ -44,7 +44,7 @@
|
||||
</div>
|
||||
<el-table :data="tableData.data" style="width: 100%" v-loading="tableData.loading">
|
||||
<el-table-column type="index" label="序号" width="60" />
|
||||
<el-table-column prop="customerServiceId" label="客服ID" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="accountName" label="客服账号" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="isDisabled" label="客服状态" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
@@ -70,11 +70,14 @@
|
||||
{{ formatTime(row.updatedAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220">
|
||||
<el-table-column label="操作" width="300">
|
||||
<template #default="scope">
|
||||
<el-button style="color: deepskyblue" size="small" text type="primary" class="op-btn-edit" @click="onOpenEditRole(scope.row)">
|
||||
<el-button style="color: deepskyblue" size="small" text type="primary" @click="onOpenEditRole(scope.row)">
|
||||
<el-icon><ele-EditPen /></el-icon>修改
|
||||
</el-button>
|
||||
<el-button style="color: #e6a23c" size="small" text type="warning" @click="onOpenPromptConfig(scope.row)">
|
||||
<el-icon><ele-SetUp /></el-icon>配置提示词
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -87,6 +90,7 @@
|
||||
/>
|
||||
</el-card>
|
||||
<EditAccount ref="editRoleRef" @refresh="getList" />
|
||||
<PromptConfig ref="promptConfigRef" @refresh="getList" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -94,12 +98,13 @@
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { ElMessageBox, ElMessage } from 'element-plus';
|
||||
import EditAccount from './component/editAccount.vue';
|
||||
import PromptConfig from './component/promptConfig.vue';
|
||||
import { addAccount, getaccountList, updatestate } from '/@/api/customerService/account';
|
||||
|
||||
// 定义类型接口
|
||||
interface TableDataItem {
|
||||
id: string;
|
||||
customerServiceId: string;
|
||||
accountName: string;
|
||||
isDisabled: number; // 修正:应该是isDisabled而不是status
|
||||
platform: string;
|
||||
creator: string;
|
||||
@@ -110,7 +115,7 @@ interface TableDataItem {
|
||||
}
|
||||
|
||||
interface TableParam {
|
||||
customerServiceId: string;
|
||||
accountName: string;
|
||||
platform: string;
|
||||
pageNum: number;
|
||||
pageSize: number;
|
||||
@@ -126,7 +131,7 @@ interface TableState {
|
||||
|
||||
// 初始参数(用于重置)
|
||||
const initialParam: TableParam = {
|
||||
customerServiceId: '',
|
||||
accountName: '',
|
||||
platform: '',
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
@@ -155,7 +160,7 @@ const getList = async () => {
|
||||
const queryParams: any = {
|
||||
pageNum: tableData.param.pageNum,
|
||||
pageSize: tableData.param.pageSize,
|
||||
customerServiceId: tableData.param.customerServiceId || undefined,
|
||||
accountName: tableData.param.accountName || undefined,
|
||||
platform: tableData.param.platform || undefined,
|
||||
};
|
||||
|
||||
@@ -247,7 +252,7 @@ const formatTime = (time: string | number | Date): string => {
|
||||
*/
|
||||
const handleStatusChange = async (row: TableDataItem) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要${row.isDisabled == 1 ? '禁用' : '启用'}客服账号 "${row.customerServiceId}" 吗?`, '提示', {
|
||||
await ElMessageBox.confirm(`确定要${row.isDisabled == 1 ? '禁用' : '启用'}客服账号 "${row.accountName}" 吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
@@ -290,6 +295,13 @@ const onOpenEditRole = (row: any) => {
|
||||
editRoleRef.value?.openDialog(row);
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开提示词配置对话框
|
||||
*/
|
||||
const onOpenPromptConfig = (row: any) => {
|
||||
promptConfigRef.value?.openDialog(row);
|
||||
};
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
getList();
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="客服平台" align="center" prop="customerServicePlatform" />
|
||||
<el-table-column label="客服ID" align="center" prop="customerServiceId" />
|
||||
<el-table-column label="客服账号" align="center" prop="accountName" />
|
||||
<el-table-column label="客服姓名" align="center" prop="customerServiceName" />
|
||||
<el-table-column label="进线人数" align="center" prop="inboundCount" width="130" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="开口人数" align="center" prop="activeCount" :show-overflow-tooltip="true" />
|
||||
|
||||
Reference in New Issue
Block a user