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