fix(analyzer): eliminate double SERP.query() call per company analysis
_analyze_company_safe called SERP.query() then passed the company name to analyze_company() which called SERP.query() again — doubling API usage. Now analyze_company() accepts an optional patents param so callers can pass pre-fetched results through.
This commit is contained in:
+6
-4
@@ -23,7 +23,7 @@ class CompanyAnalyzer:
|
||||
"""
|
||||
self.llm_analyzer = LLMAnalyzer(api_key=openrouter_api_key)
|
||||
|
||||
def analyze_company(self, company_name: str) -> str:
|
||||
def analyze_company(self, company_name: str, patents: "Patents | None" = None) -> str:
|
||||
"""Analyze a company's performance based on their patent portfolio.
|
||||
|
||||
This is the main entry point that orchestrates the full pipeline:
|
||||
@@ -35,12 +35,14 @@ class CompanyAnalyzer:
|
||||
|
||||
Args:
|
||||
company_name: Name of the company to analyze
|
||||
patents: Optional pre-fetched Patents result to avoid duplicate API calls
|
||||
|
||||
Returns:
|
||||
Comprehensive analysis of company's innovation and performance outlook
|
||||
"""
|
||||
print(f"Retrieving patents for {company_name}...")
|
||||
patents = SERP.query(company_name)
|
||||
if patents is None:
|
||||
print(f"Retrieving patents for {company_name}...")
|
||||
patents = SERP.query(company_name)
|
||||
|
||||
if not patents.patents:
|
||||
return f"No patents found for {company_name}"
|
||||
@@ -126,7 +128,7 @@ class CompanyAnalyzer:
|
||||
patents = SERP.query(company_name)
|
||||
patent_count = len(patents.patents) if patents.patents else 0
|
||||
|
||||
analysis = self.analyze_company(company_name)
|
||||
analysis = self.analyze_company(company_name, patents=patents)
|
||||
|
||||
# Check if analysis indicates failure
|
||||
if analysis.startswith("No patents found") or analysis.startswith(
|
||||
|
||||
Reference in New Issue
Block a user