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,