From f047c9b62f0eadfd4203fdb251cd1c40041a5aca Mon Sep 17 00:00:00 2001 From: AceDataCloud Date: Wed, 19 Apr 2023 02:48:49 +0800 Subject: [PATCH] add switch api --- src/components/conversation/NewMessageBox.vue | 127 ++++++++++-------- src/constants/api.ts | 15 +++ src/constants/index.ts | 1 + src/operators/api/chatgpt/operator.ts | 11 ++ src/pages/conversation/Main.vue | 70 ++++++++-- src/store/index.ts | 13 +- 6 files changed, 166 insertions(+), 71 deletions(-) create mode 100644 src/constants/api.ts diff --git a/src/components/conversation/NewMessageBox.vue b/src/components/conversation/NewMessageBox.vue index f69b0b0e..72b5d145 100644 --- a/src/components/conversation/NewMessageBox.vue +++ b/src/components/conversation/NewMessageBox.vue @@ -4,32 +4,36 @@ {{ $t('conversation.message.usedCount') }}: {{ application?.used_amount }} {{ $t('conversation.message.remainingCount') }}: {{ application?.remaining_amount }} - - - {{ $t('conversation.message.howToBreakLine') }} -
- - -
-
- {{ $t('conversation.message.initializing') }} -
-
- {{ $t('conversation.message.apiInfo') }} - - - {{ $t('common.button.apply') }} - - - {{ $t('conversation.message.tryForFree') }} +
+
+ + + {{ $t('conversation.message.howToBreakLine') }} +
+ + +
+
+ {{ $t('conversation.message.initializing') }} +
+
+ {{ $t('conversation.message.apiInfo') }} + + + {{ $t('common.button.apply') }} + + + {{ $t('conversation.message.tryForFree') }} +
+
import { defineComponent } from 'vue'; -import { ElInput, ElButton } from 'element-plus'; +import { ElInput, ElButton, ElSelect, ElOption } from 'element-plus'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { IApi, IApplication } from '@/operators'; import { IApplicationType } from '@/operators'; import ApplicationConfirm from '@/components/application/Confirm.vue'; import VoiceRecognition from './VoiceRecognition.vue'; +import { APIS } from '@/constants/api'; interface IData { applicationType: typeof IApplicationType; @@ -100,6 +105,9 @@ export default defineComponent({ computed: { conversationId() { return this.$route.params?.id?.toString(); + }, + activeApiId() { + return this.$store.getters.activeApiId; } }, watch: { @@ -120,38 +128,43 @@ export default defineComponent({ .new-message-box { position: relative; margin-bottom: 40px; - .new-message-input { - height: 50px; - } - .new-message-operations { - position: absolute; - bottom: 12px; - right: 10px; - color: var(--el-text-color-regular); - .icon-send { - cursor: pointer; + + .new-message-input-box { + position: relative; + width: 100%; + height: 100%; + .new-message-input { + height: 50px; + } + + .new-message-info-input { + position: absolute; + bottom: -25px; + left: 5px; + font-size: 12px; + color: var(--el-text-color-regular); + } + .new-message-operations { + position: absolute; + bottom: 12px; + right: 10px; + color: var(--el-text-color-regular); + .icon-send { + cursor: pointer; + } + } + + .new-message-apply { + position: absolute; + top: 50%; + left: 50%; + width: 100%; + text-align: center; + transform: translate(-50%, -50%); + font-size: 12px; + color: #666; } } - - .new-message-info-input { - position: absolute; - bottom: -25px; - left: 5px; - font-size: 12px; - color: var(--el-text-color-regular); - } - - .new-message-apply { - position: absolute; - top: 50%; - left: 50%; - width: 100%; - text-align: center; - transform: translate(-50%, -50%); - font-size: 12px; - color: #666; - } - .new-message-box-usage-info { color: #999; font-size: 12px; diff --git a/src/constants/api.ts b/src/constants/api.ts new file mode 100644 index 00000000..41577d20 --- /dev/null +++ b/src/constants/api.ts @@ -0,0 +1,15 @@ +export const API_ID_CHATGPT = '1d58971c-e3cd-4713-a3ce-854a731adb14'; +export const API_ID_CHATGPT4 = '1c4e8fa3-362b-4e0a-b0fd-9ff9fc173b77'; + +export const APIS = [ + { + id: API_ID_CHATGPT, + name: 'ChatGPT-3.5' + }, + { + id: API_ID_CHATGPT4, + name: 'ChatGPT-4' + } +]; + +export const DEFAULT_API = APIS[0]; diff --git a/src/constants/index.ts b/src/constants/index.ts index a4768bd1..82e88a64 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -2,3 +2,4 @@ export * from './errorCode'; export * from './env'; export * from './endpoint'; export * from './image'; +export * from './api'; diff --git a/src/operators/api/chatgpt/operator.ts b/src/operators/api/chatgpt/operator.ts index d84d7b18..2d491c4a 100644 --- a/src/operators/api/chatgpt/operator.ts +++ b/src/operators/api/chatgpt/operator.ts @@ -15,3 +15,14 @@ class ChatGPTOperator { } export const chatgptOperator = new ChatGPTOperator(); + +class ChatGPT4Operator { + async post(data: IRequest, query: IQuery, config?: AxiosRequestConfig): Promise> { + return await axios.post(`/chatgpt4`, data, { + ...config, + params: query + }); + } +} + +export const chatgpt4Operator = new ChatGPT4Operator(); diff --git a/src/pages/conversation/Main.vue b/src/pages/conversation/Main.vue index e3305d48..7c126e57 100644 --- a/src/pages/conversation/Main.vue +++ b/src/pages/conversation/Main.vue @@ -1,5 +1,10 @@