From 0b46f24fb5b39b51c0ec7131561b0ef46e878269 Mon Sep 17 00:00:00 2001 From: Andrew Chang Date: Tue, 14 Nov 2023 17:23:13 +0200 Subject: [PATCH] Backport PR #443: Ensure initials appear in collaborative mode --- packages/jupyter-ai/jupyter_ai/handlers.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/handlers.py b/packages/jupyter-ai/jupyter_ai/handlers.py index 2bba7d876..fcafa10a8 100644 --- a/packages/jupyter-ai/jupyter_ai/handlers.py +++ b/packages/jupyter-ai/jupyter_ai/handlers.py @@ -118,15 +118,19 @@ def get_chat_user(self) -> ChatUser: if collaborative: names = self.current_user.name.split(" ", maxsplit=2) - initials = "".join( - [(name.capitalize()[0] if len(name) > 0 else "") for name in names] - ) + initials = getattr(self.current_user, "initials", None) + if not initials: + # compute default initials in case IdentityProvider doesn't + # return initials, e.g. JupyterHub (#302) + 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), + "initials": initials, } + return ChatUser(**chat_user_kwargs) login = getpass.getuser()