Spaces:
Sleeping
Sleeping
File size: 2,651 Bytes
e34506d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 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) |