Skip to content

Build and run agents you can see, understand and trust.

add huggingface endpoint fix (#1340)

garyzhang99c19b8bc5723e
diff --git a/src/agentscope/token/_huggingface_token_counter.py b/src/agentscope/token/_huggingface_token_counter.py
index 96b3317d6..7cb2661cf 100644
--- a/src/agentscope/token/_huggingface_token_counter.py
+++ b/src/agentscope/token/_huggingface_token_counter.py
@@ -35,7 +35,17 @@ class HuggingFaceTokenCounter(TokenCounterBase):
tokenizer.
"""
if use_mirror:
- os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
+ mirror = "https://hf-mirror.com"
+ os.environ["HF_ENDPOINT"] = mirror
+
+ # if the huggingface is already imported in other dependencies,
+ # we need to set the endpoint manually
+ import huggingface_hub.constants
+
+ huggingface_hub.constants.ENDPOINT = mirror
+ huggingface_hub.constants.HUGGINGFACE_CO_URL_TEMPLATE = (
+ mirror + "/{repo_id}/resolve/{revision}/{filename}"
+ )
from transformers import AutoTokenizer