From 1689e7f2de12a56617035901b995543ad7fa0347 Mon Sep 17 00:00:00 2001 From: david qiu Date: Fri, 4 Aug 2023 09:18:44 -0700 Subject: [PATCH] handle IDPs that don't return initials (#316) * handle IDPs that don't return initials * pre-commit * use current_user.name for default initials * capitalize initials --- packages/jupyter-ai/jupyter_ai/handlers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/handlers.py b/packages/jupyter-ai/jupyter_ai/handlers.py index 1daa78b32..1f85ff31f 100644 --- a/packages/jupyter-ai/jupyter_ai/handlers.py +++ b/packages/jupyter-ai/jupyter_ai/handlers.py @@ -115,12 +115,23 @@ def get_chat_user(self) -> ChatUser: ) if collaborative: - return ChatUser(**asdict(self.current_user)) + names = self.current_user.name.split(" ", maxsplit=2) + initials = "".join( + [(name.capitalize()[0] if len(name) > 0 else "") for name in names] + ) + chat_user_kwargs = { + # set in case IdentityProvider doesn't return initials, e.g. + # JupyterHub (#302) + "initials": initials, + **asdict(self.current_user), + } + return ChatUser(**chat_user_kwargs) login = getpass.getuser() + initials = login[0].capitalize() return ChatUser( username=login, - initials=login[0].capitalize(), + initials=initials, name=login, display_name=login, color=None,