Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
aeb5a08a
Unverified
Commit
aeb5a08a
authored
Aug 04, 2023
by
Sylvain Gugger
Committed by
GitHub
Aug 04, 2023
Browse files
Add offline mode for agents (#25226)
* Add offline mode for agents * Disable second check too
parent
bff4313b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
11 deletions
+16
-11
src/transformers/tools/agents.py
src/transformers/tools/agents.py
+16
-11
No files found.
src/transformers/tools/agents.py
View file @
aeb5a08a
...
...
@@ -25,7 +25,7 @@ import requests
from
huggingface_hub
import
HfFolder
,
hf_hub_download
,
list_spaces
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
.prompts
import
CHAT_MESSAGE_PROMPT
,
download_prompt
from
.python_interpreter
import
evaluate
...
...
@@ -75,6 +75,10 @@ HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB = [
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
)
tools
=
{}
for
space_info
in
spaces
:
...
...
@@ -105,16 +109,17 @@ def _setup_default_tools():
description
=
tool_class
.
description
HUGGINGFACE_DEFAULT_TOOLS
[
tool_class
.
name
]
=
PreTool
(
task
=
task_name
,
description
=
description
,
repo_id
=
None
)
for
task_name
in
HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB
:
found
=
False
for
tool_name
,
tool
in
remote_tools
.
items
():
if
tool
.
task
==
task_name
:
HUGGINGFACE_DEFAULT_TOOLS
[
tool_name
]
=
tool
found
=
True
break
if
not
found
:
raise
ValueError
(
f
"
{
task_name
}
is not implemented on the Hub."
)
if
not
is_offline_mode
():
for
task_name
in
HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB
:
found
=
False
for
tool_name
,
tool
in
remote_tools
.
items
():
if
tool
.
task
==
task_name
:
HUGGINGFACE_DEFAULT_TOOLS
[
tool_name
]
=
tool
found
=
True
break
if
not
found
:
raise
ValueError
(
f
"
{
task_name
}
is not implemented on the Hub."
)
_tools_are_initialized
=
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment