Skip to content

Commit

Permalink
fix(chat): improve ConversationLimitException
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Feb 23, 2025
1 parent b969f8e commit ab27033
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion duckduckgo_search/duckduckgo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _get_url(
logger.debug(f"_get_url() {resp.url} {resp.status_code} {len(resp.content)}")
if resp.status_code == 200:
return resp.content
elif resp.status_code in (202, 301, 403):
elif resp.status_code in (202, 301, 403, 400, 429, 418):
raise RatelimitException(f"{resp.url} {resp.status_code} Ratelimit")
raise DuckDuckGoSearchException(f"{resp.url} return None. {params=} {content=} {data=}")

Expand Down Expand Up @@ -170,6 +170,8 @@ def chat_yield(self, keywords: str, model: str = "gpt-4o-mini", timeout: int = 3
if line and line.startswith("data:"):
if line == "data: [DONE]":
break
if line == "data: [DONE][LIMIT_CONVERSATION]":
raise ConversationLimitException("ERR_CONVERSATION_LIMIT")
x = json_loads(line[5:].strip())
if isinstance(x, dict):
if x.get("action") == "error":
Expand Down

0 comments on commit ab27033

Please sign in to comment.