feat: add system configration for enable/disable funciton in chat session

This commit is contained in:
RockYang 2023-10-11 14:35:47 +08:00
parent ba206bb387
commit 287fac3a89
3 changed files with 55 additions and 12 deletions

View File

@ -113,7 +113,8 @@ type SystemConfig struct {
InitImgCalls int `json:"init_img_calls"`
VipMonthCalls int `json:"vip_month_calls"` // 会员每个赠送的调用次数
EnabledRegister bool `json:"enabled_register"`
EnabledMsg bool `json:"enabled_msg"` // 启用短信验证码服务
EnabledDraw bool `json:"enabled_draw"` // 启动 AI 绘画功能
RewardImg string `json:"reward_img"` // 众筹收款二维码地址
EnabledMsg bool `json:"enabled_msg"` // 启用短信验证码服务
EnabledDraw bool `json:"enabled_draw"` // 启动 AI 绘画功能
RewardImg string `json:"reward_img"` // 众筹收款二维码地址
EnabledFunction bool `json:"enabled_function"` // 启用 API 函数功能
}

View File

@ -203,14 +203,16 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
req.Temperature = h.App.ChatConfig.OpenAI.Temperature
req.MaxTokens = h.App.ChatConfig.OpenAI.MaxTokens
// OpenAI 支持函数功能
var functions = make([]types.Function, 0)
for _, f := range types.InnerFunctions {
if !h.App.SysConfig.EnabledDraw && f.Name == types.FuncMidJourney {
continue
if h.App.SysConfig.EnabledFunction {
var functions = make([]types.Function, 0)
for _, f := range types.InnerFunctions {
if !h.App.SysConfig.EnabledDraw && f.Name == types.FuncMidJourney {
continue
}
functions = append(functions, f)
}
functions = append(functions, f)
req.Functions = functions
}
req.Functions = functions
default:
utils.ReplyMessage(ws, "不支持的平台:"+session.Model.Platform+",请联系管理员!")
utils.ReplyMessage(ws, "![](/images/wx.png)")

View File

@ -18,12 +18,46 @@
<el-form-item label="开放注册服务" prop="enabled_register">
<el-switch v-model="system['enabled_register']"/>
</el-form-item>
<el-form-item label="短信验证服务" prop="enabled_msg">
<el-form-item label="短信服务" prop="enabled_msg">
<el-switch v-model="system['enabled_msg']"/>
<el-tooltip
effect="dark"
content="是否在注册时候开启短信验证码服务"
raw-content
placement="right"
>
<el-icon>
<InfoFilled/>
</el-icon>
</el-tooltip>
</el-form-item>
<el-form-item label="开放AI绘画" prop="enabled_draw">
<el-form-item label="启用函数功能" prop="enabled_function">
<el-switch v-model="system['enabled_function']"/>
<el-tooltip
effect="dark"
content="是否在AI对话时启用函数功能"
raw-content
placement="right"
>
<el-icon>
<InfoFilled/>
</el-icon>
</el-tooltip>
</el-form-item>
<el-form-item label="启用AI绘画" prop="enabled_draw">
<el-switch v-model="system['enabled_draw']"/>
<el-tooltip
effect="dark"
content="需要开启函数功能此配置才会生效"
raw-content
placement="right"
>
<el-icon>
<InfoFilled/>
</el-icon>
</el-tooltip>
</el-form-item>
<el-form-item label="收款二维码" prop="reward_img">
<el-input v-model="system['reward_img']" placeholder="众筹收款二维码地址">
<template #append>
@ -122,7 +156,7 @@ import {onMounted, reactive, ref} from "vue";
import {httpGet, httpPost} from "@/utils/http";
import Compressor from "compressorjs";
import {ElMessage} from "element-plus";
import {UploadFilled} from "@element-plus/icons-vue";
import {InfoFilled, UploadFilled} from "@element-plus/icons-vue";
const system = ref({models: []})
const chat = ref({
@ -250,6 +284,12 @@ const uploadRewardImg = (file) => {
line-height 1.5;
}
.el-icon {
font-size 16px
margin-left 10px
cursor pointer
}
.uploader-icon {
font-size 24px
position relative