Skip to content

Commit

Permalink
handle IDPs that don't return initials (jupyterlab#316)
Browse files Browse the repository at this point in the history
* handle IDPs that don't return initials

* pre-commit

* use current_user.name for default initials

* capitalize initials
  • Loading branch information
dlqqq authored and Marchlak committed Oct 28, 2024
1 parent 3a3e079 commit 3e998d5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/jupyter-ai/jupyter_ai/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3e998d5

Please sign in to comment.