Files
chatai/src/components/settings.vue

105 lines
2.5 KiB
Vue
Raw Normal View History

2023-05-12 15:53:39 +08:00
<template>
<section class="settings">
2023-05-15 17:05:36 +08:00
<el-form label-position="top" class="w100">
<el-form-item label="语言模型">
<el-row class="flexWrap">
<ai-model v-for="m in models" :model="m" small :class="{active:settings.model.id==m.id}"
@click="settings.model=m"/>
</el-row>
</el-form-item>
<el-form-item label="流式输出">
<el-switch v-model="settings.stream" :active-value="true" :inactive-value="false"/>
</el-form-item>
<el-form-item label="API KEY">
<el-input v-model="settings.model.apiKey" clearable @change="v=>settings.model.setApiKey(v),getModelAccount()"/>
</el-form-item>
2023-05-15 17:58:00 +08:00
<el-row v-loading="loadingAccount" element-loading-background="#272A37">
<el-form-item label="账号用户" class="fill">{{ account.username }}</el-form-item>
<el-form-item label="账户余额" class="fill">{{ [account.usage, account.total].join(" / ") }}</el-form-item>
<el-button type="text" @click="getModelAccount">刷新</el-button>
2023-05-15 17:05:36 +08:00
</el-row>
</el-form>
2023-05-12 15:53:39 +08:00
</section>
</template>
<script>
2023-05-15 17:05:36 +08:00
import AiModel from "../ui/AiModel";
import AiSelect from "../ui/AiSelect";
import * as models from "../utils/models";
2023-05-12 15:53:39 +08:00
export default {
name: "settings",
2023-05-15 17:05:36 +08:00
components: {AiModel, AiSelect},
2023-05-12 15:53:39 +08:00
props: {
2023-05-12 16:41:11 +08:00
modelValue: {default: () => ({})}
2023-05-12 15:53:39 +08:00
},
2023-05-12 16:41:11 +08:00
emits: ["update:modelValue"],
2023-05-12 15:53:39 +08:00
data() {
2023-05-12 16:41:11 +08:00
return {
2023-05-15 17:58:00 +08:00
settings: {},
loadingAccount: false
2023-05-12 16:41:11 +08:00
}
2023-05-12 15:53:39 +08:00
},
2023-05-15 17:05:36 +08:00
watch: {
modelValue: {
immediate: true,
handler(v) {
2023-05-15 17:58:00 +08:00
this.settings = v
2023-05-15 17:05:36 +08:00
}
}
},
computed: {
models: () => Object.values(models).map((model => new model())),
account: v => v.settings.account || {usage: 0, total: 0}
},
methods: {
getModelAccount() {
2023-05-15 17:58:00 +08:00
const ai = this.settings.model
if (ai.getAccount) {
this.loadingAccount = true
ai.getAccount().then(v => this.settings.account = v).finally(() => this.loadingAccount = false)
}
2023-05-15 17:05:36 +08:00
}
},
2023-05-12 15:53:39 +08:00
created() {
}
}
</script>
<style lang="scss" scoped>
.settings {
min-width: 400px;
2023-05-15 17:05:36 +08:00
:deep(.el-form) {
.el-form-item__label {
2023-05-15 17:58:00 +08:00
color: #bbb;
}
.el-form-item__content {
2023-05-15 17:05:36 +08:00
color: white;
}
.el-input__wrapper {
background-color: transparent;
& > input {
color: white;
}
}
.AiModel {
padding: 8px;
border: 1px solid transparent;
cursor: pointer;
user-select: none;
&.active {
border-color: #409EFF;
border-radius: 4px;
}
}
}
2023-05-12 15:53:39 +08:00
}
</style>