mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
feat: add system config item for dall e3 generate image num
This commit is contained in:
parent
024c0032eb
commit
91ed41b536
@ -116,6 +116,7 @@ type ChatConfig struct {
|
|||||||
EnableHistory bool `json:"enable_history"` // 是否允许保存聊天记录
|
EnableHistory bool `json:"enable_history"` // 是否允许保存聊天记录
|
||||||
ContextDeep int `json:"context_deep"` // 上下文深度
|
ContextDeep int `json:"context_deep"` // 上下文深度
|
||||||
DallApiURL string `json:"dall_api_url"` // dall-e3 绘图 API 地址
|
DallApiURL string `json:"dall_api_url"` // dall-e3 绘图 API 地址
|
||||||
|
DallImgNum int `json:"dall_img_num"` // dall-e3 出图数量
|
||||||
}
|
}
|
||||||
|
|
||||||
type Platform string
|
type Platform string
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"chatplus/store/model"
|
"chatplus/store/model"
|
||||||
"chatplus/utils"
|
"chatplus/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/imroc/req/v3"
|
"github.com/imroc/req/v3"
|
||||||
"gorm.io/gorm"
|
"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)
|
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 res imgRes
|
||||||
var errRes ErrRes
|
var errRes ErrRes
|
||||||
r, err := req.C().SetProxyURL(f.proxyURL).R().SetHeader("Content-Type", "application/json").
|
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{
|
SetBody(imgReq{
|
||||||
Model: "dall-e-3",
|
Model: "dall-e-3",
|
||||||
Prompt: prompt,
|
Prompt: prompt,
|
||||||
N: 1,
|
N: imgNum,
|
||||||
Size: "1024x1024",
|
Size: "1024x1024",
|
||||||
}).
|
}).
|
||||||
SetErrorResult(&errRes).
|
SetErrorResult(&errRes).
|
||||||
SetSuccessResult(&res).Post(chatConfig.DallApiURL)
|
SetSuccessResult(&res).Post(apiURL)
|
||||||
if err != nil || r.IsErrorState() {
|
if err != nil || r.IsErrorState() {
|
||||||
return "", fmt.Errorf("error with http request: %v%v%s", err, r.Err, errRes.Error.Message)
|
return "", fmt.Errorf("error with http request: %v%v%s", err, r.Err, errRes.Error.Message)
|
||||||
}
|
}
|
||||||
|
@ -249,10 +249,13 @@
|
|||||||
<el-input v-model.number="chat['xun_fei']['max_tokens']" placeholder="回复的最大字数,最大4096"/>
|
<el-input v-model.number="chat['xun_fei']['max_tokens']" placeholder="回复的最大字数,最大4096"/>
|
||||||
</el-form-item>
|
</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-form-item label="DALL-E3 API地址">
|
||||||
<el-input v-model="chat['dall_api_url']" placeholder="OpenAI官方API需要配合代理使用"/>
|
<el-input v-model="chat['dall_api_url']" placeholder="OpenAI官方API需要配合代理使用"/>
|
||||||
</el-form-item>
|
</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-form-item style="text-align: right">
|
||||||
<el-button type="primary" @click="save('chat')">保存</el-button>
|
<el-button type="primary" @click="save('chat')">保存</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -295,26 +298,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
// 加载聊天配置
|
// 加载聊天配置
|
||||||
httpGet('/api/admin/config/get?key=chat').then(res => {
|
httpGet('/api/admin/config/get?key=chat').then(res => {
|
||||||
// chat.value = res.data
|
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
|
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("加载聊天配置失败: " + e.message)
|
ElMessage.error("加载聊天配置失败: " + e.message)
|
||||||
|
Loading…
Reference in New Issue
Block a user