Skip to content

Commit

Permalink
Update duckduckgo_search
Browse files Browse the repository at this point in the history
There have been breaking changes in the API.
See <https://github.com/deedy5/duckduckgo_search/releases/tag/v5.0b1>
  • Loading branch information
paulovcmedeiros committed Mar 3, 2024
1 parent 16aa69b commit b01ed80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
audio-recorder-streamlit = "^0.0.8"
beautifulsoup4 = "^4.12.3"
chime = "^0.7.0"
duckduckgo-search = "^4.5.0"
duckduckgo-search = {git = "https://github.com/deedy5/duckduckgo_search"}
gtts = "^2.5.1"
httpx = "^0.26.0"
ipinfo = "^5.0.1"
Expand Down
10 changes: 6 additions & 4 deletions pyrobbot/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,12 @@ def _translate(self, text):
return cached_translation

logger.debug("Processing translation of '{}' to '{}'...", text, lang)
translation_prompt = f"Translate the text between triple quotes below to {lang}. "
translation_prompt += "DO NOT WRITE ANYTHING ELSE. Only the translation. "
translation_prompt += f"If the text is already in {lang}, then just return ''.\n"
translation_prompt += f"'''{text}'''"
translation_prompt = (
f"Translate the text between triple quotes below to {lang}. "
"DO NOT WRITE ANYTHING ELSE. Only the translation. "
f"If the text is already in {lang}, then don't translate. Just return ''.\n"
f"'''{text}'''"
)
translation = "".join(self.respond_system_prompt(prompt=translation_prompt))

translation = translation.strip(" '\"")
Expand Down
19 changes: 8 additions & 11 deletions pyrobbot/internet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,14 @@ async def async_raw_websearch(
region: str = GeneralDefinitions.IPINFO["country_name"],
):
"""Search the web using DuckDuckGo Search API."""
async with AsyncDDGS() as ddgs:
async_results = [
result
async for result in ddgs.text(
keywords=query,
region=region,
max_results=max_results,
backend="html",
)
]
return async_results
async with AsyncDDGS(proxies=None) as addgs:
results = await addgs.text(
keywords=query,
region=region,
max_results=max_results,
backend="html",
)
return results


def raw_websearch(
Expand Down

0 comments on commit b01ed80

Please sign in to comment.