tycoding 1 anno fa
parent
commit
70c45aaeba

+ 1 - 1
docs/langchat.sql

@@ -25,7 +25,7 @@ CREATE TABLE `aigc_app` (
 -- Records of aigc_app
 -- ----------------------------
 BEGIN;
-INSERT INTO `aigc_app` (`id`, `model_id`, `knowledge_ids`, `cover`, `name`, `prompt`, `des`, `save_time`, `create_time`) VALUES ('e16a582b47d3041cf14074d5451dff7a', '0c21c2f8ebd3aa3757ef1bae81154cc4', '[\"393704ac13f67fde5da674ddd0742b03\"]', 'http://127.0.0.1/langchat/2024081066b6e0fbcdb220c420fe6bae.JPEG', 'LangChat官方应用', '你是一个专业的文档分析师,你擅长从文档中提取关键内容并总结分析含义,下面你需要根据用户的问题做出解答。\n\n## 限制\n不要回答和文档无关的内容', '快速解答LangChat项目相关的内容,LangChat官方助手', '2024-08-10 11:39:41', '2024-08-04 17:49:24');
+INSERT INTO `aigc_app` (`id`, `model_id`, `knowledge_ids`, `cover`, `name`, `prompt`, `des`, `save_time`, `create_time`) VALUES ('e16a582b47d3041cf14074d5451dff7a', '0c21c2f8ebd3aa3757ef1bae81154cc4', '[\"393704ac13f67fde5da674ddd0742b03\"]', 'http://cdn.tycoding.cn/tycoding.jpg', 'LangChat官方应用', '你是一个专业的文档分析师,你擅长从文档中提取关键内容并总结分析含义,下面你需要根据用户的问题做出解答。\n\n## 限制\n不要回答和文档无关的内容', '快速解答LangChat项目相关的内容,LangChat官方助手', '2024-08-10 11:39:41', '2024-08-04 17:49:24');
 COMMIT;
 
 -- ----------------------------

+ 2 - 2
langchat-ui/src/utils/dateUtil.ts

@@ -16,8 +16,8 @@
 
 import { format } from 'date-fns';
 
-const DATE_TIME_FORMAT = 'yyyy/MM/dd HH:mm:ss';
-const DATE_FORMAT = 'yyyy/MM/dd ';
+const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
+const DATE_FORMAT = 'yyyy-MM-dd ';
 
 export function formatToDateTime(date: Date | number, formatStr = DATE_TIME_FORMAT): string {
   return format(date, formatStr);

+ 2 - 3
langchat-ui/src/views/app/components/prompt/index.vue

@@ -16,14 +16,13 @@
 
 <script lang="ts" setup>
   import SvgIcon from '@/components/SvgIcon/index.vue';
-  import { useMessage } from 'naive-ui';
   import { useAppStore } from '@/views/app/store';
 
+  const emit = defineEmits(['update']);
   const appStore = useAppStore();
-  const ms = useMessage();
 
   async function onUpdate() {
-    await appStore.updateInfo();
+    emit('update');
   }
 </script>
 

+ 36 - 6
langchat-ui/src/views/app/info.vue

@@ -22,17 +22,19 @@
   import router from '@/router';
   import { onMounted, ref } from 'vue';
   import { getById } from '@/api/app/app';
-  import { useMessage } from 'naive-ui';
+  import { useDialog, useMessage } from 'naive-ui';
   import { useAppStore } from './store';
   import ModelSelect from '@/views/channel/ModelSelect.vue';
   import { useChatStore } from '@/views/chat/store/useChatStore';
-  import { getMessages } from '@/api/aigc/chat';
+  import { clean, getMessages } from '@/api/aigc/chat';
+  import { formatToDateTime } from '@/utils/dateUtil';
 
   const appStore = useAppStore();
   const chatStore = useChatStore();
   const form = ref<any>({});
   const loading = ref(false);
   const ms = useMessage();
+  const dialog = useDialog();
 
   onMounted(async () => {
     await fetchData();
@@ -54,13 +56,35 @@
     loading.value = false;
   }
 
-  async function onSave(val) {
+  async function onSave() {
     loading.value = true;
-    appStore.modelId = val.id;
+    form.value.saveTime = formatToDateTime(new Date());
     await appStore.updateInfo();
     ms.success('应用配置保存成功');
     loading.value = false;
   }
+
+  async function onSaveModel(val) {
+    appStore.modelId = val.id;
+    await onSave();
+  }
+
+  function handleClear() {
+    if (chatStore.conversationId == null) {
+      return;
+    }
+    dialog.warning({
+      title: '清除聊天',
+      content: '确认清除聊天',
+      positiveText: '是',
+      negativeText: '否',
+      onPositiveClick: async () => {
+        await clean(chatStore.conversationId);
+        await fetchData();
+        ms.success('聊天记录清除成功');
+      },
+    });
+  }
 </script>
 
 <template>
@@ -82,8 +106,14 @@
         </div>
       </div>
       <div class="flex gap-2 items-center">
-        <ModelSelect :id="appStore.modelId" class="!w-auto" @update="onSave" />
+        <ModelSelect :id="appStore.modelId" class="!w-auto" @update="onSaveModel" />
         <n-button class="px-6 rounded-lg" type="info" @click="onSave">保存应用</n-button>
+        <n-button secondary size="small" type="warning" @click="handleClear">
+          <template #icon>
+            <SvgIcon class="text-[14px]" icon="fluent:delete-12-regular" />
+          </template>
+          清空聊天
+        </n-button>
       </div>
     </div>
     <n-split
@@ -96,7 +126,7 @@
     >
       <template #1>
         <div class="p-2 h-full m-2 bg-white rounded-lg">
-          <PromptPage />
+          <PromptPage @update="onSave" />
         </div>
       </template>
       <template #2>