Files
st/server/model/app/response/ai_preset.go

43 lines
1.2 KiB
Go

package response
import (
"encoding/json"
"git.echol.cn/loser/st/server/model/app"
"time"
)
// AIPresetResponse 预设响应
type AIPresetResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Content map[string]interface{} `json:"content"`
IsSystem bool `json:"isSystem"`
IsDefault bool `json:"isDefault"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// ToAIPresetResponse 转换为响应格式
func ToAIPresetResponse(preset *app.AIPreset) *AIPresetResponse {
content := make(map[string]interface{})
if preset.Config != nil && len(preset.Config) > 0 {
// 将 datatypes.JSON 转换为 map
if err := json.Unmarshal(preset.Config, &content); err != nil {
// 如果解析失败,返回空 map
content = make(map[string]interface{})
}
}
return &AIPresetResponse{
ID: preset.ID,
Name: preset.Name,
Type: preset.PresetType,
Content: content,
IsSystem: preset.IsSystem,
IsDefault: preset.IsDefault,
CreatedAt: preset.CreatedAt,
UpdatedAt: preset.UpdatedAt,
}
}