fix(cache): respect TIKTOKEN_OFFLINE env var to prevent network downloads#527
Open
xodn348 wants to merge 1 commit intoopenai:mainfrom
Open
fix(cache): respect TIKTOKEN_OFFLINE env var to prevent network downloads#527xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348 wants to merge 1 commit intoopenai:mainfrom
Conversation
…oads (openai#513) When TIKTOKEN_OFFLINE is set and a cache miss occurs, tiktoken now raises a ValueError instead of silently attempting a network download. This allows users in air-gapped or offline environments to get a clear error message directing them to pre-populate the cache. TIKTOKEN_CACHE_DIR was already respected; this commit adds the missing TIKTOKEN_OFFLINE guard before the read_file() network call. Closes openai#513
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #513
When
TIKTOKEN_OFFLINEis set and a required file is not found in the cache, tiktoken previously ignored the env var and silently attempted a network download. This PR adds a guard that raises a clearValueErrorbefore theread_file()network call, directing users to pre-populate the cache or setTIKTOKEN_CACHE_DIR.Changes
tiktoken/load.py: AddedTIKTOKEN_OFFLINEcheck inread_file_cached()before the network download path. When the env var is set and the file is missing from cache, aValueErroris raised with an actionable error message.Behavior
TIKTOKEN_OFFLINEset, file cachedTIKTOKEN_OFFLINEset, file NOT cachedValueErrorwith clear messageTIKTOKEN_OFFLINEnot setTIKTOKEN_CACHE_DIRsetTesting
All 33 existing tests pass.