fix: reformatted for better conversion to react, add fonts to layout

This commit is contained in:
Suraj Jha 2025-08-01 22:53:22 +05:45
parent cd57b53348
commit 0413ee26d4
3 changed files with 25 additions and 26 deletions

File diff suppressed because one or more lines are too long

View file

@ -65,6 +65,7 @@ class LayoutData(BaseModel):
layout_id: str # Unique identifier for the layout
layout_name: str # Display name of the layout
layout_code: str # TSX/React component code for the layout
fonts: Optional[List[str]] = None # Optional list of font links
class SaveLayoutsRequest(BaseModel):
@ -365,7 +366,7 @@ async def generate_react_component_from_html(html_content: str, api_key: str) ->
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=20000,
max_tokens=64000,
temperature=1,
system=HTML_TO_REACT_SYSTEM_PROMPT,
messages=[
@ -381,7 +382,7 @@ async def generate_react_component_from_html(html_content: str, api_key: str) ->
],
thinking={
"type": "enabled",
"budget_tokens": 16000
"budget_tokens": 25000
}
) as stream:
print("Streaming started, collecting React component response...")
@ -880,6 +881,7 @@ async def save_layouts(
# Update existing layout
existing_layout.layout_name = layout_data.layout_name
existing_layout.layout_code = layout_data.layout_code
existing_layout.fonts = layout_data.fonts
existing_layout.updated_at = datetime.now()
else:
# Create new layout
@ -887,7 +889,8 @@ async def save_layouts(
presentation_id=layout_data.presentation_id,
layout_id=layout_data.layout_id,
layout_name=layout_data.layout_name,
layout_code=layout_data.layout_code
layout_code=layout_data.layout_code,
fonts=layout_data.fonts
)
session.add(new_layout)
@ -969,7 +972,8 @@ async def get_layouts(
presentation_id=layout.presentation_id,
layout_id=layout.layout_id,
layout_name=layout.layout_name,
layout_code=layout.layout_code
layout_code=layout.layout_code,
fonts=layout.fonts
)
for layout in layouts_db
]

View file

@ -1,6 +1,6 @@
from datetime import datetime
from typing import Optional
from sqlalchemy import Column, DateTime, Text
from typing import Optional, List
from sqlalchemy import Column, DateTime, Text, JSON
from sqlmodel import SQLModel, Field
@ -14,5 +14,6 @@ class PresentationLayoutCodeModel(SQLModel, table=True):
layout_id: str = Field(description="Unique identifier for the layout")
layout_name: str = Field(description="Display name of the layout")
layout_code: str = Field(sa_column=Column(Text), description="TSX/React component code for the layout")
fonts: Optional[List[str]] = Field(sa_column=Column(JSON), default=None, description="Optional list of font links")
created_at: datetime = Field(sa_column=Column(DateTime, default=datetime.now))
updated_at: datetime = Field(sa_column=Column(DateTime, default=datetime.now, onupdate=datetime.now))