加入「拾绪」:心情说说 + 小拾 AI 评论
- 新增 moments 应用:Moment / MomentImage / MomentComment 及迁移 - 7 种心情、文字 + 最多 4 张图片、心情筛选 - 发布时调用本地 Ollama,以「小拾」人设自动评论 - 支持「让小拾再说一句」,每条最多 6 条 AI 回应 - 写操作复用拾匣密码;首页新增「拾绪」入口 - explore/llm.py 增加通用 chat_text 与超时参数
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import re
|
||||
|
||||
from explore.llm import LLMBadResponse, chat_text
|
||||
|
||||
PERSONA_NAME = "小拾"
|
||||
MAX_AI_COMMENTS = 6
|
||||
|
||||
SYSTEM_PROMPT = """你是「小拾」,一个温暖、敏锐、偶尔有点俏皮的朋友。你的朋友在记录此刻的心情。
|
||||
请针对这条说说,写一句像朋友一样的评论,20-60 个汉字:
|
||||
- 先接住对方的情绪,再给一点自己的感受,或者轻轻开个玩笑
|
||||
- 像微信里说话,口语化
|
||||
- 不要总结、不要说教、不要鸡汤套话
|
||||
- 不要自称 AI,不要写“我理解你的感受”这种空话
|
||||
- 不要编造说说里没有的具体事实,不要替对方补充细节
|
||||
- 不要加引号、不要换行、不要用括号写动作
|
||||
如果下面有你说过的话,请换一个角度,不要重复。"""
|
||||
|
||||
|
||||
def _clean_comment(text):
|
||||
text = (text or "").strip()
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
lines = [line.strip() for line in text.splitlines() if line.strip()]
|
||||
text = lines[0] if lines else ""
|
||||
|
||||
text = re.sub(r"^(?:[-*•]|\d+[.、])\s*", "", text)
|
||||
text = re.sub(r"^(小拾|AI)\s*[::]\s*", "", text)
|
||||
text = text.strip().strip("\"'“”‘’")
|
||||
text = re.sub(r"[*_`#]+", "", text)
|
||||
text = re.sub(r"\s+", " ", text)
|
||||
return text[:160].strip()
|
||||
|
||||
|
||||
def generate_comment(moment, existing=None):
|
||||
"""为一条说说生成一句拟人化评论。"""
|
||||
lines = [
|
||||
"心情:{}".format(moment.mood_label),
|
||||
"说说:{}".format(moment.content),
|
||||
]
|
||||
|
||||
existing = list(existing or [])
|
||||
if existing:
|
||||
lines.append("你之前说过:")
|
||||
for comment in existing:
|
||||
lines.append("- " + comment.content)
|
||||
lines.append("请换一个角度,不要重复。")
|
||||
|
||||
raw = chat_text(
|
||||
SYSTEM_PROMPT,
|
||||
"\n".join(lines),
|
||||
temperature=0.85,
|
||||
num_predict=160,
|
||||
timeout=30,
|
||||
)
|
||||
comment = _clean_comment(raw)
|
||||
if not comment:
|
||||
raise LLMBadResponse("小拾没想好说什么,等会儿再试试")
|
||||
return comment
|
||||
Reference in New Issue
Block a user