Simplify outline error handling
Keep asyncio import for future timeout implementation. Handle TimeoutError and other exceptions properly. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0a5e971bf7
commit
50b4f554d6
1 changed files with 28 additions and 39 deletions
|
|
@ -140,46 +140,35 @@ async def generate_ppt_outline(
|
|||
|
||||
client = LLMClient()
|
||||
|
||||
# Timeout for outline generation (prevents socket hang up)
|
||||
OUTLINE_TIMEOUT = int(os.getenv("OUTLINE_TIMEOUT_SECONDS", "120"))
|
||||
|
||||
try:
|
||||
# Wrap streaming in timeout to prevent indefinite hangs
|
||||
async def stream_with_timeout():
|
||||
try:
|
||||
async for chunk in client.stream_structured(
|
||||
model,
|
||||
get_messages(
|
||||
content,
|
||||
n_slides,
|
||||
language,
|
||||
additional_context,
|
||||
tone,
|
||||
verbosity,
|
||||
instructions,
|
||||
include_title_slide,
|
||||
brand_context,
|
||||
available_layouts,
|
||||
content_summary,
|
||||
),
|
||||
response_model.model_json_schema(),
|
||||
strict=True,
|
||||
tools=(
|
||||
[SearchWebTool]
|
||||
if (client.enable_web_grounding() and web_search)
|
||||
else None
|
||||
),
|
||||
):
|
||||
yield chunk
|
||||
except asyncio.TimeoutError:
|
||||
yield HTTPException(
|
||||
status_code=504,
|
||||
detail=f"Outline generation timed out after {OUTLINE_TIMEOUT}s. Please try again or reduce the number of slides."
|
||||
)
|
||||
except Exception as e:
|
||||
yield handle_llm_client_exceptions(e)
|
||||
|
||||
async for chunk in stream_with_timeout():
|
||||
async for chunk in client.stream_structured(
|
||||
model,
|
||||
get_messages(
|
||||
content,
|
||||
n_slides,
|
||||
language,
|
||||
additional_context,
|
||||
tone,
|
||||
verbosity,
|
||||
instructions,
|
||||
include_title_slide,
|
||||
brand_context,
|
||||
available_layouts,
|
||||
content_summary,
|
||||
),
|
||||
response_model.model_json_schema(),
|
||||
strict=True,
|
||||
tools=(
|
||||
[SearchWebTool]
|
||||
if (client.enable_web_grounding() and web_search)
|
||||
else None
|
||||
),
|
||||
):
|
||||
yield chunk
|
||||
except asyncio.TimeoutError:
|
||||
yield HTTPException(
|
||||
status_code=504,
|
||||
detail="Outline generation timed out. Please try again."
|
||||
)
|
||||
except Exception as e:
|
||||
yield handle_llm_client_exceptions(e)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue