feat: add key-free demo mode replaying recorded fixtures
This commit is contained in:
parent
0664cc2d27
commit
401a0ddea7
21 changed files with 1040 additions and 31 deletions
|
|
@ -1,4 +1,4 @@
|
|||
"""Authenticated recommendation streaming and playlist creation routes."""
|
||||
"""Recommendation streaming and playlist creation routes."""
|
||||
|
||||
import asyncio
|
||||
from collections.abc import AsyncIterator, Callable
|
||||
|
|
@ -38,6 +38,10 @@ from app.pipeline.orchestrator import RecommendationPipeline
|
|||
from app.ports.protocols import MusicCatalog, PlaylistWriter
|
||||
|
||||
SpotifyClientFactory = Callable[[SpotifySession], MusicCatalog | PlaylistWriter]
|
||||
MusicCatalogFactory = Callable[
|
||||
[SpotifySession, str, tuple[PreviousRecommendation, ...]],
|
||||
MusicCatalog,
|
||||
]
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
|
@ -47,14 +51,12 @@ async def recommendations(
|
|||
request: Request,
|
||||
payload: RecommendationRequest,
|
||||
) -> StreamingResponse:
|
||||
"""Stream one authenticated discovery response as NDJSON."""
|
||||
"""Stream one session-resolved discovery response as NDJSON."""
|
||||
resolved = resolve_session(request)
|
||||
if resolved is None:
|
||||
raise HTTPException(status_code=401, detail="Not authenticated")
|
||||
|
||||
pipeline = cast(RecommendationPipeline, request.app.state.recommendation_pipeline)
|
||||
factory = cast(SpotifyClientFactory, request.app.state.spotify_client_factory)
|
||||
catalog = cast(MusicCatalog, factory(resolved.session))
|
||||
request_id = cast(str, request.state.request_id)
|
||||
history = tuple(ConversationTurn(turn.role, turn.content) for turn in payload.history)
|
||||
previous = tuple(
|
||||
|
|
@ -66,6 +68,8 @@ async def recommendations(
|
|||
)
|
||||
for item in payload.prior_recommendations
|
||||
)
|
||||
factory = cast(MusicCatalogFactory, request.app.state.music_catalog_factory)
|
||||
catalog = factory(resolved.session, payload.query, previous)
|
||||
|
||||
return StreamingResponse(
|
||||
_stream_lines(
|
||||
|
|
@ -86,7 +90,7 @@ async def create_playlist(
|
|||
request: Request,
|
||||
payload: PlaylistCreateRequest,
|
||||
) -> PlaylistCreateResponse:
|
||||
"""Create and fill one authenticated Spotify playlist."""
|
||||
"""Create and fill one live or simulated playlist."""
|
||||
resolved = resolve_session(request)
|
||||
if resolved is None:
|
||||
raise HTTPException(status_code=401, detail="Not authenticated")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue