Add web search knowledge base, message tagging, and word-memory tip topics
Introduces websearch.py (Tavily) + knowledge.py to ground chat responses in search results, tagging.py to tag user and assistant messages via LLM and pick related topics for the Discord useless-tips job, and word_memory.py to track recent conversation nouns (surfaced in the new WordPool.vue sidebar) used to pick tip topics close to a related tag.
This commit is contained in:
@@ -23,6 +23,7 @@ from app.core.llm import complete
|
||||
from app.core.notify import send_discord_message
|
||||
from app.core.weather import fetch_tomorrow_weather, judge_laundry
|
||||
from app.core.weather_cache import set_latest
|
||||
from app.core.word_memory import pick_random_word
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -77,7 +78,12 @@ async def _generate_message(weather: str, pop_text: str, judgement: str, reason:
|
||||
return fallback
|
||||
|
||||
|
||||
async def send_useless_tip() -> None:
|
||||
async def send_useless_tip(topic_override: str | None = None) -> None:
|
||||
"""どうでもいいtipsをDiscordへ送信する。
|
||||
|
||||
topic_overrideを渡すと、ワードプールのランダム単語より優先してそのトピックでネタを作る。
|
||||
雑談Botがタグベースで『近しい話題』を渡したいときに使う。
|
||||
"""
|
||||
if not DISCORD_WEBHOOK_URL_TIPS:
|
||||
logger.warning("DISCORD_WEBHOOK_URL_TIPS is not set; skipping useless tip")
|
||||
return
|
||||
@@ -86,19 +92,31 @@ async def send_useless_tip() -> None:
|
||||
logger.info("Skipping useless tip during 3am quiet hour")
|
||||
return
|
||||
|
||||
topic_word = topic_override or pick_random_word()
|
||||
|
||||
prompt = (
|
||||
"誰の役にも立たない、死ぬほどどうでもいい雑学・豆知識を一つ教えてください。\n"
|
||||
"- 1〜3文程度で簡潔に\n"
|
||||
"- 「どうでもいい」感が伝わるようなノリで\n"
|
||||
"あなたは『どうでもいいTips』という名前のDiscord Botです。"
|
||||
"あなた自身は、これから話す雑学が誰かの役に立つ、有益な豆知識だと心の底から信じ切っています。"
|
||||
"本人にその自覚は一切なく、本気の善意と謎の使命感で「これは知っておいた方がいい」と思って共有しています。\n\n"
|
||||
"実際の内容は、誰の役にも立たない、死ぬほどどうでもいい雑学・豆知識にしてください。\n"
|
||||
"- 全体で60文字以内(絵文字含む)に必ず収める。1文の短いつぶやきでよい\n"
|
||||
"- 「これは役に立ちますよ」「知っておくと得しますよ」というような、善意・自信たっぷりの前置きや一言を添える\n"
|
||||
"- ただし中身は本当にどうでもいい内容にする(このギャップが面白さのポイント)\n"
|
||||
"- 「どや顔」「これ豆な」的な、ちょっと得意げなノリにする\n"
|
||||
"- 絵文字を1つくらい添えてもよい\n"
|
||||
"- 出力は本文のみ(前置き・説明不要)\n"
|
||||
"- 出力は本文のみ(メタな説明やこの指示の繰り返しは不要)\n"
|
||||
"- 過去に何度も言われていそうな定番ネタは避け、できるだけ意外性のある内容にする"
|
||||
)
|
||||
if topic_word:
|
||||
prompt += (
|
||||
f"\n- 雑談Botでの会話に出てきた「{topic_word}」という話題に、こじつけでもいいので"
|
||||
"何らかの形でネタを絡めてください(無関係でも強引に繋げてOK)"
|
||||
)
|
||||
|
||||
try:
|
||||
messages = [{"role": "user", "content": prompt}]
|
||||
tip = await complete(messages, model=USELESS_TIPS_MODEL)
|
||||
content = f"🤷 **どうでもいいtips**\n{tip.strip()}"
|
||||
content = f"💡 **今日のお役立ち情報**\n{tip.strip()}"
|
||||
await send_discord_message(DISCORD_WEBHOOK_URL_TIPS, content)
|
||||
except Exception:
|
||||
logger.exception("Failed to send useless tip")
|
||||
|
||||
Reference in New Issue
Block a user