From cf33154dd6c3fe0a1d693ae020c727ed2a88758c Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Thu, 19 Dec 2024 15:44:51 -0800 Subject: [PATCH] Fix ValueError in DuckDuckGoWebSearchDriver --- CHANGELOG.md | 6 ++++++ .../drivers/web_search/duck_duck_go_web_search_driver.py | 7 ++++++- tests/integration/test_code_blocks.py | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfc0b2f00..22314ec47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for `BranchTask` in `StructureVisualizer`. - `EvalEngine` for evaluating the performance of an LLM's output against a given input. - `BaseFileLoader.save()` method for saving an Artifact to a destination. +- `DuckDuckGoWebSearchDriver.backend` for setting the backend to use for DuckDuckGo searches. ### Changed @@ -31,6 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `StructureVisualizer.query_params` for setting query parameters on the url generated by `StructureVisualizer.to_url()`. - Parsing `ActionCallDeltaMessageContent`s with empty string `partial_input`s. - `Stream` util not properly propagating thread contextvars. +- `ValueError` with `DuckDuckGoWebSearchDriver`. + +### Deprecated + +- `DuckDuckGoWebSearchDriver`. `DuckDuckGoWebSearchDriver` relies on `duckduckgo_search` which is no longer maintained and has been archived. ## [1.0.0] - 2024-12-09 diff --git a/griptape/drivers/web_search/duck_duck_go_web_search_driver.py b/griptape/drivers/web_search/duck_duck_go_web_search_driver.py index 113ca5a8a..b2ecf8205 100644 --- a/griptape/drivers/web_search/duck_duck_go_web_search_driver.py +++ b/griptape/drivers/web_search/duck_duck_go_web_search_driver.py @@ -18,6 +18,7 @@ class DuckDuckGoWebSearchDriver(BaseWebSearchDriver): language: str = field(default="en", kw_only=True) country: str = field(default="us", kw_only=True) + backend: str = field(default="api", kw_only=True) _client: DDGS = field(default=None, kw_only=True, alias="client", metadata={"serializable": False}) @lazy_property() @@ -27,7 +28,11 @@ def client(self) -> DDGS: def search(self, query: str, **kwargs) -> ListArtifact: try: results = self.client.text( - query, region=f"{self.language}-{self.country}", max_results=self.results_count, **kwargs + query, + region=f"{self.language}-{self.country}", + max_results=self.results_count, + backend=self.backend, + **kwargs, ) return ListArtifact( [ diff --git a/tests/integration/test_code_blocks.py b/tests/integration/test_code_blocks.py index 409bdd599..11bb2ec86 100644 --- a/tests/integration/test_code_blocks.py +++ b/tests/integration/test_code_blocks.py @@ -20,6 +20,7 @@ "docs/griptape-framework/structures/src/observability_1.py", "docs/griptape-framework/structures/src/observability_2.py", "docs/griptape-framework/data/src/loaders_9.py", + "docs/griptape-framework/drivers/src/web_search_drivers_3.py", ]