update: changed prompt and dropped turbopack

This commit is contained in:
Suraj Jha 2025-08-08 00:06:08 +05:45
parent 2facff5280
commit 464d27624f
5 changed files with 69 additions and 69 deletions

File diff suppressed because one or more lines are too long

View file

@ -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

View file

@ -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 = (

View file

@ -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",

View file

@ -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",