fix: fixed bug for mj service pool config pointer

This commit is contained in:
RockYang
2023-12-15 22:52:57 +08:00
parent 58f3dd5336
commit 3bea8f9706
8 changed files with 77 additions and 53 deletions

View File

@@ -3,18 +3,19 @@ package mj
import (
"chatplus/core/types"
"fmt"
"github.com/imroc/req/v3"
"time"
"github.com/imroc/req/v3"
)
// MidJourney client
type Client struct {
client *req.Client
config *types.MidJourneyConfig
config types.MidJourneyConfig
}
func NewClient(config *types.MidJourneyConfig, proxy string) *Client {
func NewClient(config types.MidJourneyConfig, proxy string) *Client {
client := req.C().SetTimeout(10 * time.Second)
// set proxy URL
if proxy != "" {

View File

@@ -5,6 +5,7 @@ import (
"chatplus/service/oss"
"chatplus/store"
"fmt"
"github.com/go-redis/redis/v8"
"gorm.io/gorm"
)
@@ -24,7 +25,7 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa
continue
}
// create mj client
client := NewClient(&config, appConfig.ProxyURL)
client := NewClient(config, appConfig.ProxyURL)
name := fmt.Sprintf("MjService-%d", k)
// create mj service

View File

@@ -5,6 +5,7 @@ import (
"chatplus/service/oss"
"chatplus/store"
"fmt"
"github.com/go-redis/redis/v8"
"gorm.io/gorm"
)
@@ -25,7 +26,7 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa
// create sd service
name := fmt.Sprintf("StableDifffusion Service-%d", k)
service := NewService(name, 4, 600, &config, queue, db, manager)
service := NewService(name, 4, 600, config, queue, db, manager)
// run sd service
go func() {
service.Run()

View File

@@ -8,20 +8,21 @@ import (
"chatplus/utils"
"encoding/json"
"fmt"
"github.com/imroc/req/v3"
"gorm.io/gorm"
"io"
"os"
"strconv"
"sync/atomic"
"time"
"github.com/imroc/req/v3"
"gorm.io/gorm"
)
// SD 绘画服务
type Service struct {
httpClient *req.Client
config *types.StableDiffusionConfig
config types.StableDiffusionConfig
taskQueue *store.RedisQueue
db *gorm.DB
uploadManager *oss.UploaderManager
@@ -32,7 +33,7 @@ type Service struct {
taskTimeout int64
}
func NewService(name string, maxTaskNum int32, timeout int64, config *types.StableDiffusionConfig, queue *store.RedisQueue, db *gorm.DB, manager *oss.UploaderManager) *Service {
func NewService(name string, maxTaskNum int32, timeout int64, config types.StableDiffusionConfig, queue *store.RedisQueue, db *gorm.DB, manager *oss.UploaderManager) *Service {
return &Service{
name: name,
config: config,

View File

@@ -33,13 +33,13 @@ var ParamKeys = map[string]int{
"steps": 4,
"sampler": 5,
"face_fix": 6, // 面部修复
"cfg_scale": 8,
"seed": 27,
"height": 9,
"width": 10,
"hd_fix": 11,
"hd_redraw_rate": 12, //高清修复重绘幅度
"hd_scale": 13, // 高清修复放大倍数
"hd_scale_alg": 14, // 高清修复放大算法
"hd_sample_num": 15, // 高清修复采样次数
"cfg_scale": 10,
"seed": 11,
"height": 17,
"width": 18,
"hd_fix": 19,
"hd_redraw_rate": 20, //高清修复重绘幅度
"hd_scale": 21, // 高清修复放大倍数
"hd_scale_alg": 22, // 高清修复放大算法
"hd_sample_num": 23, // 高清修复采样次数
}