fix: harden request handling, pipeline containment, and startup boundaries
This commit is contained in:
parent
2cc33a721c
commit
3555256a02
18 changed files with 656 additions and 107 deletions
|
|
@ -5,6 +5,7 @@ from contextlib import asynccontextmanager
|
|||
from pathlib import Path
|
||||
|
||||
import httpx2
|
||||
import structlog
|
||||
from anthropic import AsyncAnthropic
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
|
@ -12,6 +13,7 @@ from fastapi.staticfiles import StaticFiles
|
|||
from app.adapters.anthropic.llm import AnthropicRecommender
|
||||
from app.adapters.spotify.auth import TokenSet, refresh_access_token
|
||||
from app.adapters.spotify.client import SpotifyClient
|
||||
from app.adapters.spotify.errors import SpotifyError
|
||||
from app.adapters.spotify.session import PendingLogins, SessionStore, SpotifySession
|
||||
from app.api.recommendations import router as recommendations_router
|
||||
from app.api.routes import router
|
||||
|
|
@ -44,7 +46,8 @@ def create_app(
|
|||
application.state.settings = active_settings
|
||||
application.state.seed_session_id = None
|
||||
anthropic_client = AsyncAnthropic(
|
||||
api_key=active_settings.anthropic_api_key or "unused-demo-key"
|
||||
api_key=active_settings.anthropic_api_key or "unused-demo-key",
|
||||
timeout=active_settings.llm_timeout_seconds,
|
||||
)
|
||||
application.state.anthropic = anthropic_client
|
||||
application.state.recommendation_pipeline = RecommendationPipeline(
|
||||
|
|
@ -60,11 +63,17 @@ def create_app(
|
|||
active_settings.app_mode is AppMode.LIVE
|
||||
and active_settings.spotify_seed_refresh_token
|
||||
):
|
||||
application.state.seed_session_id = await _install_seed_session(
|
||||
http,
|
||||
application.state.session_store,
|
||||
active_settings,
|
||||
)
|
||||
try:
|
||||
application.state.seed_session_id = await _install_seed_session(
|
||||
http,
|
||||
application.state.session_store,
|
||||
active_settings,
|
||||
)
|
||||
except (SpotifyError, ValueError) as error:
|
||||
structlog.get_logger().warning(
|
||||
"seed_session_install_failed",
|
||||
error_type=type(error).__name__,
|
||||
)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue