feat: add system config item for dall e3 generate image num

This commit is contained in:
RockYang 2023-12-10 17:13:25 +08:00
parent 0da81a4d10
commit f19c15491e
3 changed files with 18 additions and 24 deletions

View File

@ -116,6 +116,7 @@ type ChatConfig struct {
EnableHistory bool `json:"enable_history"` // 是否允许保存聊天记录
ContextDeep int `json:"context_deep"` // 上下文深度
DallApiURL string `json:"dall_api_url"` // dall-e3 绘图 API 地址
DallImgNum int `json:"dall_img_num"` // dall-e3 出图数量
}
type Platform string

View File

@ -6,6 +6,7 @@ import (
"chatplus/store/model"
"chatplus/utils"
"fmt"
"github.com/imroc/req/v3"
"gorm.io/gorm"
)
@ -75,6 +76,14 @@ func (f FuncImage) Invoke(params map[string]interface{}) (string, error) {
return "", fmt.Errorf("error with decode chat config: %v", err)
}
apiURL := chatConfig.DallApiURL
if utils.IsEmptyValue(apiURL) {
apiURL = "https://api.openai.com/v1/images/generations"
}
imgNum := chatConfig.DallImgNum
if imgNum <= 0 {
imgNum = 1
}
var res imgRes
var errRes ErrRes
r, err := req.C().SetProxyURL(f.proxyURL).R().SetHeader("Content-Type", "application/json").
@ -82,11 +91,11 @@ func (f FuncImage) Invoke(params map[string]interface{}) (string, error) {
SetBody(imgReq{
Model: "dall-e-3",
Prompt: prompt,
N: 1,
N: imgNum,
Size: "1024x1024",
}).
SetErrorResult(&errRes).
SetSuccessResult(&res).Post(chatConfig.DallApiURL)
SetSuccessResult(&res).Post(apiURL)
if err != nil || r.IsErrorState() {
return "", fmt.Errorf("error with http request: %v%v%s", err, r.Err, errRes.Error.Message)
}

View File

@ -249,10 +249,13 @@
<el-input v-model.number="chat['xun_fei']['max_tokens']" placeholder="回复的最大字数最大4096"/>
</el-form-item>
<el-divider content-position="center">绘图绘图</el-divider>
<el-divider content-position="center">AI绘图</el-divider>
<el-form-item label="DALL-E3 API地址">
<el-input v-model="chat['dall_api_url']" placeholder="OpenAI官方API需要配合代理使用"/>
</el-form-item>
<el-form-item label="默认出图数量">
<el-input v-model.number="chat['dall_img_num']" placeholder="调用 DALL E3 API 传入的出图数量"/>
</el-form-item>
<el-form-item style="text-align: right">
<el-button type="primary" @click="save('chat')">保存</el-button>
</el-form-item>
@ -295,26 +298,7 @@ onMounted(() => {
//
httpGet('/api/admin/config/get?key=chat').then(res => {
// chat.value = res.data
if (res.data.open_ai) {
chat.value.open_ai = res.data.open_ai
}
if (res.data.azure) {
chat.value.azure = res.data.azure
}
if (res.data.chat_gml) {
chat.value.chat_gml = res.data.chat_gml
}
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
chat.value.dall_api_url = res.data.dall_api_url
chat.value = res.data
loading.value = false
}).catch(e => {
ElMessage.error("加载聊天配置失败: " + e.message)