From 14541a41458209fc7e195d6c523032d35cd84c46 Mon Sep 17 00:00:00 2001 From: Germey Date: Sat, 30 Dec 2023 23:06:20 +0800 Subject: [PATCH] fix bugs --- src/components/chat/ModelSelector.vue | 71 ++++++++++----------- src/components/chat/SidePanel.vue | 7 +- src/components/common/Navigator.vue | 3 +- src/pages/chat/Conversation.vue | 92 ++++++++++++++++----------- src/pages/midjourney/History.vue | 13 +--- src/router/chat.ts | 7 +- src/router/constants.ts | 1 + src/store/chat/actions.ts | 20 ++++++ src/store/chat/models.ts | 3 +- src/store/chat/mutations.ts | 7 +- src/store/chat/persist.ts | 2 +- src/store/chat/state.ts | 2 + 12 files changed, 134 insertions(+), 94 deletions(-) diff --git a/src/components/chat/ModelSelector.vue b/src/components/chat/ModelSelector.vue index f4f61f6..0dbd7a8 100644 --- a/src/components/chat/ModelSelector.vue +++ b/src/components/chat/ModelSelector.vue @@ -4,7 +4,7 @@ - {{ value.displayName }} + {{ model.displayName }} {{ group.label }} @@ -14,13 +14,13 @@ @@ -41,6 +41,21 @@ import { } from '@/operators/chat/constants'; import { IChatModel } from '@/operators'; +const GROUPS = [ + { + label: '3.5', + value: 'base', + icon: 'fa-solid fa-bolt', + options: [CHAT_MODEL_CHATGPT, CHAT_MODEL_CHATGPT_16K, CHAT_MODEL_CHATGPT_BROWSING] + }, + { + label: '4.0', + value: 'plus', + icon: 'fa-solid fa-wand-magic-sparkles', + options: [CHAT_MODEL_CHATGPT4, CHAT_MODEL_CHATGPT4_BROWSING] + } +]; + export default defineComponent({ name: 'ModelSelector', components: { @@ -49,38 +64,23 @@ export default defineComponent({ ElDropdownItem, FontAwesomeIcon }, - props: { - modelValue: { - type: Object as () => IChatModel, - required: true - } - }, emits: ['update:modelValue', 'select'], data() { + // find active group according to model + const model = this.$store.state.chat.model; + const activeGroup = GROUPS.find((group) => { + return group.options.find((option: IChatModel) => { + return option.name === model.name; + }); + })?.value; return { - value: this.modelValue, - activeGroup: 'base', - groups: [ - { - label: '3.5', - value: 'base', - icon: 'fa-solid fa-bolt', - options: [CHAT_MODEL_CHATGPT, CHAT_MODEL_CHATGPT_16K, CHAT_MODEL_CHATGPT_BROWSING] - }, - { - label: '4.0', - value: 'plus', - icon: 'fa-solid fa-wand-magic-sparkles', - options: [CHAT_MODEL_CHATGPT4, CHAT_MODEL_CHATGPT4_BROWSING] - } - ] + activeGroup, + groups: GROUPS }; }, - watch: { - modelValue(val) { - if (val !== this.value) { - this.value = val; - } + computed: { + model() { + return this.$store.state.chat.model; } }, methods: { @@ -90,16 +90,15 @@ export default defineComponent({ } this.activeGroup = group.value; const options = group.options; + // by default select first option if (options && options.length > 0) { - this.value = options[0]; - this.$emit('update:modelValue', options[0]); this.$emit('select', options[0]); + this.$store.dispatch('chat/setModel', options[0]); } }, onCommandChange(command: IChatModel) { - this.value = command; - this.$emit('update:modelValue', command); this.$emit('select', command); + this.$store.dispatch('chat/setModel', command); } } }); diff --git a/src/components/chat/SidePanel.vue b/src/components/chat/SidePanel.vue index 0fe88c6..28503eb 100644 --- a/src/components/chat/SidePanel.vue +++ b/src/components/chat/SidePanel.vue @@ -68,7 +68,7 @@ import { defineComponent } from 'vue'; import { ElSkeleton, ElInput } from 'element-plus'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; -import { ROUTE_CHAT_CONVERSATION } from '@/router/constants'; +import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router/constants'; import { chatOperator } from '@/operators'; import { IChatConversation } from '@/operators/chat/models'; import { Status } from '@/store/common/models'; @@ -97,10 +97,7 @@ export default defineComponent({ methods: { async onNewConversation() { this.$router.push({ - name: ROUTE_CHAT_CONVERSATION, - params: { - id: uuid() - } + name: ROUTE_CHAT_CONVERSATION_NEW }); }, async onConfirm(conversation: IChatConversation) { diff --git a/src/components/common/Navigator.vue b/src/components/common/Navigator.vue index 69bf02c..1fe5c8c 100644 --- a/src/components/common/Navigator.vue +++ b/src/components/common/Navigator.vue @@ -31,6 +31,7 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { ROUTE_AUTH_LOGIN, ROUTE_CHAT_CONVERSATION, + ROUTE_CHAT_CONVERSATION_NEW, ROUTE_CHAT_INDEX, ROUTE_MIDJOURNEY_HISTORY, ROUTE_MIDJOURNEY_INDEX @@ -50,7 +51,7 @@ export default defineComponent({ name: ROUTE_CHAT_INDEX }, icon: 'fa-regular fa-comment', - routes: [ROUTE_CHAT_INDEX, ROUTE_CHAT_CONVERSATION] + routes: [ROUTE_CHAT_INDEX, ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW] }, { route: { diff --git a/src/pages/chat/Conversation.vue b/src/pages/chat/Conversation.vue index ecb200e..19a780f 100644 --- a/src/pages/chat/Conversation.vue +++ b/src/pages/chat/Conversation.vue @@ -1,6 +1,6 @@