mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-17 16:56:38 +08:00
feat: add image generation API URL in chat configurations
This commit is contained in:
parent
4d612c15af
commit
cf4dcc34ec
@ -109,6 +109,7 @@ type ChatConfig struct {
|
|||||||
EnableContext bool `json:"enable_context"` // 是否开启聊天上下文
|
EnableContext bool `json:"enable_context"` // 是否开启聊天上下文
|
||||||
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 地址
|
||||||
}
|
}
|
||||||
|
|
||||||
type Platform string
|
type Platform string
|
||||||
|
@ -136,7 +136,6 @@ func (h *ChatHandler) sendOpenAiMessage(
|
|||||||
params["user_id"] = userVo.Id
|
params["user_id"] = userVo.Id
|
||||||
params["role_id"] = role.Id
|
params["role_id"] = role.Id
|
||||||
params["chat_id"] = session.ChatId
|
params["chat_id"] = session.ChatId
|
||||||
params["icon"] = "/images/avatar/mid_journey.png"
|
|
||||||
params["session_id"] = session.SessionId
|
params["session_id"] = session.SessionId
|
||||||
}
|
}
|
||||||
data, err := f.Invoke(params)
|
data, err := f.Invoke(params)
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
|
|
||||||
type FuncImage struct {
|
type FuncImage struct {
|
||||||
name string
|
name string
|
||||||
apiURL string
|
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
uploadManager *oss.UploaderManager
|
uploadManager *oss.UploaderManager
|
||||||
proxyURL string
|
proxyURL string
|
||||||
@ -26,7 +25,6 @@ func NewImageFunc(db *gorm.DB, manager *oss.UploaderManager, config *types.AppCo
|
|||||||
name: "DALL-E3 绘画",
|
name: "DALL-E3 绘画",
|
||||||
uploadManager: manager,
|
uploadManager: manager,
|
||||||
proxyURL: config.ProxyURL,
|
proxyURL: config.ProxyURL,
|
||||||
apiURL: "https://api.openai.com/v1/images/generations",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,9 +55,26 @@ type ErrRes struct {
|
|||||||
func (f FuncImage) Invoke(params map[string]interface{}) (string, error) {
|
func (f FuncImage) Invoke(params map[string]interface{}) (string, error) {
|
||||||
logger.Infof("绘画参数:%+v", params)
|
logger.Infof("绘画参数:%+v", params)
|
||||||
prompt := utils.InterfaceToString(params["prompt"])
|
prompt := utils.InterfaceToString(params["prompt"])
|
||||||
// 获取绘图 API KEY
|
// get image generation API KEY
|
||||||
var apiKey model.ApiKey
|
var apiKey model.ApiKey
|
||||||
f.db.Where("platform = ? AND type = ?", types.OpenAI, "img").Order("last_used_at ASC").First(&apiKey)
|
tx := f.db.Where("platform = ? AND type = ?", types.OpenAI, "img").Order("last_used_at ASC").First(&apiKey)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return "", fmt.Errorf("error with get generation API KEY: %v", tx.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// get image generation api URL
|
||||||
|
var conf model.Config
|
||||||
|
var chatConfig types.ChatConfig
|
||||||
|
tx = f.db.Where("marker", "chat").First(&conf)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return "", fmt.Errorf("error with get chat configs: %v", tx.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := utils.JsonDecode(conf.Config, &chatConfig)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error with decode chat config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
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").
|
||||||
@ -71,7 +86,7 @@ func (f FuncImage) Invoke(params map[string]interface{}) (string, error) {
|
|||||||
Size: "1024x1024",
|
Size: "1024x1024",
|
||||||
}).
|
}).
|
||||||
SetErrorResult(&errRes).
|
SetErrorResult(&errRes).
|
||||||
SetSuccessResult(&res).Post(f.apiURL)
|
SetSuccessResult(&res).Post(chatConfig.DallApiURL)
|
||||||
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,6 +249,10 @@
|
|||||||
<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-form-item label="DALL-E3 API地址">
|
||||||
|
<el-input v-model="chat['dall_api_url']" placeholder="OpenAI官方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>
|
||||||
@ -274,6 +278,7 @@ const chat = ref({
|
|||||||
context_deep: 0,
|
context_deep: 0,
|
||||||
enable_context: true,
|
enable_context: true,
|
||||||
enable_history: true,
|
enable_history: true,
|
||||||
|
dall_api_url: "",
|
||||||
})
|
})
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const systemFormRef = ref(null)
|
const systemFormRef = ref(null)
|
||||||
@ -309,6 +314,7 @@ onMounted(() => {
|
|||||||
chat.value.context_deep = res.data.context_deep
|
chat.value.context_deep = res.data.context_deep
|
||||||
chat.value.enable_context = res.data.enable_context
|
chat.value.enable_context = res.data.enable_context
|
||||||
chat.value.enable_history = res.data.enable_history
|
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