Spaces:
Runtime error
Runtime error
Download utils.py from Kimmy7/chat_over_docs: direct link, hf CLI and curl.
- Browser
- Download file 859 Bytes
-
https://huggingface.co/spaces/Kimmy7/chat_over_docs/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Kimmy7/chat_over_docs/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Kimmy7/chat_over_docs/resolve/main/utils.py
859 Bytes
| from langchain_core.callbacks.base import BaseCallbackHandler | |
| from langchain.agents.agent import AgentAction | |
| from typing import Any, Union | |
| class RetryCallbackHandler(BaseCallbackHandler): | |
| def on_tool_error( | |
| self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any | |
| ) -> Any: | |
| # Log the error or perform any necessary actions | |
| # Retry logic | |
| max_retries = 1 | |
| current_retry = kwargs.get("retry_count", 0) | |
| if current_retry < max_retries: | |
| print(f"Retrying tool execution (Attempt {current_retry + 1})") | |
| # Increment retry count | |
| kwargs["retry_count"] = current_retry + 1 | |
| # Re-run the tool | |
| return AgentAction.RERUN | |
| else: | |
| print("Maximum retries reached. Switching to another tool.") | |
| return AgentAction.CHANGE_TOOL | |