Skip to content

Commit

Permalink
Ensure initials appear in collaborative mode (#443)
Browse files Browse the repository at this point in the history
* Ensure initials appear in collaborative mode

* Set default initials and use instead of null current_user attr

* Black format to avoid pre-commit failure

* Getattr does not return default because initials attr still exists even though it's None

* optimize and set to one initial var
  • Loading branch information
aychang95 authored Nov 14, 2023
1 parent a710af8 commit 51a1e5a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/jupyter-ai/jupyter_ai/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,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()
Expand Down

0 comments on commit 51a1e5a

Please sign in to comment.