feat: adjust package struct, put chat code the seperate 'chatimpl' package, fix bug: baidu api chat context number must be even number

This commit is contained in:
RockYang
2023-10-11 15:46:40 +08:00
parent 287fac3a89
commit 21c3a419a5
14 changed files with 402 additions and 91 deletions

View File

@@ -2,115 +2,137 @@ html,
body,
#app,
.wrapper {
width: 100%;
height: 100%;
overflow: hidden;
width: 100%;
height: 100%;
overflow: hidden;
}
body {
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
.admin-home a {
text-decoration: none;
text-decoration: none;
}
.admin-home .content-box {
position: absolute;
left: 250px;
right: 0;
top: 0;
bottom: 0;
padding-bottom: 30px;
-webkit-transition: left 0.3s ease-in-out;
transition: left 0.3s ease-in-out;
background: #f0f0f0;
position: absolute;
left: 250px;
right: 0;
top: 0;
bottom: 0;
/*padding-bottom: 30px;*/
-webkit-transition: left 0.3s ease-in-out;
transition: left 0.3s ease-in-out;
background: #f0f0f0;
overflow-y: scroll;
}
.admin-home .content-box .content {
width: auto;
height: 100%;
padding: 10px;
overflow-y: scroll;
box-sizing: border-box;
/*BaseForm*/
width: auto;
padding: 10px;
box-sizing: border-box;
/*BaseForm*/
}
.admin-home .content-box .content .container {
padding: 30px;
background: #fff;
border: 1px solid #ddd;
border-radius: 5px;
padding: 30px;
background: #fff;
border: 1px solid #ddd;
border-radius: 5px;
}
.admin-home .content-box .content .container .handle-box {
margin-bottom: 20px;
margin-bottom: 20px;
}
.admin-home .content-box .content .crumbs {
margin: 10px 0;
margin: 10px 0;
}
.admin-home .content-box .content .el-table th {
background-color: #f5f7fa !important;
background-color: #f5f7fa !important;
}
.admin-home .content-box .content .pagination {
margin: 20px 0;
display: flex;
justify-content: center;
width: 100%;
margin: 20px 0;
display: flex;
justify-content: center;
width: 100%;
}
.admin-home .content-box .content .plugins-tips {
padding: 20px 10px;
margin-bottom: 20px;
padding: 20px 10px;
margin-bottom: 20px;
}
.admin-home .content-box .content .el-button + .el-tooltip {
margin-left: 10px;
margin-left: 10px;
}
.admin-home .content-box .content .el-table tr:hover {
background: #f6faff;
background: #f6faff;
}
.admin-home .content-box .content .mgb20 {
margin-bottom: 20px;
margin-bottom: 20px;
}
.admin-home .content-box .content .move-enter-active,
.admin-home .content-box .content .move-leave-active {
transition: opacity 0.1s ease;
transition: opacity 0.1s ease;
}
.admin-home .content-box .content .move-enter-from,
.admin-home .content-box .content .move-leave-to {
opacity: 0;
opacity: 0;
}
.admin-home .content-box .content .form-box {
width: 600px;
width: 600px;
}
.admin-home .content-box .content .form-box .line {
text-align: center;
text-align: center;
}
.admin-home .content-box .content .el-time-panel__content::after,
.admin-home .content-box .content .el-time-panel__content::before {
margin-top: -7px;
margin-top: -7px;
}
.admin-home .content-box .content .el-time-spinner__wrapper .el-scrollbar__wrap:not(.el-scrollbar__wrap--hidden-default) {
padding-bottom: 0;
padding-bottom: 0;
}
.admin-home .content-box .content [class*=" el-icon-"],
.admin-home .content-box .content [class^=el-icon-] {
speak: none;
font-style: normal;
font-weight: 400;
font-variant: normal;
text-transform: none;
line-height: 1;
vertical-align: baseline;
display: inline-block;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
speak: none;
font-style: normal;
font-weight: 400;
font-variant: normal;
text-transform: none;
line-height: 1;
vertical-align: baseline;
display: inline-block;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.admin-home .content-box .content .el-sub-menu [class^=el-icon-] {
vertical-align: middle;
margin-right: 5px;
width: 24px;
text-align: center;
font-size: 18px;
vertical-align: middle;
margin-right: 5px;
width: 24px;
text-align: center;
font-size: 18px;
}
.admin-home .content-box .content [hidden] {
display: none !important;
display: none !important;
}
.admin-home .content-collapse {
left: 65px;
left: 65px;
}

View File

@@ -40,11 +40,14 @@
v-model="showDialog"
:title="title"
>
<el-alert title="注意如果是百度文心一言平台需要用竖线| API Key Secret Key 串接起来填入"
type="warning"
:closable="false"
show-icon
style="margin-bottom: 10px; font-size:14px;"/>
<el-alert
type="warning"
:closable="false"
show-icon
style="margin-bottom: 10px; font-size:14px;">
<p><b>注意:</b>如果是百度文心一言平台,需要用竖线(|)将 API Key 和 Secret Key 串接起来填入!</p>
<p><b>注意:</b>如果是讯飞星火大模型,需要用竖线(|)将 APPID, APIKey 和 APISecret 按照顺序串接起来填入!</p>
</el-alert>
<el-form :model="item" label-width="120px" ref="formRef" :rules="rules">
<el-form-item label="所属平台" prop="platform">
<el-select v-model="item.platform" placeholder="请选择平台">
@@ -87,10 +90,11 @@ const loading = ref(true)
const formRef = ref(null)
const title = ref("")
const platforms = ref([
{name: "OpenAIChatGPT", value: "OpenAI"},
{name: "讯飞星火大模型", value: "XunFei"},
{name: "清华智普ChatGLM", value: "ChatGLM"},
{name: "百度文心一言", value: "Baidu"},
{name: "微软Azure", value: "Azure"},
{name: "OpenAIChatGPT", value: "OpenAI"},
])
// 获取数据

View File

@@ -95,10 +95,11 @@ const rules = reactive({
const loading = ref(true)
const formRef = ref(null)
const platforms = ref([
{name: "OpenAIChatGPT", value: "OpenAI"},
{name: "讯飞星火大模型", value: "XunFei"},
{name: "清华智普ChatGLM", value: "ChatGLM"},
{name: "百度文心一言", value: "Baidu"},
{name: "微软Azure", value: "Azure"},
{name: "OpenAIChatGPT", value: "OpenAI"},
])
// 获取数据

View File

@@ -91,7 +91,7 @@
<el-input-number v-model="chat['context_deep']" :min="0" :max="10"/>
<div class="tip" style="margin-top: 10px;">会话上下文深度在老会话中继续会话默认加载多少条聊天记录作为上下文如果设置为
0
则不加载聊天记录仅仅使用当前角色的上下文该配置参数最好设置 2 的整数倍
则不加载聊天记录仅仅使用当前角色的上下文该配置参数最好设置需要为偶数否则将无法兼容百度的 API
</div>
</el-form-item>
@@ -143,6 +143,18 @@
<el-input v-model.number="chat['baidu']['max_tokens']" placeholder="回复的最大字数最大4096"/>
</el-form-item>
<el-divider content-position="center">讯飞星火</el-divider>
<el-form-item label="API 地址" prop="xun_fei.api_url">
<el-input v-model="chat['xun_fei']['api_url']" placeholder="支持变量,{model} => 模型名称"/>
</el-form-item>
<el-form-item label="模型创意度">
<el-slider v-model="chat['xun_fei']['temperature']" :max="1" :step="0.1"/>
<div class="tip">值越大 AI 回答越发散值越小回答越保守建议保持默认值</div>
</el-form-item>
<el-form-item label="最大响应长度">
<el-input v-model.number="chat['xun_fei']['max_tokens']" placeholder="回复的最大字数最大4096"/>
</el-form-item>
<el-form-item style="text-align: right">
<el-button type="primary" @click="save('chat')">保存</el-button>
</el-form-item>
@@ -164,6 +176,7 @@ const chat = ref({
azure: {api_url: "", temperature: 1, max_tokens: 1024},
chat_gml: {api_url: "", temperature: 0.95, max_tokens: 1024},
baidu: {api_url: "", temperature: 0.95, max_tokens: 1024},
xun_fei: {api_url: "", temperature: 0.5, max_tokens: 1024},
context_deep: 0,
enable_context: true,
enable_history: true,
@@ -195,6 +208,9 @@ onMounted(() => {
if (res.data.baidu) {
chat.value.baidu = res.data.baidu
}
if (res.data.xun_fei) {
chat.value.xun_fei = res.data.xun_fei
}
chat.value.context_deep = res.data.context_deep
chat.value.enable_context = res.data.enable_context
chat.value.enable_history = res.data.enable_history
@@ -210,9 +226,6 @@ const rules = reactive({
admin_title: [{required: true, message: '请输入控制台标题', trigger: 'blur',}],
user_init_calls: [{required: true, message: '请输入赠送对话次数', trigger: 'blur'}],
user_img_calls: [{required: true, message: '请输入赠送绘图次数', trigger: 'blur'}],
open_ai: {api_url: [{required: true, message: '请输入 API URL', trigger: 'blur'}]},
azure: {api_url: [{required: true, message: '请输入 API URL', trigger: 'blur'}]},
chat_gml: {api_url: [{required: true, message: '请输入 API URL', trigger: 'blur'}]},
})
const save = function (key) {
if (key === 'system') {
@@ -226,6 +239,9 @@ const save = function (key) {
}
})
} else if (key === 'chat') {
if (chat.value.context_deep % 2 !== 0) {
return ElMessage.error("会话上下文深度必须为偶数!")
}
chatFormRef.value.validate((valid) => {
if (valid) {
httpPost('/api/admin/config/update', {key: key, config: chat.value}).then(() => {