chore: error handling if generated outline is not valid json
This commit is contained in:
parent
062adb6a0d
commit
d0fd1b3aed
3 changed files with 29 additions and 4 deletions
|
|
@ -68,7 +68,15 @@ async def stream_outlines(
|
|||
).to_string()
|
||||
presentation_outlines_text += chunk
|
||||
|
||||
presentation_outlines_json = json.loads(presentation_outlines_text)
|
||||
try:
|
||||
presentation_outlines_json = json.loads(presentation_outlines_text)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Failed to generate presentation outlines. Please try again.",
|
||||
)
|
||||
|
||||
presentation_outlines = PresentationOutlineModel(
|
||||
**presentation_outlines_json
|
||||
)
|
||||
|
|
|
|||
|
|
@ -355,7 +355,14 @@ async def generate_presentation_api(
|
|||
):
|
||||
presentation_outlines_text += chunk
|
||||
|
||||
presentation_outlines_json = json.loads(presentation_outlines_text)
|
||||
try:
|
||||
presentation_outlines_json = json.loads(presentation_outlines_text)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Failed to generate presentation outlines. Please try again.",
|
||||
)
|
||||
presentation_outlines = PresentationOutlineModel(**presentation_outlines_json)
|
||||
outlines = presentation_outlines.slides[:n_slides]
|
||||
total_outlines = len(outlines)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
from fastapi import HTTPException
|
||||
from typing import Dict, Any, Optional, List, Annotated
|
||||
from models.presentation_outline_model import PresentationOutlineModel
|
||||
from utils.llm_calls.generate_presentation_outlines import generate_ppt_outline
|
||||
|
|
@ -63,8 +64,17 @@ async def generate_outline(
|
|||
await asyncio.sleep(0)
|
||||
presentation_outlines_text += chunk
|
||||
|
||||
presentation_outlines_json = json.loads(presentation_outlines_text)
|
||||
presentation_outlines = PresentationOutlineModel(**presentation_outlines_json)
|
||||
try:
|
||||
presentation_outlines_json = json.loads(presentation_outlines_text)
|
||||
presentation_outlines = PresentationOutlineModel(
|
||||
**presentation_outlines_json
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Failed to generate presentation outlines. Please try again.",
|
||||
)
|
||||
|
||||
# Truncate slides to n_slides
|
||||
presentation_outlines.slides = presentation_outlines.slides[:n_slides]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue