Unverified Commit aeb5a08a authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Add offline mode for agents (#25226)

* Add offline mode for agents

* Disable second check too
parent bff4313b
...@@ -25,7 +25,7 @@ import requests ...@@ -25,7 +25,7 @@ import requests
from huggingface_hub import HfFolder, hf_hub_download, list_spaces from huggingface_hub import HfFolder, hf_hub_download, list_spaces
from ..models.auto import AutoTokenizer from ..models.auto import AutoTokenizer
from ..utils import is_openai_available, is_torch_available, logging from ..utils import is_offline_mode, is_openai_available, is_torch_available, logging
from .base import TASK_MAPPING, TOOL_CONFIG_FILE, Tool, load_tool, supports_remote from .base import TASK_MAPPING, TOOL_CONFIG_FILE, Tool, load_tool, supports_remote
from .prompts import CHAT_MESSAGE_PROMPT, download_prompt from .prompts import CHAT_MESSAGE_PROMPT, download_prompt
from .python_interpreter import evaluate from .python_interpreter import evaluate
...@@ -75,6 +75,10 @@ HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB = [ ...@@ -75,6 +75,10 @@ HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB = [
def get_remote_tools(organization="huggingface-tools"): def get_remote_tools(organization="huggingface-tools"):
if is_offline_mode():
logger.info("You are in offline mode, so remote tools are not available.")
return {}
spaces = list_spaces(author=organization) spaces = list_spaces(author=organization)
tools = {} tools = {}
for space_info in spaces: for space_info in spaces:
...@@ -105,6 +109,7 @@ def _setup_default_tools(): ...@@ -105,6 +109,7 @@ def _setup_default_tools():
description = tool_class.description description = tool_class.description
HUGGINGFACE_DEFAULT_TOOLS[tool_class.name] = PreTool(task=task_name, description=description, repo_id=None) HUGGINGFACE_DEFAULT_TOOLS[tool_class.name] = PreTool(task=task_name, description=description, repo_id=None)
if not is_offline_mode():
for task_name in HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB: for task_name in HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB:
found = False found = False
for tool_name, tool in remote_tools.items(): for tool_name, tool in remote_tools.items():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment