Add nnsight login command and notebook helper (#506)#668
Open
EphraiemSarabamoun wants to merge 1 commit into
Open
Add nnsight login command and notebook helper (#506)#668EphraiemSarabamoun wants to merge 1 commit into
EphraiemSarabamoun wants to merge 1 commit into
Conversation
Resolves ndif-team#506. Adds a getpass based way to store the NDIF API key, mirroring the HuggingFace login flow. - New src/nnsight/login.py with a login() helper that prompts for the key via getpass and persists it through CONFIG.set_default_api_key, plus a main() console entry point. - Export login from the top level package so 'from nnsight import login' works in a notebook. - Register the 'nnsight' console script in pyproject.toml so 'nnsight login' works from the command line.
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.
What
This resolves #506 by adding a way to store your NDIF API key from the command line or from a notebook, in the same spirit as the HuggingFace login flow.
You can now run
nnsight loginin a terminal and get prompted for your key, or callfrom nnsight import loginand runlogin()in a notebook.How it works
The new
src/nnsight/login.pyholds a smallloginhelper. When called with no argument it prompts for the key withgetpass, so the key is never echoed to the screen. It then persists the key through the existingCONFIG.set_default_api_key, which already writesconfig.yaml, so future sessions pick the key up automatically. Passing the key directly aslogin("my-key")skips the prompt, and empty input is a safe no-op that saves nothing.The same module exposes a
mainfunction that backs a newnnsightconsole command with aloginsubcommand, built withargparseto match the style of the existingnnsight-serveCLI.Three edits make this work. The helper lives in
src/nnsight/login.py. The package exports it with one new line insrc/nnsight/__init__.pysofrom nnsight import loginresolves. A new[project.scripts]section inpyproject.tomlregistersnnsight = "nnsight.login:main", which is the first console script for this package.Verification
I installed the package editable in a clean virtual environment and confirmed the following against the real install. The import
from nnsight import loginworks. Callinglogin()withgetpasspatched to a dummy key updatesCONFIG.API.APIKEYand writes that key intoconfig.yaml. Passing the key explicitly persists it too, and whitespace only input leaves the stored key untouched. The console script is registered as aconsole_scriptsentry point, andnnsight --helplists theloginsubcommand whilennsight loginprompts for the key. The change is minimal and the new module is clean under both black and isort.Usage
Closes #506