From 24e4be019ae40246c60ef244204f7af470b9bf9d Mon Sep 17 00:00:00 2001 From: RockYang Date: Mon, 27 May 2024 11:42:14 +0800 Subject: [PATCH] fixed bug for dalle prompt translate --- api/service/dalle/service.go | 7 +++++-- api/utils/openai.go | 4 ++-- database/update-v4.0.8.sql | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 database/update-v4.0.8.sql diff --git a/api/service/dalle/service.go b/api/service/dalle/service.go index 3dfbe6c0..f3e813b2 100644 --- a/api/service/dalle/service.go +++ b/api/service/dalle/service.go @@ -126,7 +126,7 @@ func (s *Service) Image(task types.DallTask, sync bool) (string, error) { // get image generation API KEY var apiKey model.ApiKey - tx := s.db.Where("platform", types.OpenAI). + tx := s.db.Where("platform", types.OpenAI.Value). Where("type", "img"). Where("enabled", true). 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 s.db.Model(&apiKey).UpdateColumn("last_used_at", time.Now().Unix()) // 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, "org_url": res.Data[0].Url, "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}) var content string diff --git a/api/utils/openai.go b/api/utils/openai.go index 4fa3ee0f..86a976a5 100644 --- a/api/utils/openai.go +++ b/api/utils/openai.go @@ -54,7 +54,7 @@ type apiErrRes struct { func OpenAIRequest(db *gorm.DB, prompt string) (string, error) { 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 { return "", fmt.Errorf("error with fetch OpenAI API KEY:%v", res.Error) } @@ -90,4 +90,4 @@ func OpenAIRequest(db *gorm.DB, prompt string) (string, error) { db.Model(&apiKey).UpdateColumn("last_used_at", time.Now().Unix()) return response.Choices[0].Message.Content, nil -} \ No newline at end of file +} diff --git a/database/update-v4.0.8.sql b/database/update-v4.0.8.sql new file mode 100644 index 00000000..76c42f1a --- /dev/null +++ b/database/update-v4.0.8.sql @@ -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 '原图地址'; \ No newline at end of file