Explorar o código

change client service

tycoding hai 1 ano
pai
achega
e434867ebf

+ 0 - 2
langchat-aigc/src/main/java/cn/tycoding/langchat/aigc/controller/AigcConversationController.java

@@ -82,8 +82,6 @@ public class AigcConversationController {
     @GetMapping("/messages/{conversationId}")
     public R getMessages(@PathVariable String conversationId) {
         List<AigcMessage> list = aigcMessageService.getMessages(conversationId);
-
-        //TODO 处理会话
         return R.ok(list);
     }
 

+ 1 - 1
langchat-aigc/src/main/java/cn/tycoding/langchat/aigc/controller/AigcPromptController.java

@@ -37,7 +37,7 @@ public class AigcPromptController {
 
     @GetMapping("/list")
     public R list(AigcPrompt data) {
-        List<AigcPrompt> list = aigcPromptService.list();
+        List<AigcPrompt> list = aigcPromptService.list(Wrappers.<AigcPrompt>lambdaQuery().orderByDesc(AigcPrompt::getCreateTime));
         return R.ok(list);
     }
 

+ 7 - 1
langchat-server/src/main/java/cn/tycoding/langchat/aigc/endpoint/AigcChatEndpoint.java

@@ -1,5 +1,6 @@
 package cn.tycoding.langchat.aigc.endpoint;
 
+import cn.hutool.core.util.StrUtil;
 import cn.tycoding.langchat.aigc.entity.AigcOss;
 import cn.tycoding.langchat.aigc.service.AigcOssService;
 import cn.tycoding.langchat.aigc.service.ChatService;
@@ -42,7 +43,12 @@ public class AigcChatEndpoint {
         req.setEmitter(emitter);
         req.setUserId(AigcAuthUtil.getUserId());
         req.setUsername(AigcAuthUtil.getUsername());
-        req.setPrompt(PromptUtil.build(req.getMessage()));
+
+        if (StrUtil.isBlank(req.getPromptId())) {
+            req.setPrompt(PromptUtil.build(req.getMessage()));
+        } else {
+            req.setPrompt(PromptUtil.build(req.getMessage(), req.getPromptText()));
+        }
 
         if (req.getModel().endsWith(ModelConst.IMAGE_SUFFIX)) {
             AigcOss oss = chatService.image(

+ 1 - 0
langchat-ui-client/src/api/models/index.d.ts

@@ -38,6 +38,7 @@ export interface ChatR {
   conversationId?: string;
   message?: string;
   promptId?: string;
+  promptText?: string;
   role?: 'user' | 'assistant' | 'system';
   createTime?: string;
   type?: string;

+ 2 - 2
langchat-ui-client/src/api/prompt.ts

@@ -1,8 +1,8 @@
 import { http } from '@/utils/request';
 
-export function getBotPage(data: any) {
+export function getPrompts(data: any) {
   return http.get({
-    url: '/aigc/prompt/page',
+    url: '/aigc/prompt/list',
     data: data,
   });
 }

+ 3 - 2
langchat-ui-client/src/utils/request/index.ts

@@ -65,14 +65,15 @@ function axios<T = any>({
 
   const failHandler = (error: any) => {
     console.error(error);
+
+    const $message = window['$message'];
     const { status } = error.response;
     if (status === 401) {
+      $message!.error('Login failed, please login again');
       router.push({ name: 'Login' });
       return;
     }
 
-    const $message = window['$message'];
-
     if (error.response !== undefined && error.response.data != undefined) {
       $message!.error(error.response.data.message ?? '接口请求异常');
     }

+ 12 - 2
langchat-ui-client/src/views/modules/chat/index.vue

@@ -80,6 +80,14 @@
 
   async function onChat(message: string, conversationId?: string) {
     try {
+      let promptText = undefined;
+      if (chatStore.selectPromptId !== null && chatStore.selectPromptId !== '') {
+        const arr = chatStore.prompts.filter((i) => i.id === chatStore.selectPromptId);
+        if (arr.length) {
+          promptText = arr[0].prompt;
+        }
+      }
+
       await chat(
         {
           chatId: chatId.value,
@@ -87,6 +95,8 @@
           role: 'user',
           model: chatStore.model,
           conversationId: conversationId,
+          promptId: chatStore.selectPromptId,
+          promptText,
         },
         async ({ event }) => {
           const list = event.target.responseText.split('\n\n');
@@ -188,7 +198,7 @@
   ]);
 
   const footerClass = computed(() => {
-    let classes = ['p-4'];
+    let classes = ['p-4 pt-0'];
     if (isMobile.value) {
       classes = ['sticky', 'left-0', 'bottom-0', 'right-0', 'p-2', 'pr-3', 'overflow-hidden'];
     }
@@ -227,7 +237,7 @@
                 v-else
                 ref="scrollRef"
                 class="max-w-screen-2xl m-auto"
-                :class="[isMobile ? 'p-2' : 'p-5 !px-12']"
+                :class="[isMobile ? 'p-2' : 'p-5 py-8 !px-12']"
               >
                 <Message
                   v-for="(item, index) of dataSources"

+ 1 - 1
langchat-ui-client/src/views/modules/chat/sider/List.vue

@@ -43,7 +43,7 @@
 </script>
 
 <template>
-  <NScrollbar class="px-4">
+  <NScrollbar class="px-4 flex-1">
     <div class="flex flex-col gap-2 text-sm">
       <template v-if="!dataSources.length">
         <div

+ 9 - 1
langchat-ui-client/src/views/modules/chat/sider/index.vue

@@ -83,8 +83,16 @@
             <span>{{ t('chat.newChatButton') }}</span>
           </n-button>
         </div>
-        <div class="flex-1 min-h-0 pb-4 overflow-hidden">
+        <div class="flex-1 min-h-0 pb-4 overflow-hidden flex flex-col gap-2">
           <List />
+          <div class="pb-2 px-4">
+            <n-select
+              :options="chatStore.prompts"
+              :label-field="'name'"
+              :value-field="'id'"
+              v-model:value="chatStore.selectPromptId"
+            />
+          </div>
         </div>
       </main>
     </div>

+ 2 - 0
langchat-ui-client/src/views/modules/chat/store/chat.d.ts

@@ -9,4 +9,6 @@ export interface ChatState {
   conversations: any[]; //左侧会话窗口列表
   curConversation: any; //当前选中的会话窗口
   messages: any[]; //当前选中的消息内容
+  prompts: any[];
+  selectPromptId: any;
 }

+ 6 - 2
langchat-ui-client/src/views/modules/chat/store/useChatStore.ts

@@ -9,6 +9,7 @@ import {
 import { ChatState } from './chat';
 import { formatToDateTime } from '@/utils/dateUtil';
 import { toRaw } from 'vue';
+import { getPrompts } from '@/api/prompt';
 
 export const useChatStore = defineStore('chat-store', {
   state: (): ChatState =>
@@ -23,6 +24,8 @@ export const useChatStore = defineStore('chat-store', {
       conversations: [],
       curConversation: undefined,
       messages: [],
+      prompts: [],
+      selectPromptId: undefined,
     },
 
   getters: {},
@@ -49,6 +52,8 @@ export const useChatStore = defineStore('chat-store', {
           this.curConversation = data[0];
           await this.selectConversation({ id: data[0].id });
         }
+
+        this.prompts = await getPrompts({});
       } finally {
         this.sideIsLoading = false;
         this.chatIsLoading = false;
@@ -59,7 +64,6 @@ export const useChatStore = defineStore('chat-store', {
      * 选择会话窗口
      */
     async selectConversation(params: any) {
-      console.log('选择窗口', params);
       this.chatIsLoading = true;
       this.messages = [];
       if (params.id == undefined) {
@@ -68,7 +72,7 @@ export const useChatStore = defineStore('chat-store', {
       await this.setActive(params.id);
       getMessages(params.id)
         .then((res: any) => {
-          this.messages = res.reverse();
+          this.messages = res;
         })
         .finally(() => {
           this.chatIsLoading = false;

+ 2 - 2
langchat-ui-client/src/views/modules/doc/components/Chat.vue

@@ -53,8 +53,8 @@
 
   const messages = ref<
     {
-      id: string;
-      role: 'role' | 'assistant';
+      id: any;
+      role: 'user' | 'assistant';
       error: boolean;
       message: string;
       createTime?: any;

+ 2 - 9
langchat-ui-client/src/views/modules/home/components/CardList.vue

@@ -5,8 +5,6 @@
   import { useRouter } from 'vue-router';
   import { t } from '@/locales';
   import { useChatStore } from '@/views/modules/chat/store/useChatStore';
-  import { add as addConversation } from '@/api/conversation';
-  import { Conversation } from '@/typings/chat';
 
   interface Props {
     list: Array<Bot>;
@@ -16,13 +14,8 @@
   const router = useRouter();
 
   async function onUse(id: string) {
-    const data = (await addConversation({ promptId: id })) as Conversation;
-    chatStore.curConversation = data;
-    await router.push({
-      name: 'Chat',
-      query: { conversationId: data.id, promptId: data.id },
-    });
-    chatStore.active = '';
+    chatStore.selectPromptId = id;
+    await router.push('/chat');
   }
 </script>
 

+ 4 - 11
langchat-ui-client/src/views/modules/home/index.vue

@@ -4,17 +4,12 @@
   import Typed from 'typed.js';
   import CardList from './components/CardList.vue';
   import { Bot } from '@/api/models';
-  import { getBotPage } from '@/api/prompt';
+  import { getPrompts } from '@/api/prompt';
   import { useRouter } from 'vue-router';
   import { t } from '@/locales';
 
   const router = useRouter();
-  const pageInfo = {
-    page: 1,
-    limit: 20,
-    total: 0,
-  };
-  const botList = ref<Bot[]>([]);
+  const prompts = ref<Bot[]>([]);
   const loading = ref(true);
   const title = ref('');
 
@@ -31,9 +26,7 @@
   });
 
   async function fetchData() {
-    const data = await getBotPage({ ...pageInfo, title: title.value });
-    botList.value = data.rows;
-    pageInfo.total = data.total;
+    prompts.value = await getPrompts({ title: title.value });
     loading.value = false;
   }
 </script>
@@ -88,7 +81,7 @@
         </n-input>
 
         <n-spin size="large" :show="loading">
-          <CardList :list="botList" />
+          <CardList :list="prompts" />
         </n-spin>
       </div>
     </div>