This commit is contained in:
lyc 2024-11-16 23:37:11 +08:00
parent 135cc4802f
commit f168e04405
4 changed files with 130 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import request from '@/utils/request' import request from '@/utils/request'
import axios from 'axios' import axios from 'axios'
let rootPath = import.meta.env.VITE_APP_ENV === 'production' ? "https://ai.ysaix.com:7864" : ''; let rootPath = import.meta.env.VITE_APP_ENV === 'production' ? 'https://ai.ysaix.com:7864' : ''
// 查询模板列表 // 查询模板列表
export function modelList(params) { export function modelList(params) {
return request({ return request({
@ -16,8 +16,8 @@ export function conversation(data) {
url: rootPath + '/v1/api/new_conversation', url: rootPath + '/v1/api/new_conversation',
method: 'get', method: 'get',
headers: { headers: {
'Authorization':'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm', Authorization: 'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm',
'Content-Type': 'application/json', 'Content-Type': 'application/json'
}, },
data: data data: data
}) })
@ -29,10 +29,45 @@ export function completion(data) {
url: rootPath + '/v1/api/completion', url: rootPath + '/v1/api/completion',
method: 'post', method: 'post',
headers: { headers: {
'Authorization':'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm', Authorization: 'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': '*/*' Accept: '*/*'
}, },
data: data data: data
}) })
} }
// 添加提示词 (系统预设)
export function addKeyWords(data) {
return request({
url: '/education/llmModel/copy',
method: 'post',
data
})
}
// 添加子模板
export function addChildTemp(data) {
return request({
url: '/education/llmModel',
method: 'post',
data
})
}
// 编辑子模板
export function editChildTemp(data) {
return request({
url: '/education/llmModel',
method: 'put',
data
})
}
// 删除子模板
export function removeChildTemp(id) {
return request({
url: '/education/llmModel/' + id,
method: 'delete'
})
}

View File

@ -20,7 +20,7 @@
</template> </template>
</el-dropdown> </el-dropdown>
<div> <div>
<el-button type="primary" link @click="wordDialog = true"> <el-button type="primary" link @click="onAdd">
<el-icon> <el-icon>
<Plus /> <Plus />
</el-icon> </el-icon>
@ -31,7 +31,8 @@
</div> </div>
</div> </div>
</div> </div>
<keywordDialog v-model="wordDialog"/> <!--添加提示词-->
<keywordDialog v-model="wordDialog" :modeType="type" :isAdd="wordDialog" :temp="curTemplate"/>
<Dialog v-model="showDialog" :modeType="type" /> <Dialog v-model="showDialog" :modeType="type" />
</template> </template>
@ -69,7 +70,7 @@ const curTemplate = reactive({ name: '', id: '' })
const templateList = ref([]) const templateList = ref([])
// //
const getTemplateList = () => { const getTemplateList = () => {
modelList({ model: props.type, type: 1 }).then(res => { modelList({ model: props.type, type: 1, ex3: 1 }).then(res => {
templateList.value = res.rows templateList.value = res.rows
Object.assign(curTemplate, res.rows[0]); Object.assign(curTemplate, res.rows[0]);
emit('changeTemp', res.rows[0].id) emit('changeTemp', res.rows[0].id)
@ -93,6 +94,11 @@ const changeTemplate = (val) => {
}) })
} }
const onAdd = () =>{
wordDialog.value = true
}
onMounted(() => { onMounted(() => {
getTemplateList() getTemplateList()
}) })

View File

@ -1,28 +1,27 @@
<template> <template>
<el-dialog v-model="mode" :show-close="false" width="600"> <el-dialog v-model="mode" :show-close="false" width="600" destroy-on-close>
<template #header> <template #header>
<div class="custom-header flex"> <div class="custom-header flex">
<span>{{ isAdd ? '添加' : '编辑' }}提示词</span> <span>{{ isAdd ? temp && temp.ex3 == '1' ? '请输入新的模板名称' : '添加提示词' : '编辑提示词' }}</span>
<i class="iconfont icon-guanbi" @click="mode = false"></i> <i class="iconfont icon-guanbi" @click="mode = false"></i>
</div> </div>
</template> </template>
<div class="dialog-content"> <div class="dialog-content" v-loading="loading">
<el-form :model="form" label-width="auto"> <el-form :model="form" label-width="auto">
<el-form-item label="名称"> <el-form-item label="名称">
<el-input v-model="form.name" /> <el-input v-model="form.name" />
</el-form-item> </el-form-item>
<el-form-item label="提示词"> <el-form-item label="提示词" v-if="isAdd ? !(temp && temp.ex3 == '1') : true">
<el-input v-model="form.prompt" type="textarea" /> <el-input v-model="form.prompt" type="textarea" />
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button @click="mode = false">取消</el-button> <el-button @click="mode = false">取消</el-button>
<el-button type="primary" @click="mode = false"> <el-button type="primary" @click="saveAdd">
确定 确定
</el-button> </el-button>
</div> </div>
@ -31,16 +30,27 @@
</template> </template>
<script setup> <script setup>
import { reactive, watch } from 'vue' import { ref, reactive, watch } from 'vue'
const mode = defineModel() import { ElMessage } from 'element-plus'
import { addKeyWords, addChildTemp, editChildTemp } from '@/api/mode/index'
const mode = defineModel()
const props = defineProps({ const props = defineProps({
modeType: {
type: Number,
default: 1
},
isAdd: { isAdd: {
type: Boolean, type: Boolean,
default: true default: true
}, },
item: { item: { //
type: Object type: Object
},
temp: { //
Object
} }
}) })
@ -51,11 +61,60 @@ const form = reactive({
watch(() => props.isAdd, (newVal) => { watch(() => props.isAdd, (newVal) => {
if (!newVal) { if (!newVal) {
console.log(props.item) console.log(newVal, 'isEditKeyWord');
form.name = props.item.name
form.prompt = props.item.prompt form.name = props.item?.name
form.prompt = props.item?.prompt
} }
}, { immediate: true })
}, { immediate: false })
const loading = ref(false)
const saveAdd = async () => {
loading.value = true
if (props.isAdd) {
try {
var msg = null
//
if (props.temp.ex3 == '1') {
var { msg } = await addKeyWords({ name: form.name, id: props.temp.id })
}
else {
//
let obj = {
name: form.name,
type: 2, // 2
sortNum: 1,
parentId: props.temp.id,
lmType: 1,
model: props.modeType,
prompt: form.prompt,
ex1: props.temp.ex1, //
ex2: props.temp.ex2, //
ex3: '', //
}
var { msg } = await addChildTemp(obj)
}
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
} else {
//
try {
let data = JSON.parse(JSON.stringify(props.item))
data.name = form.name;
data.prompt = form.prompt
const { msg } = await editChildTemp(data)
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
}
}
</script> </script>

View File

@ -17,7 +17,7 @@
</template> </template>
<template #default> <template #default>
<el-button type="primary" link @click="editKeyWord(item)">编辑</el-button> <el-button type="primary" link @click="editKeyWord(item)">编辑</el-button>
<el-button type="primary" link>移除</el-button> <el-button type="primary" link @click="removeItem(item)">移除</el-button>
</template> </template>
</el-popover> </el-popover>
</div> </div>
@ -55,18 +55,19 @@
<!--AI 对话调整--> <!--AI 对话调整-->
<AdjustDialog v-model="isAdjust" :item="editItem" @saveAdjust="saveAdjust" /> <AdjustDialog v-model="isAdjust" :item="editItem" @saveAdjust="saveAdjust" />
<!--编辑提示词--> <!--编辑提示词-->
<keywordDialog v-model="isEditKeyWord" :isAdd="false" :item="keywordItem"/> <keywordDialog v-model="isEditKeyWord" :isAdd="isAdd" :item="keywordItem"/>
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted, watch } from 'vue'; import { ref, reactive, onMounted, watch } from 'vue';
import { ElMessage } from 'element-plus'
import EditDialog from './edit-dialog.vue' import EditDialog from './edit-dialog.vue'
import AdjustDialog from './adjust-dialog.vue' import AdjustDialog from './adjust-dialog.vue'
import keywordDialog from './keyword-dialog.vue'; import keywordDialog from './keyword-dialog.vue';
import { sessionStore } from '@/utils/store' import { sessionStore } from '@/utils/store'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import { conversation, completion, modelList } from '@/api/mode/index' import { conversation, completion, modelList, removeChildTemp } from '@/api/mode/index'
const userStore = useUserStore() const userStore = useUserStore()
@ -205,6 +206,11 @@ const editKeyWord = (item) =>{
Object.assign(keywordItem, item) Object.assign(keywordItem, item)
} }
//
const removeItem = async(item) =>{
const { msg } = await removeChildTemp(item.id)
ElMessage.success(msg)
}
onMounted(() => { onMounted(() => {