lyc-dev #45

Merged
lyc merged 8 commits from lyc-dev into main 2024-11-20 15:26:02 +08:00
4 changed files with 130 additions and 24 deletions
Showing only changes of commit f168e04405 - Show all commits

View File

@ -1,7 +1,7 @@
import request from '@/utils/request'
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) {
return request({
@ -16,8 +16,8 @@ export function conversation(data) {
url: rootPath + '/v1/api/new_conversation',
method: 'get',
headers: {
'Authorization':'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm',
'Content-Type': 'application/json',
Authorization: 'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm',
'Content-Type': 'application/json'
},
data: data
})
@ -29,10 +29,45 @@ export function completion(data) {
url: rootPath + '/v1/api/completion',
method: 'post',
headers: {
'Authorization':'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm',
Authorization: 'Bearer ragflow-IwNzMxMTIyOGY0ZTExZWZiOGE2MDI0Mm',
'Content-Type': 'application/json',
'Accept': '*/*'
Accept: '*/*'
},
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>
</el-dropdown>
<div>
<el-button type="primary" link @click="wordDialog = true">
<el-button type="primary" link @click="onAdd">
<el-icon>
<Plus />
</el-icon>
@ -31,7 +31,8 @@
</div>
</div>
</div>
<keywordDialog v-model="wordDialog"/>
<!--添加提示词-->
<keywordDialog v-model="wordDialog" :modeType="type" :isAdd="wordDialog" :temp="curTemplate"/>
<Dialog v-model="showDialog" :modeType="type" />
</template>
@ -69,7 +70,7 @@ const curTemplate = reactive({ name: '', id: '' })
const templateList = ref([])
//
const getTemplateList = () => {
modelList({ model: props.type, type: 1 }).then(res => {
modelList({ model: props.type, type: 1, ex3: 1 }).then(res => {
templateList.value = res.rows
Object.assign(curTemplate, res.rows[0]);
emit('changeTemp', res.rows[0].id)
@ -93,6 +94,11 @@ const changeTemplate = (val) => {
})
}
const onAdd = () =>{
wordDialog.value = true
}
onMounted(() => {
getTemplateList()
})

View File

@ -1,28 +1,27 @@
<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>
<div class="custom-header flex">
<span>{{ isAdd ? '添加' : '编辑' }}提示词</span>
<span>{{ isAdd ? temp && temp.ex3 == '1' ? '请输入新的模板名称' : '添加提示词' : '编辑提示词' }}</span>
<i class="iconfont icon-guanbi" @click="mode = false"></i>
</div>
</template>
<div class="dialog-content">
<div class="dialog-content" v-loading="loading">
<el-form :model="form" label-width="auto">
<el-form-item label="名称">
<el-input v-model="form.name" />
</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-form-item>
</el-form>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="mode = false">取消</el-button>
<el-button type="primary" @click="mode = false">
<el-button type="primary" @click="saveAdd">
确定
</el-button>
</div>
@ -31,16 +30,27 @@
</template>
<script setup>
import { reactive, watch } from 'vue'
const mode = defineModel()
import { ref, reactive, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { addKeyWords, addChildTemp, editChildTemp } from '@/api/mode/index'
const mode = defineModel()
const props = defineProps({
modeType: {
type: Number,
default: 1
},
isAdd: {
type: Boolean,
default: true
},
item: {
item: { //
type: Object
},
temp: { //
Object
}
})
@ -51,11 +61,60 @@ const form = reactive({
watch(() => props.isAdd, (newVal) => {
if (!newVal) {
console.log(props.item)
form.name = props.item.name
form.prompt = props.item.prompt
console.log(newVal, 'isEditKeyWord');
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>

View File

@ -17,7 +17,7 @@
</template>
<template #default>
<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>
</el-popover>
</div>
@ -55,18 +55,19 @@
<!--AI 对话调整-->
<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>
</template>
<script setup>
import { ref, reactive, onMounted, watch } from 'vue';
import { ElMessage } from 'element-plus'
import EditDialog from './edit-dialog.vue'
import AdjustDialog from './adjust-dialog.vue'
import keywordDialog from './keyword-dialog.vue';
import { sessionStore } from '@/utils/store'
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()
@ -205,6 +206,11 @@ const editKeyWord = (item) =>{
Object.assign(keywordItem, item)
}
//
const removeItem = async(item) =>{
const { msg } = await removeChildTemp(item.id)
ElMessage.success(msg)
}
onMounted(() => {