Added logging to main

This commit is contained in:
bolade
2025-10-28 21:34:20 +01:00
parent f63672bdac
commit 3ab2592c22
+32 -31
View File
@@ -1,9 +1,11 @@
import io
import logging
import pandas as pd
from db.db import Base, db_dependency, engine
from dotenv import load_dotenv
from fastapi import FastAPI, File, Form, UploadFile
from fastapi import FastAPI, File, Form, HTTPException, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from routers import (
companies,
@@ -26,10 +28,21 @@ def init_database():
Base.metadata.create_all(bind=engine)
logger = logging.getLogger(__name__)
init_database()
app = FastAPI()
# Add CORS middleware to allow frontend requests
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # In production, replace with specific origins
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Request models
class QueryRequest(BaseModel):
@@ -109,42 +122,30 @@ async def parse_csv(
"/query", response_model=PaginatedResponse[InvestmentResponse], tags=["Querying"]
)
async def query_investors(request: QueryRequest):
"""
Query investors using natural language.
Returns fund-level matches (one row per fund) with investor details.
This ensures only relevant funds are included in the response.
Supports queries like:
- "Show me seed stage investors"
- "Find fintech investors in Silicon Valley"
- "Growth stage investors with $5M+ check sizes"
- "Healthcare investors in Europe"
"""
processor = QueryProcessor()
results = await processor.process_query(request.question)
return results
"""Query investors/funds using natural language"""
try:
processor = QueryProcessor()
result = await processor.process_query(request.question)
logger.info(f"Query completed successfully with {result.total} results")
return result
except Exception as e:
logger.error(f"Error in query_investors: {e}", exc_info=True)
raise HTTPException(status_code=500, detail=str(e))
@app.post(
"/query-companies", response_model=PaginatedResponse[CompanyData], tags=["Querying"]
)
async def query_companies(request: CompanyQueryRequest):
"""
Query companies using natural language.
Returns company matches with their investor relationships, team members, and sectors.
Supports queries like:
- "Show me fintech companies founded in 2020"
- "Find healthcare companies in San Francisco"
- "Companies in the AI sector"
- "Companies that received funding from Sequoia"
- "European startups founded after 2019"
"""
processor = CompanyQueryProcessor()
results = await processor.process_query(request.question)
return results
"""Query companies using natural language"""
try:
processor = CompanyQueryProcessor()
result = await processor.process_query(request.question)
logger.info(f"Company query completed successfully with {result.total} results")
return result
except Exception as e:
logger.error(f"Error in query_companies: {e}", exc_info=True)
raise HTTPException(status_code=500, detail=str(e))
app.include_router(investors.router)