Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option TIKTOKEN_FORCE_CACHE #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tiktoken/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def read_file_cached(blobpath: str) -> bytes:
if os.path.exists(cache_path):
with open(cache_path, "rb") as f:
return f.read()

elif os.environ.get("TIKTOKEN_FORCE_CACHE") == "1":
Copy link

@jd jd Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or TIKTOKEN_DISALLOW_DOWNLOAD?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, why not. I will let the maintainers decide.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my pov, this should be passed via the library API not an os.environ.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to keep the spirit of the function that uses os.environ to retrieve the cache_dir

raise FileNotFoundError(f"Cache for: {blobpath} not found in tiktoken cache dir: {cache_dir}")

contents = read_file(blobpath)

os.makedirs(cache_dir, exist_ok=True)
Expand Down