Files
hunli/hunliji-api/spark/blessing.go
2026-08-01 16:55:39 +08:00

51 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package spark
import (
"fmt"
"strings"
)
var BlessingStyles = map[string]string{
"classic": "古风典雅",
"modern": "现代文风",
"funny": "搞怪文风",
"roast": "损友文风",
}
func NormalizeStyle(style string) (string, bool) {
s := strings.TrimSpace(style)
_, ok := BlessingStyles[s]
return s, ok
}
func (c *Client) GenerateBlessing(name, style string) (string, error) {
styleKey, ok := NormalizeStyle(style)
if !ok {
return "", fmt.Errorf("无效的祝福风格")
}
label := BlessingStyles[styleKey]
guest := strings.TrimSpace(name)
guestHint := "宾客未署名"
if guest != "" {
guestHint = "宾客姓名:" + guest
}
styleGuide := map[string]string{
"classic": "用文言雅致、含蓄温润的古风表达,可适度用典故意象,忌生僻堆砌。",
"modern": "用简洁真诚的现代汉语,自然得体,适合婚礼现场朗读。",
"funny": "轻松幽默、俏皮可爱,但保持祝福善意,不低俗。",
"roast": "损友互怼口吻,先轻度调侃再真心祝福,尺度友好不人身攻击。",
}
sys := "你是婚礼祝福文案助手。只输出一条中文祝福正文,不要标题、不要解释、不要引号包裹。"
user := fmt.Sprintf(`请写一条婚礼祝福。
风格:%s(%s)
%s
要求:30到60个汉字;积极祝福新人;不要出现违法、色情、歧视或辱骂内容。`, label, styleGuide[styleKey], guestHint)
return c.Chat([]Message{
{Role: "system", Content: sys},
{Role: "user", Content: user},
})
}