- 用户域:注册/登录(JWT)/修改密码/个人资料 - 照片/衣橱/身形/化身:上传存储 + 3D 化身模板匹配 - 穿搭生成:天气(高德+和风+缓存) → 规则预筛 → LLM 规划(1次调用) → 规则评分(5维100分制) → 全低分触发 LLM 兜底创作 → 异步任务状态机 - 效果图:选主方案后异步生成 3 视角(mock/wanx 供应商 + 内容 hash 缓存 + 每日限额) - 商业化:合作门店列表(seed 4 家) - 冒烟:全链路端到端验证通过(mock LLM/天气),23 个 API 端点 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
// CandidateData 预筛候选服装(供 LLM 选择组合)
|
|
type CandidateData struct {
|
|
SetId int64 `json:"set_id"` // 所属预筛组合编号
|
|
ItemId int64 `json:"item_id"` // 衣橱条目 id
|
|
Category string `json:"category"`
|
|
Name string `json:"name"`
|
|
Color string `json:"color"`
|
|
Season string `json:"season"`
|
|
Style string `json:"style"`
|
|
}
|
|
|
|
// PlanOutfits 规则预筛候选 → LLM 润色规划(1 次调用)
|
|
func PlanOutfits(ctx context.Context, cfg *ModelConfig, sysPrompt, userInput string, candidates []CandidateData) (*PlanOutput, error) {
|
|
candJSON, err := json.Marshal(candidates)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("候选序列化失败: %w", err)
|
|
}
|
|
msg := userInput + "\n候选服装(JSON,set_id 表示第几套预选,请在同一套内选择):" + string(candJSON)
|
|
return callPlan(ctx, cfg, sysPrompt, msg)
|
|
}
|
|
|
|
// CreateRecommendPlan 兜底创作(全低分时调用,1 次调用)
|
|
func CreateRecommendPlan(ctx context.Context, cfg *ModelConfig, sysPrompt, userInput string) (*PlanOutput, error) {
|
|
return callPlan(ctx, cfg, sysPrompt, userInput)
|
|
}
|
|
|
|
func callPlan(ctx context.Context, cfg *ModelConfig, sysPrompt, userInput string) (*PlanOutput, error) {
|
|
req := &ChatRequest{
|
|
Messages: []*ChatMessage{
|
|
{Role: RoleSystem, Content: sysPrompt},
|
|
{Role: RoleUser, Content: userInput},
|
|
},
|
|
MaxTokens: cfg.MaxTokens,
|
|
Temperature: cfg.Temperature,
|
|
}
|
|
resp, err := CallChatModel(ctx, cfg, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out, err := ParsePlanOutput(resp.Content)
|
|
if err != nil {
|
|
g.Log().Warningf(ctx, "LLM 方案输出解析失败: %v\n原始输出: %s", err, resp.Content)
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|