from fastapi import APIRouter, Depends, HTTPException, BackgroundTasks from typing import List, Optional import os import json from app.models.pitch_input import PitchInput, InvestorType from app.models.pitch_output import PitchOutput from app.services.openai_agents import OpenAIAgentService from app.core.config import settings router = APIRouter() agent_service = OpenAIAgentService() @router.post("/generate-pitch", response_model=PitchOutput) async def generate_pitch(pitch_input: PitchInput): """ Generate pitch scripts based on user input. This endpoint: 1. Accepts structured user input about their startup 2. Processes it through a RAG pipeline (Perplexity → Gemini → OpenAI) 3. Returns elevator and full pitch scripts with competitor analysis """ try: if pitch_input.investor_type == InvestorType.ANGEL: return await agent_service.create_angel_investor_agent(pitch_input) else: return await agent_service.create_vc_investor_agent(pitch_input) except Exception as e: raise HTTPException(status_code=500, detail=f"Error generating pitch: {str(e)}") @router.get("/scripts/{script_id}", response_model=PitchOutput) async def get_script(script_id: str): """ Retrieve a previously generated script by ID. """ # Search in both angel and vc directories for investor_type in ["angel", "vc"]: filename = f"{settings.SCRIPTS_STORAGE_PATH}/{investor_type}_{script_id}.json" if os.path.exists(filename): with open(filename, "r") as f: data = json.load(f) return data["output"] raise HTTPException(status_code=404, detail=f"Script with ID {script_id} not found") @router.get("/scripts", response_model=List[dict]) async def list_scripts(): """ List all available scripts. """ scripts = [] # List all JSON files in the scripts directory for filename in os.listdir(settings.SCRIPTS_STORAGE_PATH): if filename.endswith(".json"): filepath = os.path.join(settings.SCRIPTS_STORAGE_PATH, filename) with open(filepath, "r") as f: data = json.load(f) # Add a summary to the list scripts.append({ "script_id": data["output"]["script_id"], "startup_name": data["input"]["startup_name"], "investor_type": data["input"]["investor_type"], "created_at": os.path.getctime(filepath) }) return sorted(scripts, key=lambda x: x["created_at"], reverse=True)