Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle IDPs that don't return initials #316

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
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,
dlqqq marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where initials is set to None by the identity provider, this doesn't work. This line should be below the following line.

**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