update model selector

This commit is contained in:
AceDataCloud committed 2023-10-01 13:24:12 +08:00
1 parent 8c1f3ab04d
commit aef00375d7
6 files changed
+213 -94

No files matched your search

+90 -53
View File
@@ -1,14 +1,26 @@
<template> <template>
<div class="model-selector"> <div class="model-selector">
<el-dropdown v-for="(group, groupIndex) in groups" :key="groupIndex" @command="onCommandChange"> <el-dropdown v-for="(group, groupIndex) in groups" :key="groupIndex" trigger="click" @command="onCommandChange">
<el-button type="primary"> <el-button :class="{ group: true, active: group.value === activeGroup }" @click="onSwitchGroup(group)">
{{ group.label }} <font-awesome-icon :icon="group.icon" :class="'icon ' + group.value" />
<el-icon class="el-icon--right"><arrow-down /></el-icon> <span v-if="group.value === activeGroup">
{{ value.displayName }}
</span>
<span v-else>
{{ group.label }}
</span>
<font-awesome-icon icon="fa-solid fa-chevron-down" />
</el-button> </el-button>
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu class="menu">
<el-dropdown-item v-for="(option, optionIndex) in group.options" :key="optionIndex" :command="option.value"> <el-dropdown-item
{{ option.label }} v-for="(model, modelIndex) in group.options"
:key="modelIndex"
:command="model"
class="option"
>
<font-awesome-icon :icon="group.icon" :class="'icon ' + group.value" />
{{ model.displayName }}
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
@@ -18,16 +30,16 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { ElSelect, ElOption, ElDropdown, ElButton, ElDropdownItem } from 'element-plus'; import { ElDropdown, ElButton, ElDropdownItem } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ROUTE_CHAT_INDEX } from '@/router/constants';
import { import {
API_ID_CHATGPT, CHAT_MODEL_CHATGPT,
API_ID_CHATGPT4, CHAT_MODEL_CHATGPT4,
API_ID_CHATGPT4_BROWSING, CHAT_MODEL_CHATGPT4_BROWSING,
API_ID_CHATGPT_16K, CHAT_MODEL_CHATGPT_16K,
API_ID_CHATGPT_BROWSING CHAT_MODEL_CHATGPT_BROWSING
} from '@/operators/chat/constants'; } from '@/operators/chat/constants';
import { IChatModel } from '@/operators';
export default defineComponent({ export default defineComponent({
name: 'ModelSelector', name: 'ModelSelector',
@@ -39,7 +51,7 @@ export default defineComponent({
}, },
props: { props: {
modelValue: { modelValue: {
type: String, type: Object as () => IChatModel,
required: true required: true
} }
}, },
@@ -47,38 +59,19 @@ export default defineComponent({
data() { data() {
return { return {
value: this.modelValue, value: this.modelValue,
activeGroup: 'base',
groups: [ groups: [
{ {
label: '基础', label: '基础',
value: 'base', value: 'base',
options: [ icon: 'fa-solid fa-bolt',
{ options: [CHAT_MODEL_CHATGPT, CHAT_MODEL_CHATGPT_16K, CHAT_MODEL_CHATGPT_BROWSING]
label: 'AI 问答',
value: API_ID_CHATGPT
},
{
label: 'AI 问答 3.5 - 16K',
value: API_ID_CHATGPT_16K
},
{
label: 'AI 问答 3.5 - 联网版',
value: API_ID_CHATGPT_BROWSING
}
]
}, },
{ {
label: 'Plus', label: 'Plus',
value: 'plus', value: 'plus',
options: [ icon: 'fa-solid fa-wand-magic-sparkles',
{ options: [CHAT_MODEL_CHATGPT4, CHAT_MODEL_CHATGPT4_BROWSING]
label: 'AI 问答 4.0',
value: API_ID_CHATGPT4
},
{
label: 'AI 问答 4.0 - 联网版',
value: API_ID_CHATGPT4_BROWSING
}
]
} }
] ]
}; };
@@ -91,29 +84,73 @@ export default defineComponent({
} }
}, },
methods: { methods: {
onCommandChange(command: string) { onSwitchGroup(group: any) {
console.log('val', command); this.activeGroup = group.value;
const options = group.options;
if (options && options.length > 0) {
this.value = options[0];
this.$emit('select', options[0]);
this.$emit('update:modelValue', options[0]);
}
},
onCommandChange(command: IChatModel) {
this.value = command; this.value = command;
// this.$emit('update:modelValue', command);
this.$emit('select', command); this.$emit('select', command);
console.log('ss', command); this.$emit('update:modelValue', command);
} }
} }
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.sidebar { .model-selector {
display: flex; background-color: #ececf1;
flex-direction: column; padding: 7px;
align-items: flex-end; border-radius: 15px;
.top { .group {
display: flex; padding: 20px 30px;
flex-direction: column; color: black;
border: none;
border-radius: 10px;
margin: 0 3px;
background-color: inherit;
&:hover,
&:focus {
background-color: inherit;
}
&.active {
background-color: white;
}
.icon {
display: inline-block;
margin-right: 5px;
&.base {
color: #ff9900;
}
&.plus {
color: #ce65e6;
}
}
.fa-chevron-down {
margin-left: 5px;
font-weight: 100;
color: #999;
transform: scale(0.8);
}
} }
.bottom { }
display: flex; .menu {
flex-direction: column; .option {
.icon {
display: inline-block;
margin-right: 5px;
&.base {
color: #ff9900;
}
&.plus {
color: #ce65e6;
}
}
} }
} }
</style> </style>
+29
View File
@@ -0,0 +1,29 @@
<template>
<span v-if="application">
{{ $t('conversation.message.usedCount') }}: {{ application?.used_amount }}
{{ $t('conversation.message.remainingCount') }}: {{ application?.remaining_amount }}
</span>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IApplication } from '@/operators';
export default defineComponent({
name: 'ApiStatus',
components: {},
props: {
application: {
type: Object as () => IApplication,
required: true
}
},
data() {
return {};
},
computed: {},
methods: {}
});
</script>
<style lang="scss"></style>
+42 -1
View File
@@ -1,6 +1,47 @@
import { IChatModel } from './models';
export const ROLE_SYSTEM = 'system';
export const ROLE_ASSISTANT = 'assistant';
export const ROLE_USER = 'user';
export const CHAT_MODEL_NAME_CHATGPT = 'chatgpt';
export const CHAT_MODEL_NAME_CHATGPT4 = 'chatgpt4';
export const CHAT_MODEL_NAME_CHATGPT_16K = 'chatgpt-16k';
export const CHAT_MODEL_NAME_CHATGPT_BROWSING = 'chatgpt-browsing';
export const CHAT_MODEL_NAME_CHATGPT4_BROWSING = 'chatgpt4-browsing';
export const API_ID_CHATGPT = '1d58971c-e3cd-4713-a3ce-854a731adb14'; export const API_ID_CHATGPT = '1d58971c-e3cd-4713-a3ce-854a731adb14';
export const API_ID_CHATGPT_16K = 'bf93bb28-55a7-4428-ad82-156bf410f4e2'; export const API_ID_CHATGPT_16K = 'bf93bb28-55a7-4428-ad82-156bf410f4e2';
export const API_ID_CHATGPT_BROWSING = '12271e2e-794f-4079-a714-f68dd0df7808'; export const API_ID_CHATGPT_BROWSING = '12271e2e-794f-4079-a714-f68dd0df7808';
export const API_ID_CHATGPT4 = '1c4e8fa3-362b-4e0a-b0fd-9ff9fc173b77'; export const API_ID_CHATGPT4 = '1c4e8fa3-362b-4e0a-b0fd-9ff9fc173b77';
export const API_ID_CHATGPT4_BROWSING = 'a61de51b-d0d0-48a2-9a17-1d4986d5d497'; export const API_ID_CHATGPT4_BROWSING = 'a61de51b-d0d0-48a2-9a17-1d4986d5d497';
export const CHAT_MODEL_CHATGPT: IChatModel = {
apiId: API_ID_CHATGPT,
name: CHAT_MODEL_NAME_CHATGPT,
displayName: '基础 - 3.5'
};
export const CHAT_MODEL_CHATGPT_16K: IChatModel = {
apiId: API_ID_CHATGPT_16K,
name: CHAT_MODEL_NAME_CHATGPT_16K,
displayName: '基础 - 16k'
};
export const CHAT_MODEL_CHATGPT_BROWSING: IChatModel = {
apiId: API_ID_CHATGPT_BROWSING,
name: CHAT_MODEL_NAME_CHATGPT_BROWSING,
displayName: '基础 - 联网版'
};
export const CHAT_MODEL_CHATGPT4: IChatModel = {
apiId: API_ID_CHATGPT4,
name: CHAT_MODEL_NAME_CHATGPT4,
displayName: 'Plus - 4.0'
};
export const CHAT_MODEL_CHATGPT4_BROWSING: IChatModel = {
apiId: API_ID_CHATGPT4_BROWSING,
name: CHAT_MODEL_NAME_CHATGPT4_BROWSING,
displayName: 'Plus - 4.0 联网版'
};
+31 -24
View File
@@ -1,38 +1,51 @@
import {
CHAT_MODEL_NAME_CHATGPT,
CHAT_MODEL_NAME_CHATGPT4,
CHAT_MODEL_NAME_CHATGPT4_BROWSING,
CHAT_MODEL_NAME_CHATGPT_16K,
CHAT_MODEL_NAME_CHATGPT_BROWSING,
ROLE_ASSISTANT,
ROLE_SYSTEM,
ROLE_USER
} from './constants';
export type IChatModelName =
| typeof CHAT_MODEL_NAME_CHATGPT
| typeof CHAT_MODEL_NAME_CHATGPT4
| typeof CHAT_MODEL_NAME_CHATGPT_16K
| typeof CHAT_MODEL_NAME_CHATGPT_BROWSING
| typeof CHAT_MODEL_NAME_CHATGPT4_BROWSING;
export interface IChatModel {
apiId: string;
name: IChatModelName;
displayName: string;
}
export interface IError { export interface IError {
code: string; code: string;
detail?: string; detail?: string;
} }
export enum ChatMessageState { export enum IChatMessageState {
PENDING = 'pending', PENDING = 'pending',
ANSWERING = 'answering', ANSWERING = 'answering',
FINISHED = 'finished', FINISHED = 'finished',
FAILED = 'failed' FAILED = 'failed'
} }
export const ROLE_SYSTEM = 'system';
export const ROLE_ASSISTANT = 'assistant';
export const ROLE_USER = 'user';
export interface IChatMessage { export interface IChatMessage {
state?: ChatMessageState; state?: IChatMessageState;
content: string; content: string;
role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER; role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER;
error?: IError; error?: IError;
} }
export const CHAT_MODEL_CHATGPT = 'chatgpt'; export interface IChatOptions {
export const CHAT_MODEL_CHATGPT4 = 'chatgpt4'; stream?: (response: IChatResponse) => void;
export const CHAT_MODEL_CHATGPT_16K = 'chatgpt-16k'; token: string;
export const CHAT_MODEL_CHATGPT_BROWSING = 'chatgpt-browsing'; endpoint?: string;
export const CHAT_MODEL_CHATGPT4_BROWSING = 'chatgpt4-browsing'; }
export type IChatModel =
| typeof CHAT_MODEL_CHATGPT
| typeof CHAT_MODEL_CHATGPT4
| typeof CHAT_MODEL_CHATGPT_16K
| typeof CHAT_MODEL_CHATGPT_BROWSING
| typeof CHAT_MODEL_CHATGPT4_BROWSING;
export interface IChatRequest { export interface IChatRequest {
question: string; question: string;
@@ -45,9 +58,3 @@ export interface IChatResponse {
delta_answer: string; delta_answer: string;
conversation_id?: string; conversation_id?: string;
} }
export interface IChatOptions {
stream?: (response: IChatResponse) => void;
token: string;
endpoint?: string;
}
+17 -16
View File
@@ -1,9 +1,7 @@
<template> <template>
<div class="page"> <div class="page">
<model-selector v-model="apiId" class="model-selector" @select="onSelectModel" /> <model-selector v-model="model" class="model-selector" @select="onLoadModel" />
<div> <api-status v-if="application" :application="application" />
{{ application?.remaining_amount }}
</div>
<div class="main"> <div class="main">
<introduction v-if="messages && messages.length === 0" /> <introduction v-if="messages && messages.length === 0" />
<div v-else class="messages"> <div v-else class="messages">
@@ -29,20 +27,21 @@ import {
IChatResponse, IChatResponse,
API_ID_CHATGPT, API_ID_CHATGPT,
applicationOperator, applicationOperator,
IApplication, IApplication
ChatMessageState
} from '@/operators'; } from '@/operators';
import InputBox from '@/components/chat/InputBox.vue'; import InputBox from '@/components/chat/InputBox.vue';
import ModelSelector from '@/components/chat/ModelSelector.vue'; import ModelSelector from '@/components/chat/ModelSelector.vue';
import { chatOperator } from '@/operators'; import { chatOperator } from '@/operators';
import { ERROR_CODE_CANCELED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode'; import { ERROR_CODE_CANCELED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
import axios from 'axios'; import axios from 'axios';
import ApiStatus from '@/components/common/ApiStatus.vue';
export interface IData { export interface IData {
messages: IChatMessage[]; messages: IChatMessage[];
model: IChatModel;
application: IApplication | undefined; application: IApplication | undefined;
apiId: string;
question: ''; question: '';
needApply: boolean; applied: boolean | undefined;
} }
export default defineComponent({ export default defineComponent({
@@ -51,13 +50,14 @@ export default defineComponent({
// Introduction, // Introduction,
InputBox, InputBox,
ModelSelector, ModelSelector,
Message Message,
ApiStatus
}, },
data(): IData { data(): IData {
return { return {
model: CHAT_MODEL_CHATGPT,
question: '', question: '',
needApply: false, applied: undefined,
apiId: API_ID_CHATGPT,
application: undefined, application: undefined,
messages: [ messages: [
{ {
@@ -108,19 +108,20 @@ export default defineComponent({
return this.$route.params.id?.toString(); return this.$route.params.id?.toString();
} }
}, },
mounted() {
this.onLoadModel();
},
methods: { methods: {
async onSelectModel() { async onLoadModel() {
console.log('this.apiId', this.apiId);
const { data: applications } = await applicationOperator.getAll({ const { data: applications } = await applicationOperator.getAll({
user_id: this.$store.state.user.id, user_id: this.$store.state.user.id,
api_id: this.apiId api_id: this.model.apiId
}); });
if (!applications || applications?.items?.length === 0) { if (!applications || applications?.items?.length === 0) {
this.needApply = true; this.applied = false;
return; return;
} }
this.application = applications.items[0]; this.application = applications.items[0];
console.log('applications', applications);
}, },
async onSubmitQuestion() { async onSubmitQuestion() {
this.messages.push({ this.messages.push({
+4
View File
@@ -9,6 +9,7 @@ import {
import { import {
faMicrophone as faSolidMicrophone, faMicrophone as faSolidMicrophone,
faStop as faSolidStop, faStop as faSolidStop,
faWandMagicSparkles as faSolidWandMagicSparkles,
faPalette as faSolidPalette, faPalette as faSolidPalette,
faBars as faSolidBars, faBars as faSolidBars,
faGear as faSolidGear, faGear as faSolidGear,
@@ -18,6 +19,7 @@ import {
faBolt as faSolidBolt, faBolt as faSolidBolt,
faQuestion as faSolidQuestion, faQuestion as faSolidQuestion,
faTrash as faSolidTrash, faTrash as faSolidTrash,
faChevronDown as faSolidChevronDown,
faArrowsRotate as faSolidArrowsRotate, faArrowsRotate as faSolidArrowsRotate,
faUpRightFromSquare as faSolidUpRightFromSquare, faUpRightFromSquare as faSolidUpRightFromSquare,
faArrowRightFromBracket as faSolidArrowRightFromBracket, faArrowRightFromBracket as faSolidArrowRightFromBracket,
@@ -46,4 +48,6 @@ library.add(faRegularPaperPlane);
library.add(faRegularComment); library.add(faRegularComment);
library.add(faSolidArrowRightFromBracket); library.add(faSolidArrowRightFromBracket);
library.add(faSolidTrash); library.add(faSolidTrash);
library.add(faSolidChevronDown);
library.add(faSolidPalette); library.add(faSolidPalette);
library.add(faSolidWandMagicSparkles);