diff --git a/servers/fastapi/api/v1/ppt/endpoints/prompts.py b/servers/fastapi/api/v1/ppt/endpoints/prompts.py index 2fd20740..6f2985f0 100644 --- a/servers/fastapi/api/v1/ppt/endpoints/prompts.py +++ b/servers/fastapi/api/v1/ppt/endpoints/prompts.py @@ -22,6 +22,7 @@ Follow these rules strictly: - Replace brand icons with a circle of same size with "i" between. Generic icons like "email", "call", etc should remain same. - If there is a box/card enclosing a text, make it grow as well when the text grows, so that the text does not overflow the box/card. - Give out only HTML and Tailwind code. No other texts or explanations. +- Do not give entire HTML structure with head, body, etc. Just give the respective HTML and Tailwind code inside div with above classes. """ HTML_TO_REACT_SYSTEM_PROMPT = """ @@ -50,6 +51,7 @@ Convert given static HTML and Tailwind slide to a TSX React component so that it 13. Do not parse the slideData inside dynamicSlideLayout, just use it as it is. Do not use statements like `Schema.parse() ` anywhere. Instead directly use the data without validating or parsing. 14. Always complete the reference, do not give "slideData .? .cards" instead give "slideData?.cards". 15. Do not add anything other than code. Do not add "use client", "json", "typescript", "javascript" and other prefix or suffix, just give out code exactly formatted like example. +16. In schema, give default for all fields irrespective of their types, give defualt values for array and objects as well. For example: Input:

Effects of Global Warming

global warming effects on earth

Global warming triggers a cascade of effects on our planet. These changes impact everything from our oceans to our ecosystems.

sea level rising icon

Rising Sea Levels

Rising sea levels threaten coastal communities and ecosystems due to melting glaciers and thermal expansion.

heatwave icon

Intense Heatwaves

Heatwaves are becoming more frequent and intense, posing significant risks to human health and agriculture.

precipitation changes icon

Changes in Precipitation

Altered precipitation patterns lead to increased droughts in some regions and severe flooding in others, affecting water resources.

diff --git a/servers/fastapi/api/v1/ppt/endpoints/slide_to_html.py b/servers/fastapi/api/v1/ppt/endpoints/slide_to_html.py index a75d967b..5e09179d 100644 --- a/servers/fastapi/api/v1/ppt/endpoints/slide_to_html.py +++ b/servers/fastapi/api/v1/ppt/endpoints/slide_to_html.py @@ -189,7 +189,7 @@ async def generate_html_from_slide(base64_image: str, media_type: str, xml_conte ) -async def generate_react_component_from_html(html_content: str, api_key: str, retry_times: int = 1) -> str: +async def generate_react_component_from_html(html_content: str, api_key: str) -> str: """ Convert HTML content to TSX React component using Google Gen AI API. @@ -203,13 +203,7 @@ async def generate_react_component_from_html(html_content: str, api_key: str, re Raises: HTTPException: If API call fails or no content is generated """ - if retry_times > 2: - raise HTTPException( - status_code=500, - detail="Google Gen AI API error during React generation" - ) - - if True: + try: # Initialize Google Gen AI client client = genai.Client(api_key=api_key) @@ -243,11 +237,12 @@ async def generate_react_component_from_html(html_content: str, api_key: str, re print(f"Received React content length: {len(react_content)}") if not react_content: - return await generate_react_component_from_html(html_content, api_key, retry_times + 1) + raise HTTPException( + status_code=500, + detail="No React component generated by Google Gen AI API" + ) - react_content = react_content.replace("```tsx", "")\ - .replace("```", "").replace("typescript", "")\ - .replace("javascript", "") + react_content = react_content.replace("```tsx", "").replace("```", "").replace("typescript", "").replace("javascript", "") # Filter out lines that start with import or export @@ -261,32 +256,32 @@ async def generate_react_component_from_html(html_content: str, api_key: str, re print(f"Filtered React content length: {len(filtered_react_content)}") return filtered_react_content - # except errors.APIError as e: - # print(f"Google API Error: {e}") - # raise HTTPException( - # status_code=500, - # detail=f"Google API error during React generation: {str(e)}" - # ) - # except Exception as e: - # # Handle various API errors - # error_msg = str(e) - # print(f"Exception occurred: {error_msg}") - # print(f"Exception type: {type(e)}") - # if "timeout" in error_msg.lower(): - # raise HTTPException( - # status_code=408, - # detail=f"Google Gen AI API timeout during React generation: {error_msg}" - # ) - # elif "connection" in error_msg.lower(): - # raise HTTPException( - # status_code=503, - # detail=f"Google Gen AI API connection error during React generation: {error_msg}" - # ) - # else: - # raise HTTPException( - # status_code=500, - # detail=f"Google Gen AI API error during React generation: {error_msg}" - # ) + except errors.APIError as e: + print(f"Google API Error: {e}") + raise HTTPException( + status_code=500, + detail=f"Google API error during React generation: {str(e)}" + ) + except Exception as e: + # Handle various API errors + error_msg = str(e) + print(f"Exception occurred: {error_msg}") + print(f"Exception type: {type(e)}") + if "timeout" in error_msg.lower(): + raise HTTPException( + status_code=408, + detail=f"Google Gen AI API timeout during React generation: {error_msg}" + ) + elif "connection" in error_msg.lower(): + raise HTTPException( + status_code=503, + detail=f"Google Gen AI API connection error during React generation: {error_msg}" + ) + else: + raise HTTPException( + status_code=500, + detail=f"Google Gen AI API error during React generation: {error_msg}" + ) async def edit_html_with_images(current_ui_base64: str, sketch_base64: Optional[str], media_type: str, html_content: str, prompt: str, api_key: str) -> str: @@ -497,7 +492,7 @@ async def convert_html_to_react(request: HtmlToReactRequest): Returns: HtmlToReactResponse with generated React component """ - if True: + try: # Get Google Gen AI API key from environment api_key = os.getenv("GOOGLE_API_KEY") if not api_key: @@ -527,16 +522,16 @@ async def convert_html_to_react(request: HtmlToReactRequest): message="React component generated successfully" ) - # except HTTPException: - # # Re-raise HTTP exceptions as-is - # raise - # except Exception as e: - # # Log the full error for debugging - # print(f"Unexpected error during HTML to React processing: {str(e)}") - # raise HTTPException( - # status_code=500, - # detail=f"Error processing HTML to React: {str(e)}" - # ) + except HTTPException: + # Re-raise HTTP exceptions as-is + raise + except Exception as e: + # Log the full error for debugging + print(f"Unexpected error during HTML to React processing: {str(e)}") + raise HTTPException( + status_code=500, + detail=f"Error processing HTML to React: {str(e)}" + ) # ENDPOINT 3: HTML editing with images diff --git a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts index db2a2dd2..b28fe3ca 100644 --- a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts +++ b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts @@ -6,10 +6,6 @@ import { setStreaming, } from "@/store/slices/presentationGeneration"; import { jsonrepair } from "jsonrepair"; -<<<<<<< HEAD -import { RootState } from "@/store/store"; -======= ->>>>>>> main import { toast } from "sonner"; export const usePresentationStreaming = ( diff --git a/servers/nextjs/package-lock.json b/servers/nextjs/package-lock.json index a4cfdac8..158baf51 100644 --- a/servers/nextjs/package-lock.json +++ b/servers/nextjs/package-lock.json @@ -49,8 +49,8 @@ "next-themes": "^0.4.6", "prismjs": "^1.30.0", "puppeteer": "^24.13.0", - "react": "19.1.0", - "react-dom": "19.1.0", + "react": "^18.3.1", + "react-dom": "^18.3.1", "react-redux": "^9.1.2", "react-simple-code-editor": "^0.14.1", "recharts": "^2.15.4", @@ -8038,24 +8038,28 @@ "license": "MIT" }, "node_modules/react": { - "version": "19.1.0", - "resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz", - "integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==", + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", "license": "MIT", + "dependencies": { + "loose-envify": "^1.1.0" + }, "engines": { "node": ">=0.10.0" } }, "node_modules/react-dom": { - "version": "19.1.0", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.1.0.tgz", - "integrity": "sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g==", + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", "license": "MIT", "dependencies": { - "scheduler": "^0.26.0" + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" }, "peerDependencies": { - "react": "^19.1.0" + "react": "^18.3.1" } }, "node_modules/react-is": { @@ -8441,10 +8445,13 @@ "license": "MIT" }, "node_modules/scheduler": { - "version": "0.26.0", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.26.0.tgz", - "integrity": "sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA==", - "license": "MIT" + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.1.0" + } }, "node_modules/semver": { "version": "7.7.2", diff --git a/servers/nextjs/package.json b/servers/nextjs/package.json index 7db96e39..7554780c 100644 --- a/servers/nextjs/package.json +++ b/servers/nextjs/package.json @@ -51,8 +51,8 @@ "next-themes": "^0.4.6", "prismjs": "^1.30.0", "puppeteer": "^24.13.0", - "react": "19.1.0", - "react-dom": "19.1.0", + "react": "^18.3.1", + "react-dom": "^18.3.1", "react-redux": "^9.1.2", "react-simple-code-editor": "^0.14.1", "recharts": "^2.15.4",