This commit is contained in:
2026-09-15 16:02:45 +08:00
parent 112c5f8e46
commit ade2453083
70 changed files with 1441 additions and 707 deletions
+13 -5
View File
@@ -30,9 +30,10 @@ type RecommendLLMResponse struct {
}
// GenerateOutfitRecommendation 调用混元生成今日穿搭推荐。
func (c *Client) GenerateOutfitRecommendation(ctx context.Context, zodiac string, fortune *FortuneItem, clothes []mysqlmodel.Clothes) (*RecommendLLMResponse, error) {
// scene 为用户自定义场景(前端 scene_type=2 时传入),为空表示由模型自行判断。
func (c *Client) GenerateOutfitRecommendation(ctx context.Context, zodiac string, fortune *FortuneItem, clothes []mysqlmodel.Clothes, scene string) (*RecommendLLMResponse, error) {
messages := []Message{
{Role: "user", Content: buildRecommendPrompt(zodiac, fortune, clothes)},
{Role: "user", Content: buildRecommendPrompt(zodiac, fortune, clothes, scene)},
}
responseFormat := &ResponseFormat{
@@ -67,9 +68,16 @@ func (c *Client) GenerateOutfitRecommendation(ctx context.Context, zodiac string
}
// buildRecommendPrompt 构造穿搭推荐 prompt。
func buildRecommendPrompt(zodiac string, fortune *FortuneItem, clothes []mysqlmodel.Clothes) string {
// scene 为用户自定义场景(已做注入清洗):非空时作为硬约束写入 prompt,并指示模型在 scene 字段回填;
// 为空时整段不出现,保持「由模型自行判断场景」的原行为。
func buildRecommendPrompt(zodiac string, fortune *FortuneItem, clothes []mysqlmodel.Clothes, scene string) string {
clothesText := FormatClothesInfo(clothes)
sceneSection := ""
if s := sanitizePromptField(scene); s != "" {
sceneSection = fmt.Sprintf("\n## 用户指定场景\n用户希望这套搭配用于「%s」,请优先围绕该场景挑选单品,并在 scene 字段回填该场景。\n", s)
}
return fmt.Sprintf(`你是一位专业的时尚搭配师。请根据用户今天的星座运势和衣橱中的衣物,为用户推荐一套今日穿搭。
## 用户信息
@@ -82,7 +90,7 @@ func buildRecommendPrompt(zodiac string, fortune *FortuneItem, clothes []mysqlmo
## 用户衣橱
%s
%s
## 搭配规则
1. 所有推荐单品必须严格选自用户衣橱,clothes_id 与 clothes_uuid 必须与衣橱中存在的衣物一一对应,不得虚构
2. 先识别衣橱中包含的有效品类,仅统计以下 6 类:上装、下装、连衣裙、外套、鞋、配饰:
@@ -113,7 +121,7 @@ func buildRecommendPrompt(zodiac string, fortune *FortuneItem, clothes []mysqlmo
- items 数组长度由衣橱中存在的品类数量决定,不存在的品类不写入数组
- clothes_id 必须为整数,且必须是衣橱中真实存在的 ID
- clothes_uuid 必须从「用户衣橱」信息中精确复制,且与 clothes_id 一一对应,严禁编造或改动 UUID`,
zodiac, fortune.Overall, fortune.Love, fortune.Work, fortune.Money, fortune.Description, clothesText)
zodiac, fortune.Overall, fortune.Love, fortune.Work, fortune.Money, fortune.Description, clothesText, sceneSection)
}
// buildRecommendSchema 构造 JSON Schema 要求大模型结构化输出。