Skip to content

Commit

Permalink
Backport #316 to 1.x (#318)
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 Aug 4, 2023
1 parent e80b5e5 commit 68f28ba
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 @@ -112,12 +112,23 @@ def get_chat_user(self) -> ChatUser:
collaborative = self.config.get("LabApp", {}).get("collaborative", False)

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 68f28ba

Please sign in to comment.