加入「拾绪」:心情说说 + 小拾 AI 评论

- 新增 moments 应用:Moment / MomentImage / MomentComment 及迁移
- 7 种心情、文字 + 最多 4 张图片、心情筛选
- 发布时调用本地 Ollama,以「小拾」人设自动评论
- 支持「让小拾再说一句」,每条最多 6 条 AI 回应
- 写操作复用拾匣密码;首页新增「拾绪」入口
- explore/llm.py 增加通用 chat_text 与超时参数
This commit is contained in:
2026-11-21 12:29:33 +08:00
parent d9c58d4866
commit d0f921ed27
18 changed files with 1596 additions and 5 deletions
+23 -2
View File
@@ -111,7 +111,7 @@ class LLMBadResponse(LLMError):
super().__init__(message)
def _post_chat(payload):
def _post_chat(payload, timeout=None):
url = settings.OLLAMA_BASE_URL + "/api/chat"
request = urllib.request.Request(
url,
@@ -121,7 +121,9 @@ def _post_chat(payload):
)
try:
with urllib.request.urlopen(request, timeout=settings.OLLAMA_TIMEOUT) as response:
with urllib.request.urlopen(
request, timeout=timeout or settings.OLLAMA_TIMEOUT
) as response:
raw = response.read()
except urllib.error.HTTPError as exc:
detail = exc.read().decode("utf-8", "replace")[:300]
@@ -405,6 +407,25 @@ def analyze_repos(repos):
return result
def chat_text(system, user, temperature=0.8, num_predict=200, timeout=30):
"""通用纯文本对话(不做 JSON 约束),给「拾绪」的 AI 评论用。"""
payload = {
"model": settings.OLLAMA_MODEL,
"messages": [
{"role": "system", "content": system},
{"role": "user", "content": user},
],
"stream": False,
"options": {"temperature": temperature, "num_predict": num_predict},
}
if not getattr(settings, "OLLAMA_THINK", False):
payload["think"] = False
data = _post_chat(payload, timeout=timeout)
message = data.get("message") or {}
return (message.get("content") or data.get("response") or "").strip()
def extract_spec(idea):
"""调模型 -> 结构化条件 -> 拼 GitHub 检索式。"""
started = time.monotonic()