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:
+19
-1
@@ -7,13 +7,31 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from app.core.config import CORS_ORIGINS
|
||||
from app.core.discord_bot import start_discord_bot
|
||||
from app.core.scheduler import start_scheduler
|
||||
from app.db.database import init_db
|
||||
from app.core.word_memory import seed_from_history
|
||||
from app.db.database import SessionLocal, init_db
|
||||
from app.db.models import Message
|
||||
from app.api import chat, memory, logs, system
|
||||
|
||||
|
||||
def _seed_word_memory_from_db() -> None:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
rows = (
|
||||
db.query(Message.content)
|
||||
.filter(Message.role.in_(["user", "assistant"]))
|
||||
.order_by(Message.created_at.desc())
|
||||
.limit(200)
|
||||
.all()
|
||||
)
|
||||
seed_from_history([content for (content,) in rows])
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
init_db()
|
||||
_seed_word_memory_from_db()
|
||||
start_scheduler()
|
||||
asyncio.create_task(start_discord_bot())
|
||||
yield
|
||||
|
||||
Reference in New Issue
Block a user