Skip to content

Automate browser based workflows with AI

make token counter request optional (#4489)

Shuchang Zheng10e2dabb8b48
diff --git a/skyvern/utils/token_counter.py b/skyvern/utils/token_counter.py
index 4e3aaa5d5..d9c6abc1e 100644
--- a/skyvern/utils/token_counter.py
+++ b/skyvern/utils/token_counter.py
@@ -2,4 +2,10 @@ import tiktoken
def count_tokens(text: str) -> int:
- return len(tiktoken.encoding_for_model("gpt-4o").encode(text))
+ """
+ tiktoken sends a request to https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken to get the token
+ """
+ try:
+ return len(tiktoken.encoding_for_model("gpt-4o").encode(text))
+ except Exception:
+ return 0