From 89d692583d5ef65ea70e13a08dd8f2dcf47a46ef Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud Date: Wed, 17 Jan 2024 16:29:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/api/application.ts | 36 +----- ui/src/api/type/application.ts | 16 ++- ui/src/components/ai-chat/index.vue | 8 +- ui/src/views/application/CreateAndSetting.vue | 121 +++++++++++------- ui/src/views/dataset/DatasetSetting.vue | 2 +- ui/src/views/hit-test/index.vue | 8 +- 6 files changed, 98 insertions(+), 93 deletions(-) diff --git a/ui/src/api/application.ts b/ui/src/api/application.ts index 3314200fd..c6020ddd2 100644 --- a/ui/src/api/application.ts +++ b/ui/src/api/application.ts @@ -34,20 +34,7 @@ const getApplication: ( /** * 创建应用 - * @param 参数 - * { - "name": "string", - "desc": "string", - "model_id": "string", - "multiple_rounds_dialogue": true, - "prologue": "string", - "example": [ - "string" - ], - "dataset_id_list": [ - "string" - ] -} + * @param 参数 */ const postApplication: ( data: ApplicationFormType, @@ -59,19 +46,7 @@ const postApplication: ( /** * 修改应用 * @param 参数 - * { - "name": "string", - "desc": "string", - "model_id": "string", - "multiple_rounds_dialogue": true, - "prologue": "string", - "example": [ - "string" - ], - "dataset_id_list": [ - "string" - ] -} + */ const putApplication: ( applicaiton_id: String, @@ -168,12 +143,7 @@ const getProfile: (loading?: Ref) => Promise = (loading) => { /** * 获得临时回话Id * @param 参数 - * { - "model_id": "string", - "multiple_rounds_dialogue": true, - "dataset_id_list": [ - "string" - ] + } */ const postChatOpen: (data: ApplicationFormType) => Promise> = (data) => { diff --git a/ui/src/api/type/application.ts b/ui/src/api/type/application.ts index a9a0a3de4..d68509656 100644 --- a/ui/src/api/type/application.ts +++ b/ui/src/api/type/application.ts @@ -3,11 +3,19 @@ import { type Ref } from 'vue' interface ApplicationFormType { name?: string desc?: string - model_id: string - multiple_rounds_dialogue: boolean + model_id?: string + multiple_rounds_dialogue?: boolean prologue?: string - example?: string[] - dataset_id_list: string[] + dataset_id_list?: string[] + dataset_setting?: { + top_n: number + similarity: number + max_paragraph_char_number: number + } + model_setting?: { + prompt: string + } + problem_optimization?: boolean } interface chatType { id: string diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index adb08f15b..f86700b5b 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -191,7 +191,7 @@ const isDisabledChart = computed( const prologueList = computed(() => { const temp = props.data?.prologue - const lines = temp.split('\n') + const lines = temp?.split('\n') return lines }) const isMdArray = (val: string) => val.match(/^-\s.*/m) @@ -240,11 +240,7 @@ const startChat = (chat: chatType) => { */ function getChartOpenId() { loading.value = true - const obj = { - model_id: props.data.model_id, - dataset_id_list: props.data.dataset_id_list, - multiple_rounds_dialogue: props.data.multiple_rounds_dialogue - } + const obj = props.data if (props.appId) { applicationApi .getChatOpen(props.appId) diff --git a/ui/src/views/application/CreateAndSetting.vue b/ui/src/views/application/CreateAndSetting.vue index 761ba02d9..0b2d2fb32 100644 --- a/ui/src/views/application/CreateAndSetting.vue +++ b/ui/src/views/application/CreateAndSetting.vue @@ -49,7 +49,7 @@
AI 模型 * - 提示词 + 提示词
参数设置 -
-
+
+
相似度 高于
-
+
引用分段数
TOP
-
+
最多引用字符数
个字符 @@ -166,7 +167,6 @@
- 取消 确认 @@ -220,21 +220,6 @@ :toolbars="[]" :footers="[]" /> - - - - @@ -256,6 +241,19 @@
+ + +

通过调整提示词内容,可以引导大模型聊天方向,该提示词会被固定在上下文的开头。

+

可以使用变量:{data} 是携带知识库中已知信息;{question}是用户提出的问题。

+
+ + +
import { reactive, ref, watch, onMounted } from 'vue' import { useRouter, useRoute } from 'vue-router' -import { groupBy } from 'lodash' +import { groupBy, cloneDeep } from 'lodash' import AddDatasetDialog from './components/AddDatasetDialog.vue' import CreateModelDialog from '@/views/template/component/CreateModelDialog.vue' import SelectProviderDialog from '@/views/template/component/SelectProviderDialog.vue' @@ -295,6 +293,31 @@ const { params: { id } } = route as any +const defaultPrompt = `已知信息: + +{data} + +回答要求: + +- 请简洁和专业的来回答用户的问题。 + +- 如果你不知道答案,请回答“没有在知识库中查找到相关信息,建议咨询相关技术支持或参考官方文档进行操作”。 + +- 避免提及你是从已知信息中获得的知识。 + +- 请保证答案与已知信息中描述的一致。 + +- 请使用 Markdown 语法优化答案的格式。 + +- 已知信息中的图片、链接地址和脚本语言请直接返回。 + +- 请使用与问题相同的语言来回答。 + +问题: + +{question} + ` + const createModelRef = ref>() const selectProviderRef = ref>() @@ -303,7 +326,6 @@ const AddDatasetDialogRef = ref() const loading = ref(false) const datasetLoading = ref(false) -const exampleList = ref(['', '']) const applicationForm = ref({ name: '', desc: '', @@ -313,14 +335,18 @@ const applicationForm = ref({ - MaxKB 主要功能有什么? - MaxKB 支持哪些大语言模型? - MaxKB 支持哪些文档类型?`, - example: [], - dataset_id_list: [] + dataset_id_list: [], + dataset_setting: { + top_n: 3, + similarity: 0.6, + max_paragraph_char_number: 5000 + }, + model_setting: { + prompt: defaultPrompt + }, + problem_optimization: true }) -const formInline = reactive({ - similarity: 0.6, - top_number: 5 -}) const popoverVisible = ref(false) const rules = reactive>({ @@ -336,14 +362,19 @@ const rules = reactive>({ const modelOptions = ref(null) const providerOptions = ref>([]) const datasetList = ref([]) +const dialogFormVisible = ref(false) -watch( - () => exampleList.value, - (val) => { - applicationForm.value.example = val.filter((v) => v) - }, - { deep: true } -) +const model_setting_prompt = ref('') + +function promptChange(val: string) { + if (val === 'open') { + dialogFormVisible.value = true + model_setting_prompt.value = applicationForm.value.model_setting.prompt + } else if (val === 'close') { + dialogFormVisible.value = false + applicationForm.value.model_setting.prompt = model_setting_prompt.value + } +} const submit = async (formEl: FormInstance | undefined) => { if (!formEl) return @@ -387,11 +418,6 @@ function getDetail() { application.asyncGetApplicationDetail(id, loading).then((res: any) => { applicationForm.value = res.data applicationForm.value.model_id = res.data.model - if (res.data?.example.length === 2) { - exampleList.value = res.data?.example - } else if (res.data?.example.length === 1) { - exampleList.value = [res.data?.example[0], ''] - } }) } @@ -475,4 +501,9 @@ onMounted(() => { .prologue-md-editor { height: 150px; } +.dataset_setting { + .form-item { + background: var(--app-layout-bg-color); + } +} diff --git a/ui/src/views/dataset/DatasetSetting.vue b/ui/src/views/dataset/DatasetSetting.vue index b7e03aff8..401fa2c4c 100644 --- a/ui/src/views/dataset/DatasetSetting.vue +++ b/ui/src/views/dataset/DatasetSetting.vue @@ -42,7 +42,7 @@ diff --git a/ui/src/views/hit-test/index.vue b/ui/src/views/hit-test/index.vue index bd28fb314..3b8110b47 100644 --- a/ui/src/views/hit-test/index.vue +++ b/ui/src/views/hit-test/index.vue @@ -75,7 +75,7 @@
- +