refactor: Improve handling of optional fields and enhance compatibility score calculations
This commit is contained in:
+1
-1
@@ -122,4 +122,4 @@ app.include_router(report_route.router)
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app="main:app", host="0.0.0.0", port=8585, reload=True)
|
||||
uvicorn.run(app="main:app", host="0.0.0.0", port=8585)
|
||||
|
||||
@@ -30,7 +30,7 @@ class InvestorSchema(BaseModel):
|
||||
check_size_lower: int | None
|
||||
check_size_upper: int | None
|
||||
geographic_focus: str | None
|
||||
stage_focus: InvestmentStage
|
||||
stage_focus: Optional[InvestmentStage] = None
|
||||
number_of_investments: int | None
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
|
||||
@@ -127,7 +127,7 @@ def _calculate_project_fund_compatibility(
|
||||
geo_score = 0
|
||||
if project.location and fund.geographic_focus:
|
||||
project_location_lower = project.location.lower()
|
||||
fund_geo_lower = fund.geographic_focus.lower()
|
||||
fund_geo_lower = (fund.geographic_focus or "").lower()
|
||||
|
||||
# Exact match
|
||||
if project_location_lower == fund_geo_lower:
|
||||
@@ -223,7 +223,7 @@ def _calculate_project_investor_direct_compatibility(
|
||||
geo_score = 0
|
||||
if project.location and investor.geographic_focus:
|
||||
project_location_lower = project.location.lower()
|
||||
investor_geo_lower = investor.geographic_focus.lower()
|
||||
investor_geo_lower = (investor.geographic_focus or "").lower()
|
||||
|
||||
if project_location_lower == investor_geo_lower:
|
||||
geo_score = 20
|
||||
|
||||
@@ -26,7 +26,7 @@ class QueryProcessor:
|
||||
self.llm = ChatOpenAI(
|
||||
api_key=OPENROUTER_API_KEY,
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
model="openai/gpt-5-nano",
|
||||
model="openai/gpt-4o-mini",
|
||||
temperature=0,
|
||||
)
|
||||
self.agent = create_react_agent(
|
||||
@@ -107,6 +107,8 @@ class QueryProcessor:
|
||||
- If you cannot find sufficient data after searching, make reasonable inferences based on available information
|
||||
- DO NOT state that data is unavailable or ambiguous - provide the best analysis possible with what you find
|
||||
- Focus on ACTIONABLE insights, not disclaimers
|
||||
- Only call the tool twice at most, be strategic in your searches
|
||||
- Summarize your findings concisely and clearly
|
||||
|
||||
Provide insights in the InsightResponse schema format:
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class QueryProcessor:
|
||||
self.llm = ChatOpenAI(
|
||||
api_key=os.getenv("OPENROUTER_API_KEY"),
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
model="x-ai/grok-4-fast",
|
||||
model="openai/gpt-4o-mini",
|
||||
temperature=0,
|
||||
)
|
||||
self.toolkit = SQLDatabaseToolkit(db=db, llm=self.llm)
|
||||
|
||||
+23
-16
@@ -95,16 +95,16 @@ class ReportGenerator:
|
||||
score += weights["stage"]
|
||||
|
||||
# Geography match
|
||||
investor_geo = investor_data.get("geographic_focus", "").lower()
|
||||
project_geo = project_data.get("location", "").lower()
|
||||
investor_geo = (investor_data.get("geographic_focus") or "").lower()
|
||||
project_geo = (project_data.get("location") or "").lower()
|
||||
if investor_geo and project_geo and investor_geo in project_geo:
|
||||
score += weights["geography"]
|
||||
|
||||
# Check size match
|
||||
project_valuation = project_data.get("valuation", 0)
|
||||
check_lower = investor_data.get("check_size_lower", 0)
|
||||
check_upper = investor_data.get("check_size_upper", float("inf"))
|
||||
if check_lower <= project_valuation <= check_upper:
|
||||
check_lower = investor_data.get("check_size_lower") or 0
|
||||
check_upper = investor_data.get("check_size_upper") or float("inf")
|
||||
if check_lower and check_upper and check_lower <= project_valuation <= check_upper:
|
||||
score += weights["check_size"]
|
||||
|
||||
# Thesis alignment (simplified)
|
||||
@@ -151,14 +151,21 @@ class ReportGenerator:
|
||||
)
|
||||
|
||||
# Geography criterion
|
||||
investor_geo = investor_data.get("geographic_focus", "N/A")
|
||||
project_geo = project_data.get("location", "N/A")
|
||||
geo_match = (
|
||||
"Strong"
|
||||
if investor_geo.lower() in project_geo.lower()
|
||||
or project_geo.lower() in investor_geo.lower()
|
||||
else "Mismatch"
|
||||
)
|
||||
investor_geo = investor_data.get("geographic_focus") or "N/A"
|
||||
project_geo = project_data.get("location") or "N/A"
|
||||
|
||||
# Safe comparison handling None values
|
||||
if investor_geo == "N/A" or project_geo == "N/A":
|
||||
geo_match = "N/A" if investor_geo == "N/A" and project_geo == "N/A" else "Mismatch"
|
||||
else:
|
||||
investor_geo_lower = investor_geo.lower()
|
||||
project_geo_lower = project_geo.lower()
|
||||
geo_match = (
|
||||
"Strong"
|
||||
if investor_geo_lower in project_geo_lower
|
||||
or project_geo_lower in investor_geo_lower
|
||||
else "Mismatch"
|
||||
)
|
||||
criteria.append(
|
||||
{
|
||||
"name": "Geography",
|
||||
@@ -170,8 +177,8 @@ class ReportGenerator:
|
||||
)
|
||||
|
||||
# Check Size criterion
|
||||
check_lower = investor_data.get("check_size_lower", 0)
|
||||
check_upper = investor_data.get("check_size_upper", 0)
|
||||
check_lower = investor_data.get("check_size_lower") or 0
|
||||
check_upper = investor_data.get("check_size_upper") or 0
|
||||
project_val = project_data.get("valuation", 0)
|
||||
|
||||
check_evidence = "N/A"
|
||||
@@ -184,7 +191,7 @@ class ReportGenerator:
|
||||
|
||||
check_match = (
|
||||
"Perfect"
|
||||
if check_lower <= project_val <= check_upper
|
||||
if check_lower and check_upper and check_lower <= project_val <= check_upper
|
||||
else "Strong"
|
||||
if project_val > 0
|
||||
else "N/A"
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user