Added logging to main
This commit is contained in:
+32
-31
@@ -1,9 +1,11 @@
|
|||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from db.db import Base, db_dependency, engine
|
from db.db import Base, db_dependency, engine
|
||||||
from dotenv import load_dotenv
|
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 pydantic import BaseModel
|
||||||
from routers import (
|
from routers import (
|
||||||
companies,
|
companies,
|
||||||
@@ -26,10 +28,21 @@ def init_database():
|
|||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
init_database()
|
init_database()
|
||||||
|
|
||||||
app = FastAPI()
|
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
|
# Request models
|
||||||
class QueryRequest(BaseModel):
|
class QueryRequest(BaseModel):
|
||||||
@@ -109,42 +122,30 @@ async def parse_csv(
|
|||||||
"/query", response_model=PaginatedResponse[InvestmentResponse], tags=["Querying"]
|
"/query", response_model=PaginatedResponse[InvestmentResponse], tags=["Querying"]
|
||||||
)
|
)
|
||||||
async def query_investors(request: QueryRequest):
|
async def query_investors(request: QueryRequest):
|
||||||
"""
|
"""Query investors/funds using natural language"""
|
||||||
Query investors using natural language.
|
try:
|
||||||
|
processor = QueryProcessor()
|
||||||
Returns fund-level matches (one row per fund) with investor details.
|
result = await processor.process_query(request.question)
|
||||||
This ensures only relevant funds are included in the response.
|
logger.info(f"Query completed successfully with {result.total} results")
|
||||||
|
return result
|
||||||
Supports queries like:
|
except Exception as e:
|
||||||
- "Show me seed stage investors"
|
logger.error(f"Error in query_investors: {e}", exc_info=True)
|
||||||
- "Find fintech investors in Silicon Valley"
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
- "Growth stage investors with $5M+ check sizes"
|
|
||||||
- "Healthcare investors in Europe"
|
|
||||||
"""
|
|
||||||
processor = QueryProcessor()
|
|
||||||
results = await processor.process_query(request.question)
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
@app.post(
|
@app.post(
|
||||||
"/query-companies", response_model=PaginatedResponse[CompanyData], tags=["Querying"]
|
"/query-companies", response_model=PaginatedResponse[CompanyData], tags=["Querying"]
|
||||||
)
|
)
|
||||||
async def query_companies(request: CompanyQueryRequest):
|
async def query_companies(request: CompanyQueryRequest):
|
||||||
"""
|
"""Query companies using natural language"""
|
||||||
Query companies using natural language.
|
try:
|
||||||
|
processor = CompanyQueryProcessor()
|
||||||
Returns company matches with their investor relationships, team members, and sectors.
|
result = await processor.process_query(request.question)
|
||||||
|
logger.info(f"Company query completed successfully with {result.total} results")
|
||||||
Supports queries like:
|
return result
|
||||||
- "Show me fintech companies founded in 2020"
|
except Exception as e:
|
||||||
- "Find healthcare companies in San Francisco"
|
logger.error(f"Error in query_companies: {e}", exc_info=True)
|
||||||
- "Companies in the AI sector"
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
- "Companies that received funding from Sequoia"
|
|
||||||
- "European startups founded after 2019"
|
|
||||||
"""
|
|
||||||
processor = CompanyQueryProcessor()
|
|
||||||
results = await processor.process_query(request.question)
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
app.include_router(investors.router)
|
app.include_router(investors.router)
|
||||||
|
|||||||
Reference in New Issue
Block a user