49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"video-factory/shortdrama/model/dto"
|
|
"video-factory/shortdrama/model/entity"
|
|
"video-factory/shortdrama/service"
|
|
)
|
|
|
|
type config struct{}
|
|
|
|
var Config = new(config)
|
|
|
|
func (c *config) Get(ctx context.Context, req *dto.GetModelConfigReq) (res *dto.GetModelConfigRes, err error) {
|
|
cfg := service.ConfigService.Get(ctx)
|
|
return &dto.GetModelConfigRes{ModelConfig: cfg}, nil
|
|
}
|
|
|
|
func (c *config) Save(ctx context.Context, req *dto.SaveModelConfigReq) (res *struct{}, err error) {
|
|
if req.MinSingleDuration < 1 {
|
|
return nil, fmt.Errorf("单次生成最小时长必须大于等于1")
|
|
}
|
|
if req.MaxSingleDuration < 1 {
|
|
return nil, fmt.Errorf("单次生成最大时长必须大于等于1")
|
|
}
|
|
if req.MinSingleDuration > req.MaxSingleDuration {
|
|
return nil, fmt.Errorf("单次生成最小时长不能大于最大时长")
|
|
}
|
|
cfg := &entity.ModelConfig{
|
|
ChatProvider: req.ChatProvider,
|
|
ChatApiKey: req.ChatApiKey,
|
|
ChatBaseUrl: req.ChatBaseUrl,
|
|
ChatModelName: req.ChatModelName,
|
|
MaxTokens: req.MaxTokens,
|
|
Temperature: req.Temperature,
|
|
ChatSchema: req.ChatSchema,
|
|
VideoProvider: req.VideoProvider,
|
|
VideoApiKey: req.VideoApiKey,
|
|
VideoBaseUrl: req.VideoBaseUrl,
|
|
VideoModelName: req.VideoModelName,
|
|
MinSingleDuration: req.MinSingleDuration,
|
|
MaxSingleDuration: req.MaxSingleDuration,
|
|
VideoSchema: req.VideoSchema,
|
|
}
|
|
return nil, service.ConfigService.Save(ctx, cfg)
|
|
}
|