This commit is contained in:
2026-07-10 13:15:56 +08:00
parent 5aed3e72de
commit 2d99bda915
3 changed files with 66 additions and 32 deletions
+31 -1
View File
@@ -2,6 +2,8 @@ package dao
import (
"context"
"encoding/json"
"video-factory/shortdrama/consts/public"
"video-factory/shortdrama/model/entity"
@@ -73,7 +75,13 @@ func (d *modelConfigDao) GetFirst(ctx context.Context) (res *entity.ModelConfig,
if r == nil {
return nil, nil
}
err = r.Struct(&res)
res = new(entity.ModelConfig)
if err := r.Struct(&res); err != nil {
return nil, err
}
// SQLite TEXT → *json.RawMessage 反序列化
res.ChatSchema = textToJSONPtr(r["chat_schema"].String())
res.VideoSchema = textToJSONPtr(r["video_schema"].String())
return
}
@@ -92,6 +100,9 @@ func (d *modelConfigDao) Save(ctx context.Context, data *entity.ModelConfig) err
delete(m, "id")
delete(m, "created_at")
delete(m, "updated_at")
// *json.RawMessage → SQLite TEXT 序列化
m["chat_schema"] = jsonPtrToText(data.ChatSchema)
m["video_schema"] = jsonPtrToText(data.VideoSchema)
_, err = g.DB().Model(public.TableNameModelConfig).Ctx(ctx).Data(m).Insert()
return err
}
@@ -108,3 +119,22 @@ func (d *modelConfigDao) UpdateField(ctx context.Context, field string, value in
_, err = g.DB().Model(public.TableNameModelConfig).Ctx(ctx).Data(g.Map{field: value}).Where("id", existing.Id).Update()
return err
}
// ==================== JSON 序列化/反序列化辅助 ====================
// textToJSONPtr 将 SQLite TEXT 转换为 *json.RawMessage
func textToJSONPtr(s string) *json.RawMessage {
if s == "" {
return nil
}
raw := json.RawMessage(s)
return &raw
}
// jsonPtrToText 将 *json.RawMessage 转换为 SQLite TEXT
func jsonPtrToText(j *json.RawMessage) string {
if j == nil {
return ""
}
return string(*j)
}
+16 -14
View File
@@ -1,6 +1,8 @@
package dto
import (
"encoding/json"
"video-factory/shortdrama/model/entity"
"github.com/gogf/gf/v2/frame/g"
@@ -16,18 +18,18 @@ type GetModelConfigRes struct {
type SaveModelConfigReq struct {
g.Meta `path:"/model" method:"post" tags:"模型配置" summary:"保存模型配置"`
ChatProvider string `json:"chatProvider" dc:"对话模型供应商(qwen/deepseek/doubao/glm/ernie/openai)"`
ChatApiKey string `v:"required" json:"chatApiKey" dc:"对话模型API密钥"`
ChatBaseUrl string `v:"required|url" json:"chatBaseUrl" dc:"对话模型API接口地址"`
ChatModelName string `v:"required" json:"chatModelName" dc:"对话模型名称"`
MaxTokens int `v:"required" json:"maxTokens" dc:"最大Token数"`
Temperature float64 `v:"required" json:"temperature" dc:"温度参数"`
ChatSchema string `json:"chatSchema" dc:"对话模型schema"`
VideoProvider string `json:"videoProvider" dc:"视频模型供应商(dashscope/kling/runway),空则自动检测"`
VideoApiKey string `v:"required" json:"videoApiKey" dc:"视频模型API密钥"`
VideoBaseUrl string `v:"required|url" json:"videoBaseUrl" dc:"视频模型API接口地址"`
VideoModelName string `v:"required" json:"videoModelName" dc:"视频模型名称"`
MaxSingleDuration int `v:"required" json:"maxSingleDuration" dc:"单段最大时长"`
MinSingleDuration int `v:"required" json:"minSingleDuration" dc:"单段最小时长"`
VideoSchema string `json:"videoSchema" dc:"视频生成模型schema"`
ChatProvider string `json:"chatProvider" dc:"对话模型供应商(qwen/deepseek/doubao/glm/ernie/openai)"`
ChatApiKey string `v:"required" json:"chatApiKey" dc:"对话模型API密钥"`
ChatBaseUrl string `v:"required|url" json:"chatBaseUrl" dc:"对话模型API接口地址"`
ChatModelName string `v:"required" json:"chatModelName" dc:"对话模型名称"`
MaxTokens int `v:"required" json:"maxTokens" dc:"最大Token数"`
Temperature float64 `v:"required" json:"temperature" dc:"温度参数"`
ChatSchema *json.RawMessage `json:"chatSchema" dc:"对话模型schema"`
VideoProvider string `json:"videoProvider" dc:"视频模型供应商(dashscope/kling/runway),空则自动检测"`
VideoApiKey string `v:"required" json:"videoApiKey" dc:"视频模型API密钥"`
VideoBaseUrl string `v:"required|url" json:"videoBaseUrl" dc:"视频模型API接口地址"`
VideoModelName string `v:"required" json:"videoModelName" dc:"视频模型名称"`
MaxSingleDuration int `v:"required" json:"maxSingleDuration" dc:"单段最大时长"`
MinSingleDuration int `v:"required" json:"minSingleDuration" dc:"单段最小时长"`
VideoSchema *json.RawMessage `json:"videoSchema" dc:"视频生成模型schema"`
}
+19 -17
View File
@@ -1,25 +1,27 @@
package entity
import (
"encoding/json"
"github.com/gogf/gf/v2/os/gtime"
)
type ModelConfig struct {
Id int64 `orm:"id" json:"id" dc:"配置ID"`
ChatProvider string `orm:"chat_provider" json:"chatProvider" dc:"对话模型供应商(qwen/deepseek/doubao/glm/ernie/openai)"`
ChatApiKey string `orm:"chat_api_key" json:"chatApiKey" dc:"对话模型API密钥"`
ChatBaseUrl string `orm:"chat_base_url" json:"chatBaseUrl" dc:"对话模型接口地址"`
ChatModelName string `orm:"chat_model_name" json:"chatModelName" dc:"对话模型名称"`
MaxTokens int `orm:"max_tokens" json:"maxTokens" dc:"最大Token数"`
Temperature float64 `orm:"temperature" json:"temperature" dc:"温度参数"`
ChatSchema string `orm:"chat_schema" json:"chatSchema" dc:"对话模型schema(JSON格式)"`
VideoProvider string `orm:"video_provider" json:"videoProvider" dc:"视频模型供应商(dashscope/kling/runway)"`
VideoApiKey string `orm:"video_api_key" json:"videoApiKey" dc:"视频模型API密钥"`
VideoBaseUrl string `orm:"video_base_url" json:"videoBaseUrl" dc:"视频模型接口地址"`
VideoModelName string `orm:"video_model_name" json:"videoModelName" dc:"视频模型名称"`
MaxSingleDuration int `orm:"max_single_duration" json:"maxSingleDuration" dc:"单段最大时长"`
MinSingleDuration int `orm:"min_single_duration" json:"minSingleDuration" dc:"单段最小时长"`
VideoSchema string `orm:"video_schema" json:"videoSchema" dc:"视频生成模型schema(JSON格式)"`
CreatedAt *gtime.Time `orm:"created_at" json:"createdAt" dc:"创建时间"`
UpdatedAt *gtime.Time `orm:"updated_at" json:"updatedAt" dc:"更新时间"`
Id int64 `orm:"id" json:"id" dc:"配置ID"`
ChatProvider string `orm:"chat_provider" json:"chatProvider" dc:"对话模型供应商(qwen/deepseek/doubao/glm/ernie/openai)"`
ChatApiKey string `orm:"chat_api_key" json:"chatApiKey" dc:"对话模型API密钥"`
ChatBaseUrl string `orm:"chat_base_url" json:"chatBaseUrl" dc:"对话模型接口地址"`
ChatModelName string `orm:"chat_model_name" json:"chatModelName" dc:"对话模型名称"`
MaxTokens int `orm:"max_tokens" json:"maxTokens" dc:"最大Token数"`
Temperature float64 `orm:"temperature" json:"temperature" dc:"温度参数"`
ChatSchema *json.RawMessage `orm:"chat_schema" json:"chatSchema" dc:"对话模型schema"`
VideoProvider string `orm:"video_provider" json:"videoProvider" dc:"视频模型供应商(dashscope/kling/runway)"`
VideoApiKey string `orm:"video_api_key" json:"videoApiKey" dc:"视频模型API密钥"`
VideoBaseUrl string `orm:"video_base_url" json:"videoBaseUrl" dc:"视频模型接口地址"`
VideoModelName string `orm:"video_model_name" json:"videoModelName" dc:"视频模型名称"`
MaxSingleDuration int `orm:"max_single_duration" json:"maxSingleDuration" dc:"单段最大时长"`
MinSingleDuration int `orm:"min_single_duration" json:"minSingleDuration" dc:"单段最小时长"`
VideoSchema *json.RawMessage `orm:"video_schema" json:"videoSchema" dc:"视频生成模型schema"`
CreatedAt *gtime.Time `orm:"created_at" json:"createdAt" dc:"创建时间"`
UpdatedAt *gtime.Time `orm:"updated_at" json:"updatedAt" dc:"更新时间"`
}