fix(fastapi): /edit, /derive and /export endpoints
This commit is contained in:
parent
72d7814998
commit
cc78faea73
6 changed files with 25 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
import json
|
||||
import math
|
||||
import traceback
|
||||
import uuid
|
||||
import dirtyjson
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
|
|
@ -83,8 +84,11 @@ async def stream_outlines(
|
|||
presentation_outlines_text += chunk
|
||||
|
||||
try:
|
||||
presentation_outlines_json = dict(dirtyjson.loads(presentation_outlines_text))
|
||||
presentation_outlines_json = dict(
|
||||
dirtyjson.loads(presentation_outlines_text)
|
||||
)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Failed to generate presentation outlines. Please try again.",
|
||||
|
|
|
|||
|
|
@ -46,7 +46,10 @@ from utils.llm_calls.generate_presentation_structure import (
|
|||
from utils.llm_calls.generate_slide_content import (
|
||||
get_slide_content_from_type_and_outline,
|
||||
)
|
||||
from utils.ppt_utils import select_toc_or_list_slide_layout_index
|
||||
from utils.ppt_utils import (
|
||||
get_presentation_title_from_outlines,
|
||||
select_toc_or_list_slide_layout_index,
|
||||
)
|
||||
from utils.process_slides import (
|
||||
process_slide_add_placeholder_assets,
|
||||
process_slide_and_fetch_assets,
|
||||
|
|
@ -487,7 +490,9 @@ async def generate_presentation_api(
|
|||
presentation_outlines_text += chunk
|
||||
|
||||
try:
|
||||
presentation_outlines_json = dict(dirtyjson.loads(presentation_outlines_text))
|
||||
presentation_outlines_json = dict(
|
||||
dirtyjson.loads(presentation_outlines_text)
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise HTTPException(
|
||||
|
|
@ -576,6 +581,7 @@ async def generate_presentation_api(
|
|||
content=request.content,
|
||||
n_slides=request.n_slides,
|
||||
language=request.language,
|
||||
title=get_presentation_title_from_outlines(presentation_outlines),
|
||||
outlines=presentation_outlines.model_dump(),
|
||||
layout=layout_model.model_dump(),
|
||||
structure=presentation_structure.model_dump(),
|
||||
|
|
@ -677,7 +683,9 @@ async def edit_presentation_with_new_content(
|
|||
slides_to_delete = []
|
||||
for each_slide in slides:
|
||||
updated_content = None
|
||||
new_slide_data = list(filter(lambda x: x.index == each_slide.index, data.data))
|
||||
new_slide_data = list(
|
||||
filter(lambda x: x.index == each_slide.index, data.slides)
|
||||
)
|
||||
if new_slide_data:
|
||||
updated_content = deep_update(each_slide.content, new_slide_data[0].content)
|
||||
new_slides.append(
|
||||
|
|
@ -719,7 +727,9 @@ async def derive_presentation_from_existing_one(
|
|||
new_slides = []
|
||||
for each_slide in slides:
|
||||
updated_content = None
|
||||
new_slide_data = list(filter(lambda x: x.index == each_slide.index, data.data))
|
||||
new_slide_data = list(
|
||||
filter(lambda x: x.index == each_slide.index, data.slides)
|
||||
)
|
||||
if new_slide_data:
|
||||
updated_content = deep_update(each_slide.content, new_slide_data[0].content)
|
||||
new_slides.append(
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ class SlideContentUpdate(BaseModel):
|
|||
|
||||
class EditPresentationRequest(BaseModel):
|
||||
presentation_id: uuid.UUID
|
||||
data: List[SlideContentUpdate]
|
||||
slides: List[SlideContentUpdate]
|
||||
export_as: Literal["pptx", "pdf"] = "pptx"
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ async def export_presentation(
|
|||
async with session.post(
|
||||
"http://localhost/api/export-as-pdf",
|
||||
json={
|
||||
"id": presentation_id,
|
||||
"id": str(presentation_id),
|
||||
"title": sanitize_filename(title or str(uuid.uuid4())),
|
||||
},
|
||||
) as response:
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ from models.presentation_layout import PresentationLayoutModel
|
|||
from typing import List
|
||||
|
||||
async def get_layout_by_name(layout_name: str) -> PresentationLayoutModel:
|
||||
url = f"http://localhost/api/layout?group={layout_name}"
|
||||
url = f"http://localhost/api/template?group={layout_name}"
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as response:
|
||||
if response.status != 200:
|
||||
error_text = await response.text()
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"Layout '{layout_name}' not found: {error_text}"
|
||||
detail=f"Template '{layout_name}' not found: {error_text}"
|
||||
)
|
||||
layout_json = await response.json()
|
||||
# Parse the JSON into your Pydantic model
|
||||
|
|
|
|||
|
|
@ -41,12 +41,13 @@ export async function GET(request: Request) {
|
|||
});
|
||||
|
||||
await page.waitForSelector("[data-layouts]", { timeout: 300000 });
|
||||
await page.waitForSelector("[data-settings]", { timeout: 300000 });
|
||||
|
||||
const { dataLayouts, dataGroupSettings } = await page.$eval(
|
||||
"[data-layouts]",
|
||||
(el) => ({
|
||||
dataLayouts: el.getAttribute("data-layouts"),
|
||||
dataGroupSettings: el.getAttribute("data-group-settings"),
|
||||
dataGroupSettings: el.getAttribute("data-settings"),
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue