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: Require login #17

Merged
merged 4 commits into from
Jul 2, 2024
Merged

feat: Require login #17

merged 4 commits into from
Jul 2, 2024

Conversation

KevinJBoyer
Copy link
Contributor

@KevinJBoyer KevinJBoyer commented Jul 2, 2024

Ticket

https://navalabs.atlassian.net/browse/DST-234

Changes

  • Add shared.py so code isn't reconstructing expensive instances like AppConfig or SentenceTransformer unnecessarily. Maybe a better name would be shared.py?
  • Add login.py that adds a login page when GLOBAL_PASSWORD and CHAINLIT_AUTH_SECRET are set

Context for reviewers

  • This automatically integrates with LiteralAI for tracking by the email field -- see screenshot below

Testing

For local testing, set GLOBAL_PASSWORD and CHAINLIT_AUTH_SECRET in your .env and restart the app (make start). You may want to use incognito windows to avoid clearing your cookies each time.

Screenshot showing integration with LiteralAI (when this API key is also set):
Screenshot 2024-07-02 at 11 12 05 AM

Comment on lines -34 to -39
############################
# Authentication
############################
# The auth token used by the local endpoints
API_AUTH_TOKEN=LOCAL_AUTH_12345678

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is leftover from the Flask API code we imported, deleted it to avoid any confusion.

app/src/app_config.py Outdated Show resolved Hide resolved
@KevinJBoyer KevinJBoyer requested a review from a team July 2, 2024 15:25
app/src/cache.py Outdated Show resolved Hide resolved
app/src/cache.py Outdated Show resolved Hide resolved
app/src/cache.py Outdated


def get_appconfig() -> AppConfig:
global _app_config
Copy link
Contributor

Choose a reason for hiding this comment

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

To facilitate testing, consider minimizing use of global by encapsulating globals in an object. Plus you can use @cached_property (like this) or @property to reduce the boilerplate code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL about the built in cache decorators-- updated the code to use this!

app/src/app_config.py Outdated Show resolved Hide resolved
def test_require_login_no_password(monkeypatch):
if "GLOBAL_PASSWORD" in os.environ:
monkeypatch.delenv("GLOBAL_PASSWORD")
src.cache._app_config = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Unclear why this line is needed without examining the code. This is probably an artifact of using global variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment to the first instance of this in the file!

monkeypatch.delenv("GLOBAL_PASSWORD")
src.cache._app_config = None

require_login()
Copy link
Contributor

Choose a reason for hiding this comment

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

Arguably, this could be replaced with something like app.init(), which would call require_login(). Depends on what you want to demonstrate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, ideally I'd like to have some kind of integration test of chainlit.py. Maybe a future improvement?

@KevinJBoyer KevinJBoyer requested a review from yoomlam July 2, 2024 17:08
@KevinJBoyer KevinJBoyer merged commit cae05e6 into main Jul 2, 2024
10 checks passed
@KevinJBoyer KevinJBoyer deleted the kb/login branch July 2, 2024 17:40
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.

2 participants