Skip to content

Add nnsight login command and notebook helper (#506)#668

Open
EphraiemSarabamoun wants to merge 1 commit into
ndif-team:mainfrom
EphraiemSarabamoun:feat/nnsight-login-command
Open

Add nnsight login command and notebook helper (#506)#668
EphraiemSarabamoun wants to merge 1 commit into
ndif-team:mainfrom
EphraiemSarabamoun:feat/nnsight-login-command

Conversation

@EphraiemSarabamoun

Copy link
Copy Markdown

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 login in a terminal and get prompted for your key, or call from nnsight import login and run login() in a notebook.

How it works

The new src/nnsight/login.py holds a small login helper. When called with no argument it prompts for the key with getpass, so the key is never echoed to the screen. It then persists the key through the existing CONFIG.set_default_api_key, which already writes config.yaml, so future sessions pick the key up automatically. Passing the key directly as login("my-key") skips the prompt, and empty input is a safe no-op that saves nothing.

The same module exposes a main function that backs a new nnsight console command with a login subcommand, built with argparse to match the style of the existing nnsight-serve CLI.

Three edits make this work. The helper lives in src/nnsight/login.py. The package exports it with one new line in src/nnsight/__init__.py so from nnsight import login resolves. A new [project.scripts] section in pyproject.toml registers nnsight = "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 login works. Calling login() with getpass patched to a dummy key updates CONFIG.API.APIKEY and writes that key into config.yaml. Passing the key explicitly persists it too, and whitespace only input leaves the stored key untouched. The console script is registered as a console_scripts entry point, and nnsight --help lists the login subcommand while nnsight login prompts for the key. The change is minimal and the new module is clean under both black and isort.

Usage

$ nnsight login
Enter your NDIF API key:
NDIF API key saved.
from nnsight import login
login()

Closes #506

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alow to login using commandline / in notebook like HF

1 participant