fixed bug for dalle prompt translate

This commit is contained in:
RockYang 2024-05-27 11:42:14 +08:00
parent e18e5a38c6
commit 02faff461a
3 changed files with 8 additions and 4 deletions

View File

@ -126,7 +126,7 @@ func (s *Service) Image(task types.DallTask, sync bool) (string, error) {
// get image generation API KEY // get image generation API KEY
var apiKey model.ApiKey var apiKey model.ApiKey
tx := s.db.Where("platform", types.OpenAI). tx := s.db.Where("platform", types.OpenAI.Value).
Where("type", "img"). Where("type", "img").
Where("enabled", true). Where("enabled", true).
Order("last_used_at ASC").First(&apiKey) Order("last_used_at ASC").First(&apiKey)
@ -162,11 +162,14 @@ func (s *Service) Image(task types.DallTask, sync bool) (string, error) {
// update the api key last use time // update the api key last use time
s.db.Model(&apiKey).UpdateColumn("last_used_at", time.Now().Unix()) s.db.Model(&apiKey).UpdateColumn("last_used_at", time.Now().Unix())
// update task progress // update task progress
s.db.Model(&model.DallJob{Id: task.JobId}).UpdateColumns(map[string]interface{}{ tx = s.db.Model(&model.DallJob{Id: task.JobId}).UpdateColumns(map[string]interface{}{
"progress": 100, "progress": 100,
"org_url": res.Data[0].Url, "org_url": res.Data[0].Url,
"prompt": prompt, "prompt": prompt,
}) })
if tx.Error != nil {
return "", fmt.Errorf("err with update database: %v", tx.Error)
}
s.notifyQueue.RPush(sd.NotifyMessage{UserId: int(task.UserId), JobId: int(task.JobId), Message: sd.Finished}) s.notifyQueue.RPush(sd.NotifyMessage{UserId: int(task.UserId), JobId: int(task.JobId), Message: sd.Finished})
var content string var content string

View File

@ -54,7 +54,7 @@ type apiErrRes struct {
func OpenAIRequest(db *gorm.DB, prompt string) (string, error) { func OpenAIRequest(db *gorm.DB, prompt string) (string, error) {
var apiKey model.ApiKey var apiKey model.ApiKey
res := db.Where("platform = ?", types.OpenAI).Where("type = ?", "chat").Where("enabled = ?", true).First(&apiKey) res := db.Where("platform = ?", types.OpenAI.Value).Where("type", "chat").Where("enabled = ?", true).First(&apiKey)
if res.Error != nil { if res.Error != nil {
return "", fmt.Errorf("error with fetch OpenAI API KEY%v", res.Error) return "", fmt.Errorf("error with fetch OpenAI API KEY%v", res.Error)
} }

View File

@ -0,0 +1 @@
ALTER TABLE `chatgpt_dall_jobs` CHANGE `org_url` `org_url` VARCHAR(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '原图地址';