refactor: 按用户保存提示词缓存
This commit is contained in:
parent
0d263a311c
commit
7aee911430
@ -10,6 +10,7 @@ import useApplicationStore from './modules/application'
|
|||||||
import useDocumentStore from './modules/document'
|
import useDocumentStore from './modules/document'
|
||||||
import useProblemStore from './modules/problem'
|
import useProblemStore from './modules/problem'
|
||||||
import useLogStore from './modules/log'
|
import useLogStore from './modules/log'
|
||||||
|
import usePromptStore from './modules/prompt'
|
||||||
|
|
||||||
const useStore = () => ({
|
const useStore = () => ({
|
||||||
common: useCommonStore(),
|
common: useCommonStore(),
|
||||||
@ -20,7 +21,8 @@ const useStore = () => ({
|
|||||||
application: useApplicationStore(),
|
application: useApplicationStore(),
|
||||||
document: useDocumentStore(),
|
document: useDocumentStore(),
|
||||||
problem: useProblemStore(),
|
problem: useProblemStore(),
|
||||||
log: useLogStore()
|
log: useLogStore(),
|
||||||
|
prompt: usePromptStore(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export default useStore
|
export default useStore
|
||||||
|
|||||||
40
ui/src/stores/modules/prompt.ts
Normal file
40
ui/src/stores/modules/prompt.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
export interface promptTypes {
|
||||||
|
user: string
|
||||||
|
formValue: { model_id: string, prompt: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
const usePromptStore = defineStore({
|
||||||
|
id: 'prompt',
|
||||||
|
state: (): promptTypes[] => (JSON.parse(localStorage.getItem('PROMPT_CACHE') || '[]')),
|
||||||
|
actions: {
|
||||||
|
save(user: string, formValue: any) {
|
||||||
|
this.$state.forEach((item: any, index: number) => {
|
||||||
|
if (item.user === user) {
|
||||||
|
this.$state.splice(index, 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.$state.push({ user, formValue })
|
||||||
|
localStorage.setItem('PROMPT_CACHE', JSON.stringify(this.$state))
|
||||||
|
},
|
||||||
|
get(user: string) {
|
||||||
|
for (let i = 0; i < this.$state.length; i++) {
|
||||||
|
if (this.$state[i].user === user) {
|
||||||
|
return this.$state[i].formValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
model_id: '',
|
||||||
|
prompt: '内容:{data}\n' +
|
||||||
|
'\n' +
|
||||||
|
'请总结上面的内容,并根据内容总结生成 5 个问题。\n' +
|
||||||
|
'回答要求:\n' +
|
||||||
|
'- 请只输出问题;\n' +
|
||||||
|
'- 请将每个问题放置<question></question>标签中。'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default usePromptStore
|
||||||
@ -134,7 +134,7 @@ const {
|
|||||||
params: { id } // id为datasetID
|
params: { id } // id为datasetID
|
||||||
} = route as any
|
} = route as any
|
||||||
|
|
||||||
const { model } = useStore()
|
const { model, prompt, user } = useStore()
|
||||||
|
|
||||||
|
|
||||||
const emit = defineEmits(['refresh'])
|
const emit = defineEmits(['refresh'])
|
||||||
@ -147,15 +147,9 @@ const providerOptions = ref<Array<Provider>>([])
|
|||||||
const documentIdList = ref<string[]>([])
|
const documentIdList = ref<string[]>([])
|
||||||
|
|
||||||
const FormRef = ref()
|
const FormRef = ref()
|
||||||
const form = ref({
|
const userId = user.userInfo?.id as string
|
||||||
model_id: '',
|
const form = ref(prompt.get(userId))
|
||||||
prompt: '内容:{data}\n' +
|
|
||||||
'\n' +
|
|
||||||
'请总结上面的内容,并根据内容总结生成 5 个问题。\n' +
|
|
||||||
'回答要求:\n' +
|
|
||||||
'- 请只输出问题;\n' +
|
|
||||||
'- 请将每个问题放置<question></question>标签中。'
|
|
||||||
})
|
|
||||||
|
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
model_id: [{ required: true, message: '请选择AI 模型', trigger: 'blur' }],
|
model_id: [{ required: true, message: '请选择AI 模型', trigger: 'blur' }],
|
||||||
@ -176,6 +170,8 @@ const submitHandle = async (formEl: FormInstance) => {
|
|||||||
}
|
}
|
||||||
await formEl.validate((valid, fields) => {
|
await formEl.validate((valid, fields) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
// 保存提示词
|
||||||
|
prompt.save(user.userInfo?.id as string, form.value)
|
||||||
const data = { ...form.value, document_id_list: documentIdList.value }
|
const data = { ...form.value, document_id_list: documentIdList.value }
|
||||||
documentApi.batchGenerateRelated(id, data).then(() => {
|
documentApi.batchGenerateRelated(id, data).then(() => {
|
||||||
MsgSuccess('生成关联问题成功')
|
MsgSuccess('生成关联问题成功')
|
||||||
|
|||||||
@ -117,7 +117,7 @@
|
|||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref, watch } from 'vue'
|
import { reactive, ref } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import paragraphApi from '@/api/paragraph'
|
import paragraphApi from '@/api/paragraph'
|
||||||
|
|
||||||
@ -127,7 +127,6 @@ import type { Provider } from '@/api/type/model'
|
|||||||
import datasetApi from '@/api/dataset'
|
import datasetApi from '@/api/dataset'
|
||||||
import { groupBy } from 'lodash'
|
import { groupBy } from 'lodash'
|
||||||
import { MsgSuccess } from '@/utils/message'
|
import { MsgSuccess } from '@/utils/message'
|
||||||
import { t } from '@/locales'
|
|
||||||
import type { FormInstance } from 'element-plus'
|
import type { FormInstance } from 'element-plus'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -135,8 +134,7 @@ const {
|
|||||||
params: { id, documentId } // id为datasetID
|
params: { id, documentId } // id为datasetID
|
||||||
} = route as any
|
} = route as any
|
||||||
|
|
||||||
const { model } = useStore()
|
const { model, prompt, user } = useStore()
|
||||||
|
|
||||||
|
|
||||||
const emit = defineEmits(['refresh'])
|
const emit = defineEmits(['refresh'])
|
||||||
|
|
||||||
@ -148,15 +146,10 @@ const providerOptions = ref<Array<Provider>>([])
|
|||||||
const paragraphIdList = ref<string[]>([])
|
const paragraphIdList = ref<string[]>([])
|
||||||
|
|
||||||
const FormRef = ref()
|
const FormRef = ref()
|
||||||
const form = ref({
|
|
||||||
model_id: '',
|
const userId = user.userInfo?.id as string
|
||||||
prompt: '内容:{data}\n' +
|
const form = ref(prompt.get(userId))
|
||||||
'\n' +
|
|
||||||
'请总结上面的内容,并根据内容总结生成 5 个问题。\n' +
|
|
||||||
'回答要求:\n' +
|
|
||||||
'- 请只输出问题;\n' +
|
|
||||||
'- 请将每个问题放置<question></question>标签中。'
|
|
||||||
})
|
|
||||||
|
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
model_id: [{ required: true, message: '请选择AI 模型', trigger: 'blur' }],
|
model_id: [{ required: true, message: '请选择AI 模型', trigger: 'blur' }],
|
||||||
@ -176,6 +169,9 @@ const submitHandle = async (formEl: FormInstance) => {
|
|||||||
}
|
}
|
||||||
await formEl.validate((valid, fields) => {
|
await formEl.validate((valid, fields) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
// 保存提示词
|
||||||
|
prompt.save(user.userInfo?.id as string, form.value)
|
||||||
|
|
||||||
const data = { ...form.value, paragraph_id_list: paragraphIdList.value }
|
const data = { ...form.value, paragraph_id_list: paragraphIdList.value }
|
||||||
paragraphApi.batchGenerateRelated(id, documentId, data).then(() => {
|
paragraphApi.batchGenerateRelated(id, documentId, data).then(() => {
|
||||||
MsgSuccess('生成关联问题成功')
|
MsgSuccess('生成关联问题成功')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user