Files
socaichat/backend/app/main.py
T
gongzhiyongandClaude Opus 4.6 3759ecd1a6 feat(backend): Phase 3 - Jina search + Redis cache
- Add web_search tool with Jina Search/Reader/Rerank
- Flash mode: top 3, 8s timeout, no Reader/Rerank
- Pro mode: top 10, 20s timeout, concurrent Reader + Rerank top 5
- Add Redis async cache (TTL=300s) for search results
- Register "search" in ALL_TOOLS mapping

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 13:39:43 +08:00

64 lines
1.5 KiB
Python

"""Litestar application entry point."""
from __future__ import annotations
from contextlib import asynccontextmanager
from collections.abc import AsyncGenerator
from dotenv import load_dotenv
# Load .env before anything else reads settings
load_dotenv()
from litestar import Litestar
from litestar.config.cors import CORSConfig
from app.api.chat import stream_chat
from app.api.conversations import (
create_conversation,
delete_conversation,
get_conversation,
list_conversations,
update_conversation,
)
from app.api.health import health_check
from app.api.tickets import get_ticket, list_tickets
from app.cache.redis import close_redis
from app.store.memory import close_checkpointer
from app.store.postgres import create_tables, dispose_engine
cors_config = CORSConfig(
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
allow_credentials=False,
)
@asynccontextmanager
async def lifespan(app: Litestar) -> AsyncGenerator[None, None]:
"""Application lifespan: create tables on startup, dispose engine on shutdown."""
await create_tables()
yield
await close_checkpointer()
await close_redis()
await dispose_engine()
app = Litestar(
route_handlers=[
health_check,
stream_chat,
list_conversations,
get_conversation,
create_conversation,
update_conversation,
delete_conversation,
list_tickets,
get_ticket,
],
cors_config=cors_config,
lifespan=[lifespan],
debug=False,
)