feat: allow chat model bind a fixed api key

This commit is contained in:
RockYang
2024-04-12 17:09:22 +08:00
parent 3b292c2a12
commit 0a01b55713
22 changed files with 183 additions and 84 deletions

View File

@@ -63,7 +63,8 @@ const logo = ref('/images/logo.png')
// 加载系统配置
httpGet('/api/admin/config/get?key=system').then(res => {
title.value = res.data['admin_title'];
title.value = res.data['admin_title']
logo.value = res.data['logo']
}).catch(e => {
ElMessage.error("加载系统配置失败: " + e.message)
})
@@ -191,9 +192,9 @@ setMenuItems(items)
padding 6px 15px;
.el-image {
width 30px;
height 30px;
padding-top 8px;
width 36px;
height 36px;
padding-top 5px;
border-radius 100%
.el-image__inner {

View File

@@ -377,16 +377,7 @@ const initData = () => {
httpGet(`/api/role/list`).then((res) => {
roles.value = res.data;
roleId.value = roles.value[0]['id'];
const chatId = localStorage.getItem("chat_id")
const chat = getChatById(chatId)
if (chat === null) {
// 创建新的对话
newChat();
} else {
// 加载对话
loadChat(chat)
}
newChat();
}).catch((e) => {
ElMessage.error('获取聊天角色失败: ' + e.messages)
})

View File

@@ -2,7 +2,7 @@
<div class="home">
<div class="navigator">
<div class="logo">
<el-image :src="logo"/>
<el-image :src="logo" @click="router.push('/')"/>
<div class="divider"></div>
</div>
<ul class="nav-items">
@@ -75,6 +75,7 @@ onMounted(() => {
display flex
flex-flow column
align-items center
cursor pointer
.el-image {
width 50px

View File

@@ -1,7 +1,7 @@
<template>
<div class="index-page" :style="{height: winHeight+'px'}">
<div class="content">
<h1>{{title}}</h1>
<h1>欢迎使用 {{ title }}</h1>
<p>{{slogan}}</p>
<button class="btn" @click="router.push('/chat')">立即使用</button>
@@ -20,15 +20,22 @@ import * as THREE from 'three';
import {onMounted, ref} from "vue";
import {useRouter} from "vue-router";
import FooterBar from "@/components/FooterBar.vue";
import {httpGet} from "@/utils/http";
import {ElMessage} from "element-plus";
const router = useRouter()
const title = ref("欢迎使用 Geek-AI 创作系统")
const title = ref("Geek-AI 创作系统")
const slogan = ref("我辈之人,先干为敬,陪您先把 AI 用起来")
const size = window.innerHeight * 0.8
const winHeight = window.innerHeight - 150
onMounted(() => {
httpGet("/api/config/get?key=system").then(res => {
title.value = res.data['title']
}).catch(e => {
ElMessage.error("获取系统配置失败:" + e.message)
})
init()
})
@@ -77,7 +84,7 @@ const init = () => {
requestAnimationFrame(animate);
// 使地球自转和公转
earth.rotation.y += 0.002;
earth.rotation.y += 0.001;
renderer.render(scene, camera);
};

View File

@@ -1,5 +1,5 @@
<template>
<div class="container list" v-loading="loading">
<div class="container model-list" v-loading="loading">
<div class="handle-box">
<el-button type="primary" :icon="Plus" @click="add">新增</el-button>
@@ -13,7 +13,14 @@
</template>
</el-table-column>
<el-table-column prop="name" label="模型名称"/>
<el-table-column prop="value" label="模型值"/>
<el-table-column prop="value" label="模型值">
<template #default="scope">
<span>{{ scope.row.value }}</span>
<el-icon class="copy-model" :data-clipboard-text="scope.row.value">
<DocumentCopy/>
</el-icon>
</template>
</el-table-column>
<el-table-column prop="power" label="费率"/>
<el-table-column prop="max_tokens" label="最大响应长度"/>
<el-table-column prop="max_context" label="最大上下文长度"/>
@@ -29,12 +36,12 @@
</template>
</el-table-column>
<el-table-column label="创建时间">
<template #default="scope">
<span>{{ dateFormat(scope.row['created_at']) }}</span>
</template>
</el-table-column>
<!-- <el-table-column label="创建时间">-->
<!-- <template #default="scope">-->
<!-- <span>{{ dateFormat(scope.row['created_at']) }}</span>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column prop="key_name" label="绑定API-KEY"/>
<el-table-column label="操作" width="180">
<template #default="scope">
<el-button size="small" type="primary" @click="edit(scope.row)">编辑</el-button>
@@ -75,7 +82,7 @@
<el-form-item label="费率" prop="weight">
<template #default>
<div class="tip-input">
<el-input-number :min="1" v-model="item.power" autocomplete="off"/>
<el-input-number :min="0" v-model="item.power" autocomplete="off"/>
<div class="info">
<el-tooltip
class="box-item"
@@ -144,6 +151,15 @@
</div>
</el-form-item>
<el-form-item label="绑定API-KEY" prop="apikey">
<el-select v-model="item.key_id" placeholder="请选择 API KEY">
<el-option v-for="v in apiKeys" :value="v.id" :label="v.name" :key="v.id">
{{ v.name }}
<el-text type="info" size="small">{{ substr(v.api_url, 50) }}</el-text>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="启用状态" prop="enable">
<el-switch v-model="item.enabled"/>
</el-form-item>
@@ -178,12 +194,13 @@
</template>
<script setup>
import {onMounted, reactive, ref} from "vue";
import {onMounted, onUnmounted, reactive, ref} from "vue";
import {httpGet, httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
import {dateFormat, removeArrayItem} from "@/utils/libs";
import {InfoFilled, Plus} from "@element-plus/icons-vue";
import {dateFormat, removeArrayItem, substr} from "@/utils/libs";
import {DocumentCopy, InfoFilled, Plus} from "@element-plus/icons-vue";
import {Sortable} from "sortablejs";
import ClipboardJS from "clipboard";
// 变量定义
const items = ref([])
@@ -207,23 +224,34 @@ const platforms = ref([
])
// 获取数据
httpGet('/api/admin/model/list').then((res) => {
if (res.data) {
// 初始化数据
const arr = res.data;
for (let i = 0; i < arr.length; i++) {
arr[i].last_used_at = dateFormat(arr[i].last_used_at)
}
items.value = arr
}
loading.value = false
}).catch(() => {
ElMessage.error("获取数据失败");
// 获取 API KEY
const apiKeys = ref([])
httpGet('/api/admin/apikey/list?status=true&type=chat').then(res => {
apiKeys.value = res.data
}).catch(e => {
ElMessage.error("获取 API KEY 失败" + e.message)
})
// 获取数据
const fetchData = () => {
httpGet('/api/admin/model/list').then((res) => {
if (res.data) {
// 初始化数据
const arr = res.data;
for (let i = 0; i < arr.length; i++) {
arr[i].last_used_at = dateFormat(arr[i].last_used_at)
}
items.value = arr
}
loading.value = false
}).catch(() => {
ElMessage.error("获取数据失败");
})
}
const clipboard = ref(null)
onMounted(() => {
fetchData()
const drawBodyWrapper = document.querySelector('.el-table__body tbody')
// 初始化拖动排序插件
@@ -250,6 +278,19 @@ onMounted(() => {
})
}
})
clipboard.value = new ClipboardJS('.copy-model');
clipboard.value.on('success', () => {
ElMessage.success('复制成功!');
})
clipboard.value.on('error', () => {
ElMessage.error('复制失败!');
})
})
onUnmounted(() => {
clipboard.value.destroy()
})
const add = function () {
@@ -267,14 +308,14 @@ const edit = function (row) {
const save = function () {
formRef.value.validate((valid) => {
item.value.temperature = parseFloat(item.value.temperature)
if (!item.value.sort_num) {
item.value.sort_num = items.value.length
}
if (valid) {
showDialog.value = false
httpPost('/api/admin/model/save', item.value).then((res) => {
ElMessage.success('操作成功!')
if (!item.value['id']) {
const newItem = res.data
items.value.push(newItem)
}
fetchData()
}).catch((e) => {
ElMessage.error('操作失败,' + e.message)
})
@@ -306,7 +347,7 @@ const remove = function (row) {
<style lang="stylus" scoped>
@import "@/assets/css/admin/form.styl";
.list {
.model-list {
.opt-box {
padding-bottom: 10px;
@@ -318,6 +359,13 @@ const remove = function (row) {
}
}
.cell {
.copy-model {
margin-left 6px
cursor pointer
}
}
.el-select {
width: 100%
}

View File

@@ -19,7 +19,7 @@ import {ref} from "vue";
import ImageMj from "@/views/mobile/ImageMj.vue";
import ImageSd from "@/views/mobile/ImageSd.vue";
const activeName = ref("sd")
const activeName = ref("mj")
</script>
<style lang="stylus">