Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor DuckDuckGo search component to use new Component base class (nightly fix) #6064

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Cristhianzl
Copy link
Member

This pull request makes significant changes to the src/backend/base/langflow/components/tools/duck_duck_go_search_run.py file. The changes include a major refactor of the DuckDuckGoSearchComponent class, transitioning from the LCToolComponent base class to the Component base class, and updating the methods and properties to align with the new structure.

Refactor and updates to DuckDuckGoSearchComponent:

  • Changed base class from LCToolComponent to Component, and updated imports accordingly.
  • Updated properties such as display_name, description, documentation, and icon to match the new class structure.
  • Modified input definitions to include additional metadata like required, info, and tool_mode.
  • Added outputs property to define the output methods fetch_content and fetch_content_text.

Method updates:

  • Refactored _build_wrapper method to return a DuckDuckGoSearchRun instance.
  • Replaced build_tool method with run_model and fetch_content methods to execute searches and process results.
  • Introduced fetch_content_text method to return search results as a single text message.

… improve code structure and readability

📝 (duck_duck_go_search_run.py): update DuckDuckGoSearchComponent with new display name, description, and documentation URL
📝 (duck_duck_go_search_run.py): update DuckDuckGoSearchComponent inputs with additional information and tool mode
📝 (duck_duck_go_search_run.py): update DuckDuckGoSearchComponent outputs with new output methods and display names
📝 (duck_duck_go_search_run.py): update DuckDuckGoSearchComponent methods to improve clarity and functionality
@Cristhianzl Cristhianzl self-assigned this Feb 1, 2025
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 1, 2025
@Cristhianzl Cristhianzl changed the title fix: refactor DuckDuckGo search component to use new Component base class fix: refactor DuckDuckGo search component to use new Component base class (nightly fix) Feb 1, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 1, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 1, 2025
…o improve readability and remove unnecessary comments and code duplication
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 1, 2025
@Cristhianzl Cristhianzl closed this Feb 1, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 1, 2025
@Cristhianzl Cristhianzl reopened this Feb 1, 2025
codeflash-ai bot added a commit that referenced this pull request Feb 1, 2025
…9% in PR #6064 (`cz/fix-duckduckgo-component`)

### Explanation of Optimizations
Copy link
Contributor

codeflash-ai bot commented Feb 1, 2025

⚡️ Codeflash found optimizations for this PR

📄 1,389% (13.89x) speedup for DuckDuckGoSearchComponent._build_wrapper in src/backend/base/langflow/components/tools/duck_duck_go_search_run.py

⏱️ Runtime : 7.98 milliseconds 536 microseconds (best of 33 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch cz/fix-duckduckgo-component).

codeflash-ai bot added a commit that referenced this pull request Feb 1, 2025
…7% in PR #6064 (`cz/fix-duckduckgo-component`)

To optimize the given Python program for performance, the changes might be minimal since most of the real logic seems to be abstracted away in the imported modules and classes. However, we can make sure the component uses the DuckDuckGoSearchRun wrapper efficiently.

Here's the optimized version of your code.



### Explanation.

1. **Initialization Over Method Call**.
   - In the original code, `_build_wrapper` was creating a new instance of `DuckDuckGoSearchRun` every time it was called, which could be less efficient.
   - By initializing `DuckDuckGoSearchRun` only once in the `__init__` method and storing it as an instance variable (`self._wrapper`), we avoid redundant instantiations and potential overhead associated with that.
   - The `_build_wrapper` method now returns this pre-built instance which is more efficient in cases where this method might be called multiple times.

This change will increase the efficiency by ensuring that the instance of `DuckDuckGoSearchRun` is created only once and reused.

Since the rest of the component logic seems abstract and dependent on its base classes and external modules, there's limited room for optimization without altering the internal dependencies or functionality, which we are instructed not to do.
Copy link
Contributor

codeflash-ai bot commented Feb 1, 2025

⚡️ Codeflash found optimizations for this PR

📄 1,347% (13.47x) speedup for DuckDuckGoSearchComponent._build_wrapper in src/backend/base/langflow/components/tools/duck_duck_go_search_run.py

⏱️ Runtime : 15.0 milliseconds 1.04 millisecond (best of 194 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch cz/fix-duckduckgo-component).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant