From d387bbbdf319814c572852c224a2e3891b534683 Mon Sep 17 00:00:00 2001 From: 0xWheatyz Date: Tue, 24 Mar 2026 14:16:49 -0400 Subject: [PATCH] fix(analyzer): eliminate double SERP.query() call per company analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _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. --- SPARC/analyzer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/SPARC/analyzer.py b/SPARC/analyzer.py index c833c0d..47ae7e2 100644 --- a/SPARC/analyzer.py +++ b/SPARC/analyzer.py @@ -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(