2222from api .nodes .guide_node import GuideNode
2323from api .nodes .pdf_builder_node import PdfBuilderNode
2424from api .nodes .new_pipeline .pipeline import Generate10Pipeline
25+ from api .nodes .new_pipeline .web_fetch_node import WebFetchNode
26+ from api .nodes .new_pipeline .local_fetch_node import LocalFetchNode
27+ from api .nodes .new_pipeline .clean_node import CleanNode
28+ from api .nodes .new_pipeline .keyphrase_node import KeyphraseNode
29+ from api .nodes .new_pipeline .framework_select_node import FrameworkSelectNode
30+ from api .nodes .new_pipeline .prompt_draft_node import PromptDraftNode
31+ from api .nodes .new_pipeline .deduplicate_node import DeduplicateNode
32+ from api .nodes .new_pipeline .business_anchor_guard import BusinessAnchorGuard
33+ from api .nodes .new_pipeline .quota_enforce_node import QuotaEnforceNode
34+ from api .nodes .new_pipeline .explanation_node import ExplanationNode
35+ from api .nodes .assets_node import AssetsNode
2536
2637import logging
2738app = FastAPI (title = "Prompt Bootstrapper API" )
@@ -76,6 +87,78 @@ async def generate10(request: Request):
7687 except NotImplementedError as e :
7788 logger .exception ("10-prompt pipeline not yet implemented" )
7889 raise HTTPException (status_code = 501 , detail = str (e ))
90+ except ValueError as e :
91+ # Fallback validation errors
92+ raise HTTPException (status_code = 422 , detail = str (e ))
7993 except Exception as e :
8094 logger .exception ("Unhandled error in /generate10 endpoint" )
95+ raise HTTPException (status_code = 500 , detail = str (e ))
96+ @app .post ("/generate10/json" )
97+ async def generate10_json (request : Request ):
98+ data = await request .json ()
99+ url = data .get ('url' )
100+ raw_text = data .get ('text' )
101+ if not url and not raw_text :
102+ raise HTTPException (status_code = 400 , detail = "Missing 'url' or 'text' in request body" )
103+ try :
104+ # Determine input text: either user-supplied or fetched+cleaned
105+ # Determine input text: from user or fetched+cleaned
106+ if raw_text :
107+ text = raw_text
108+ else :
109+ # Step 1: fetch raw HTML and fallback
110+ html = WebFetchNode (url )
111+ if not html or len (html ) < 500 :
112+ html = LocalFetchNode (url )
113+ # Validate content length after fallback
114+ if not html or len (html ) < 500 :
115+ raise ValueError ("Fetched content too short (<500 characters); please provide raw text or a richer URL." )
116+ # Step 2: clean text
117+ text = CleanNode (html )
118+ # Step 3: extract keyphrases
119+ keyphrases = KeyphraseNode (text )
120+ # Step 4: framework plan
121+ plan = FrameworkSelectNode (keyphrases )
122+ # Step 5: draft prompts
123+ raw_prompts = PromptDraftNode (text , plan )
124+ # Step 6: dedupe
125+ unique_prompts = DeduplicateNode (raw_prompts )
126+ # Step 7: anchor
127+ anchored = BusinessAnchorGuard (unique_prompts , keyphrases )
128+ # Step 8: enforce quota
129+ final_prompts = QuotaEnforceNode (anchored , plan )
130+ # Step 9: explanations
131+ tips = ExplanationNode (final_prompts )
132+ # Step 10: assets for branding
133+ assets = AssetsNode (url )
134+ return JSONResponse (content = {
135+ "prompts" : final_prompts ,
136+ "tips" : tips ,
137+ "logo_url" : assets .get ('logo_url' ),
138+ "palette" : assets .get ('palette' , [])
139+ })
140+ except Exception as e :
141+ logger .exception ("Error in /generate10/json endpoint" )
142+ # Distinguish client vs server
143+ status = 422 if isinstance (e , ValueError ) else 500
144+ raise HTTPException (status_code = status , detail = str (e ))
145+
146+ @app .post ("/generate10/pdf" )
147+ async def generate10_pdf (request : Request ):
148+ data = await request .json ()
149+ prompts = data .get ("prompts" )
150+ tips = data .get ("tips" )
151+ logo_url = data .get ("logo_url" )
152+ palette = data .get ("palette" , [])
153+ if not (isinstance (prompts , list ) and isinstance (tips , list ) and len (prompts ) == len (tips )):
154+ raise HTTPException (status_code = 400 , detail = "Invalid prompts or tips payload" )
155+ try :
156+ pdf_bytes = PdfBuilderNode (logo_url , palette , prompts , tips )
157+ return StreamingResponse (
158+ io .BytesIO (pdf_bytes ),
159+ media_type = "application/pdf" ,
160+ headers = {"Content-Disposition" : "attachment; filename=\" prompts10.pdf\" " },
161+ )
162+ except Exception as e :
163+ logger .exception ("Error in /generate10/pdf endpoint" )
81164 raise HTTPException (status_code = 500 , detail = str (e ))
0 commit comments