Skip to content

Commit

Permalink
⚡️ Speed up method DuckDuckGoSearchComponent._build_wrapper by 1,38…
Browse files Browse the repository at this point in the history
…9% in PR #6064 (`cz/fix-duckduckgo-component`)

### Explanation of Optimizations
  • Loading branch information
codeflash-ai[bot] authored Feb 1, 2025
1 parent d470485 commit c3f7015
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ class DuckDuckGoSearchComponent(Component):
]

def _build_wrapper(self) -> DuckDuckGoSearchRun:
"""Build the DuckDuckGo search wrapper."""
return DuckDuckGoSearchRun()
"""Builds or returns the DuckDuckGoSearchRun wrapper for efficiency."""
if not self.wrapper_initialized:
self._wrapper = DuckDuckGoSearchRun()
self.wrapper_initialized = True
return self._wrapper

def run_model(self) -> list[Data]:
return self.fetch_content()
Expand Down Expand Up @@ -89,3 +92,8 @@ def fetch_content_text(self) -> Message:
result_string = "\n".join(item.text for item in data)
self.status = result_string
return Message(text=result_string)

def __init__(self):
super().__init__()
self._wrapper = None
self.wrapper_initialized = False

0 comments on commit c3f7015

Please sign in to comment.