From 50e3030db506548e55266d50ee1eecdc1da7b459 Mon Sep 17 00:00:00 2001 From: Twilight Date: Sun, 15 Sep 2024 21:38:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AssistantMenu.vue | 14 +++++++++++++- src/components/chat/Chat.vue | 19 ++++++++++++++----- src/config/config.ts | 2 +- src/stores/chat.ts | 1 + 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/AssistantMenu.vue b/src/components/AssistantMenu.vue index 4fee14f..1c12f1c 100644 --- a/src/components/AssistantMenu.vue +++ b/src/components/AssistantMenu.vue @@ -6,7 +6,11 @@ ċˆ‡ĉ˘ċŠİ理 - + {{ a.name }} @@ -18,10 +22,12 @@ import { useUserStore } from "../stores/user"; import { updateAll } from "../plugins/update/update"; import { useAssistantStore } from "../stores/assistants"; +import { useChatStore } from "@/stores/chat"; const loaded = ref(false); const userStore = useUserStore(); const assistantStore = useAssistantStore(); +const chatStore = useChatStore(); watch( () => userStore.logined, @@ -36,5 +42,11 @@ function update() { loaded.value = true; } +const changeAssistant = (id: number | undefined) => { + if (id) { + chatStore.currentAssistantId = id; + } +}; + update(); diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue index 0a90060..159da13 100644 --- a/src/components/chat/Chat.vue +++ b/src/components/chat/Chat.vue @@ -141,6 +141,7 @@ import { EntityChatMessage, SchemaChatMessageAddRequestRoleEnum, EntityChat, + SchemaChatMessageAddRequest, } from "@/api"; import getApi from "@/plugins/api"; import MessageList from "./MessageList.vue"; @@ -339,12 +340,20 @@ async function sendMessage( }); } + let payload: SchemaChatMessageAddRequest = { + message: text, + role: role, + }; + if (chatStore.currentAssistantId) { + payload = { + ...payload, + assistant_id: chatStore.currentAssistantId, + }; + } + toolError.value = false; getApi() - .ChatMessage.apiV1ChatsIdMessagesPost(Number(chatId.value), { - message: text, - role: role, - }) + .ChatMessage.apiV1ChatsIdMessagesPost(Number(chatId.value), payload) .then(async (res) => { // const newMessage = { // content: text, @@ -529,7 +538,7 @@ const chatData: Ref = ref({}); const getChat = async () => { chatData.value = ( await getApi().Chat.apiV1ChatsIdGet(chatStore.currentChatId) - ).data.data; + ).data.data ?? {}; }; onMounted(() => { diff --git a/src/config/config.ts b/src/config/config.ts index d2c8e61..a601ecf 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -16,7 +16,7 @@ if (process.env.NODE_ENV === "production") { config.oauth_client_id = "16"; } -// config.backend = "https://amber-api.leaflow.cn"; +config.backend = "https://amber-api.leaflow.cn"; // console.log("api endpoint: " + config.backend); diff --git a/src/stores/chat.ts b/src/stores/chat.ts index d2f3817..a1771ed 100644 --- a/src/stores/chat.ts +++ b/src/stores/chat.ts @@ -5,6 +5,7 @@ export const useChatStore = defineStore("chats", { persist: false, state: () => ({ currentChatId: 0, + currentAssistantId: 0, chats: [], }), });