diff --git a/api/src/main.py b/api/src/main.py index ae7297b..47672f5 100644 --- a/api/src/main.py +++ b/api/src/main.py @@ -111,11 +111,8 @@ def get_audiocast_endpoint(session_id: str): @app.post("/generate-audiocast-source", response_model=str) -async def generate_audiocast_source_endpoint( - request: GenerateAudiocastSource, - background_tasks: BackgroundTasks, -): - source_content = await generate_audiocast_source(request, background_tasks) +async def generate_audiocast_source_endpoint(request: GenerateAudiocastSource): + source_content = await generate_audiocast_source(request) if not source_content: raise HTTPException(status_code=500, detail="Failed to generate source content") return source_content diff --git a/api/src/utils/audiocast_utils.py b/api/src/utils/audiocast_utils.py index 97b6326..089611c 100644 --- a/api/src/utils/audiocast_utils.py +++ b/api/src/utils/audiocast_utils.py @@ -1,8 +1,8 @@ -from typing import List, TypedDict +from typing import TypedDict from pydantic import BaseModel -from src.utils.chat_utils import ContentCategory, SessionChatItem +from src.utils.chat_utils import ContentCategory class GenerateAudioCastRequest(BaseModel): @@ -14,9 +14,6 @@ class GenerateAudioCastRequest(BaseModel): class GenerateAudioCastResponse(BaseModel): script: str source_content: str - chats: List[SessionChatItem] - category: ContentCategory - title: str | None created_at: str | None diff --git a/api/src/utils/generate_audiocast.py b/api/src/utils/generate_audiocast.py index 6c1b02e..62a3575 100644 --- a/api/src/utils/generate_audiocast.py +++ b/api/src/utils/generate_audiocast.py @@ -60,7 +60,20 @@ async def generate_audiocast(request: GenerateAudioCastRequest, background_tasks db = SessionManager(session_id, category) def update_session_info(info: str): - background_tasks.add_task(db._update_info, info) + db._update_info(info) + + session_data = SessionManager.data(session_id) + source_content = session_data.metadata.source if session_data and session_data.metadata else None + + if not source_content: + update_session_info("Generating source content...") + source_content = await generate_audiocast_source( + GenerateAudiocastSource( + sessionId=session_id, + category=category, + preferenceSummary=summary, + ), + ) session_data = SessionManager.data(session_id) source_content = session_data.metadata.source if session_data and session_data.metadata else None @@ -73,7 +86,6 @@ def update_session_info(info: str): category=category, preferenceSummary=summary, ), - background_tasks, ) if not source_content: @@ -104,20 +116,8 @@ def update_session_info(info: str): audio_script, ) - session_data = SessionManager.data(session_id) - if not session_data: - raise HTTPException( - status_code=404, - detail=f"Failed to get audiocast from the DB for session_id: {session_id}", - ) - - title = session_data.metadata.title if session_data.metadata and session_data.metadata.title else "Untitled" - return GenerateAudioCastResponse( script=audio_script, source_content=source_content, created_at=datetime.now().strftime("%Y-%m-%d %H:%M"), - chats=session_data.chats, - title=title, - category=session_data.category, ) diff --git a/api/src/utils/generate_audiocast_source.py b/api/src/utils/generate_audiocast_source.py index c80df70..3372fbf 100644 --- a/api/src/utils/generate_audiocast_source.py +++ b/api/src/utils/generate_audiocast_source.py @@ -1,4 +1,3 @@ -from fastapi import BackgroundTasks from pydantic import BaseModel from src.utils.audiocast_request import GenerateSourceContent @@ -14,7 +13,7 @@ class GenerateAudiocastSource(BaseModel): preferenceSummary: str -async def generate_audiocast_source(request: GenerateAudiocastSource, background_tasks: BackgroundTasks): +async def generate_audiocast_source(request: GenerateAudiocastSource): """ Generate audiocast source material based on user preferences. """ @@ -28,11 +27,10 @@ async def generate_audiocast_source(request: GenerateAudiocastSource, background @use_cache_manager(cache_key) async def _handler(): db = SessionManager(session_id, category) - background_tasks.add_task(db._update_info, "Generating source content...") - + db._update_info("Generating source content...") generator = GenerateSourceContent(category, preference_summary) source_content = await generator._run() - background_tasks.add_task(db._update_source, source_content) + db._update_source(source_content) return source_content diff --git a/api/src/utils/get_audiocast.py b/api/src/utils/get_audiocast.py index 3bb96b1..f26601c 100644 --- a/api/src/utils/get_audiocast.py +++ b/api/src/utils/get_audiocast.py @@ -35,11 +35,4 @@ def get_audiocast(session_id: str): if session_data.created_at: created_at = datetime.fromisoformat(session_data.created_at).strftime("%Y-%m-%d %H:%M") - return GenerateAudioCastResponse( - script=transcript, - source_content=source, - created_at=created_at, - chats=session_data.chats, - title=title, - category=session_data.category, - ) + return GenerateAudioCastResponse(script=transcript, source_content=source, created_at=created_at) diff --git a/app/src/lib/components/AudiocastPageHeader.svelte b/app/src/lib/components/AudiocastPageHeader.svelte new file mode 100644 index 0000000..80a4348 --- /dev/null +++ b/app/src/lib/components/AudiocastPageHeader.svelte @@ -0,0 +1,16 @@ + + +
- Generating your audiocast...Please wait -
++ Generating your audiocast...Please wait +
+ + {#if sessionModel?.metadata?.info} ++ Status: {sessionModel.metadata.info} +
+ {/if} +