Skip to content

pref: add proxies kwargs in duckduckgo tool run func - #501

Open
cavities wants to merge 1 commit into
Undertone0809:mainfrom
cavities:main
Open

pref: add proxies kwargs in duckduckgo tool run func#501
cavities wants to merge 1 commit into
Undertone0809:mainfrom
cavities:main

Conversation

@cavities

@cavities cavities commented Mar 7, 2024

Copy link
Copy Markdown

.. add proxies kwargs in duckduckgo tool
tool.run(xxx,proxies="socks5://localhost:7891")
..

Summary by CodeRabbit

  • New Features
    • Added proxy support for DuckDuckGo search queries, allowing users to route requests through specified proxies for enhanced privacy and control.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 7, 2024
@coderabbitai

coderabbitai Bot commented Mar 7, 2024

Copy link
Copy Markdown

Walkthrough

The recent update introduces a new proxies attribute to the DuckDuckGoSearchAPIWrapper class, enhancing its flexibility by allowing the use of proxy servers during search queries. This attribute is cleverly integrated into the query functions and is dynamically set based on the presence of proxy information in method calls, ensuring seamless proxy support across the board.

Changes

File Path Change Summary
.../duckduckgo/api_wrapper.py Added proxies attribute to DuckDuckGoSearchAPIWrapper class; utilized in query functions.
.../duckduckgo/tools.py Added proxy check in _run method to set api_wrapper.proxies based on kwargs.

🐰✨
In the land of code and wire,
A rabbit worked, never to tire.
With a hop and a skip, proxies in grip,
Searches flow, no snag or mire.
Through the digital burrow, it delves deep,
Bringing secrets for all to keep.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@sweep-ai-deprecated

Copy link
Copy Markdown
Contributor

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

This is an automated message generated by Sweep AI.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @cavities, thanks for opening your first pull request 😊! We really appreciate your work. Happy Coding 🎉🎊 !

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 06a701d and e339946.
Files selected for processing (2)
  • promptulate/tools/duckduckgo/api_wrapper.py (3 hunks)
  • promptulate/tools/duckduckgo/tools.py (2 hunks)
Additional comments: 5
promptulate/tools/duckduckgo/api_wrapper.py (3)
  • 13-13: The addition of the proxies attribute with a default value of None is correctly implemented and follows the conventions of optional attributes in the class.
  • 40-40: The modification to pass self.proxies to the DDGS object in the query function is correctly implemented. Ensure that the DDGS class from the duckduckgo_search package supports the proxies parameter.
  • 77-77: The modification to pass self.proxies to the DDGS object in the query_by_formatted_results function is correctly implemented. Ensure that the DDGS class from the duckduckgo_search package supports the proxies parameter, similar to the previous comment.
promptulate/tools/duckduckgo/tools.py (2)
  • 37-39: The implementation to check for proxies in kwargs and set self.api_wrapper.proxies accordingly in the _run method of DuckDuckGoTool is correct. Ensure that this approach does not introduce any side effects, especially in concurrent or subsequent calls with different proxy settings.
  • 85-87: The implementation to check for proxies in kwargs and set self.api_wrapper.proxies accordingly in the _run method of DuckDuckGoReferenceTool is correct. Ensure that this approach does not introduce any side effects, especially in concurrent or subsequent calls with different proxy settings, similar to the previous comment.

@Undertone0809

Copy link
Copy Markdown
Owner

You can run make formatting in terminal

@Undertone0809 Undertone0809 changed the title ".. add proxies kwargs in duckduckgo tool run func .." pref: add proxies kwargs in duckduckgo tool run func Mar 7, 2024

@ruanrongman ruanrongman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before you commit your code you can make lint to check

@Undertone0809 Undertone0809 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two correctness issues block this as written: the proxy value is passed into DDGS positionally instead of as the proxies kwarg, and the tool mutates self.api_wrapper.proxies without clearing it, so a proxy can leak into later calls on the same tool instance.

num_results = self.max_num_of_results

with DDGS() as ddgs:
with DDGS(self.proxies) as ddgs:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duckduckgo_search==3.9.11 defines DDGS(headers=None, proxies=None, timeout=10), so DDGS(self.proxies) binds the proxy string to headers, not proxies. This means the proxy is never applied. Please pass it explicitly as DDGS(proxies=self.proxies) here and in the other call site.

"""
from duckduckgo_search.exceptions import RateLimitException

if "proxies" in kwargs:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mutates self.api_wrapper.proxies only when kwargs["proxies"] is truthy, so once one call sets a proxy, later calls on the same tool instance will keep using that stale proxy unless the process is restarted. It also makes proxies=None unable to clear the setting. Please thread proxies through per call, or at least assign self.api_wrapper.proxies = kwargs.get("proxies") before the query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants