对话页面可以方便的修改模型

This commit is contained in:
Wenjie Zhang 2025-03-30 11:53:18 +08:00
parent 3b65dee0e8
commit b2f40c7702
2 changed files with 96 additions and 17 deletions

View File

@ -9,11 +9,29 @@
> >
<MenuOutlined /> <MenuOutlined />
</div> </div>
<a-tooltip :title="configStore.config?.model_name" placement="rightTop">
<div class="newchat nav-btn" @click="$emit('newconv')"> <div class="newchat nav-btn" @click="$emit('newconv')">
<PlusCircleOutlined /> <span class="text">新对话</span> <PlusCircleOutlined /> <span class="text">新对话</span>
</div> </div>
</a-tooltip> <a-dropdown>
<a class="model-select nav-btn" @click.prevent>
<BulbOutlined /> <span class="text">{{ configStore.config?.model_provider }}/{{ configStore.config?.model_name }}</span>
</a>
<template #overlay>
<a-menu class="scrollable-menu">
<a-menu-item-group v-for="(item, key) in modelKeys" :key="key" :title="modelNames[item]?.name">
<a-menu-item v-for="(model, idx) in modelNames[item]?.models" :key="`${item}-${idx}`" @click="selectModel(item, model)">
{{ item }}/{{ model }}
</a-menu-item>
</a-menu-item-group>
<a-menu-item-group v-if="customModels.length > 0" title="自定义模型">
<a-menu-item v-for="(model, idx) in customModels" :key="`custom-${idx}`" @click="selectModel('custom', model.custom_id)">
custom/{{ model.custom_id }}
</a-menu-item>
</a-menu-item-group>
</a-menu>
</template>
</a-dropdown>
</div> </div>
<div class="header__right"> <div class="header__right">
<div class="nav-btn text" @click="opts.showPanel = !opts.showPanel"> <div class="nav-btn text" @click="opts.showPanel = !opts.showPanel">
@ -165,7 +183,7 @@
</template> </template>
<script setup> <script setup>
import { reactive, ref, onMounted, toRefs, nextTick, onUnmounted, watch } from 'vue' import { reactive, ref, onMounted, toRefs, nextTick, onUnmounted, watch, computed } from 'vue'
import { import {
SendOutlined, SendOutlined,
MenuOutlined, MenuOutlined,
@ -185,7 +203,7 @@ import {
FolderOpenOutlined, FolderOpenOutlined,
GlobalOutlined, GlobalOutlined,
FileTextOutlined, FileTextOutlined,
RobotOutlined, BulbOutlined,
CaretRightOutlined, CaretRightOutlined,
DeploymentUnitOutlined, DeploymentUnitOutlined,
} from '@ant-design/icons-vue' } from '@ant-design/icons-vue'
@ -607,6 +625,22 @@ watch(
}, },
{ deep: true } { deep: true }
); );
const modelNames = computed(() => configStore.config?.model_names)
const modelStatus = computed(() => configStore.config?.model_provider_status)
const customModels = computed(() => configStore.config?.custom_models || [])
// modelStatus key
const modelKeys = computed(() => {
return Object.keys(modelStatus.value || {}).filter(key => modelStatus.value?.[key])
})
//
const selectModel = (provider, name) => {
configStore.setConfigValue('model_provider', provider)
configStore.setConfigValue('model_name', name)
message.success(`已切换到模型: ${provider}/${name}`)
}
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@ -649,9 +683,9 @@ watch(
border-radius: 8px; border-radius: 8px;
color: var(--gray-900); color: var(--gray-900);
cursor: pointer; cursor: pointer;
font-size: 1rem; // font-size: 1rem;
width: auto; width: auto;
padding: 0.5rem 1rem; padding: 0.5rem 0.75rem;
.text { .text {
margin-left: 10px; margin-left: 10px;
@ -662,6 +696,18 @@ watch(
} }
} }
.model-select {
// color: var(--gray-900);
max-width: 300px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
.text {
overflow: hidden;
text-overflow: ellipsis;
}
}
} }
.metas { .metas {
display: flex; display: flex;
@ -1109,6 +1155,29 @@ watch(
margin-right: 8px; margin-right: 8px;
} }
} }
.scrollable-menu {
max-height: 300px;
overflow-y: auto;
&::-webkit-scrollbar {
width: 6px;
}
&::-webkit-scrollbar-track {
background: transparent;
border-radius: 3px;
}
&::-webkit-scrollbar-thumb {
background: var(--gray-400);
border-radius: 3px;
}
&::-webkit-scrollbar-thumb:hover {
background: var(--gray-500);
}
}
</style> </style>
<style lang="less"> <style lang="less">
@ -1161,4 +1230,14 @@ watch(
} }
</style> </style>
<style lang="less">
// dropdown
.ant-dropdown-menu {
&.scrollable-menu {
max-height: 300px;
overflow-y: auto;
}
}
</style>

View File

@ -94,7 +94,7 @@
</div> </div>
<div class="setting" v-if="state.windowWidth <= 520 || state.section === 'model'"> <div class="setting" v-if="state.windowWidth <= 520 || state.section === 'model'">
<h3>模型配置</h3> <h3>模型配置</h3>
<p>请在 <code>src/.env</code> 文件中配置对应的 APIKEY</p> <p>请在 <code>src/.env</code> 文件中配置对应的 APIKEY并重新启动服务</p>
<div class="model-provider-card"> <div class="model-provider-card">
<div class="card-header"> <div class="card-header">
<h3>自定义模型</h3> <h3>自定义模型</h3>