Skip to content

Commit 68f28ba

Browse files
authored
Backport #316 to 1.x (#318)
* handle IDPs that don't return initials * pre-commit * use current_user.name for default initials * capitalize initials
1 parent e80b5e5 commit 68f28ba

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/jupyter-ai/jupyter_ai/handlers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,23 @@ def get_chat_user(self) -> ChatUser:
112112
collaborative = self.config.get("LabApp", {}).get("collaborative", False)
113113

114114
if collaborative:
115-
return ChatUser(**asdict(self.current_user))
115+
names = self.current_user.name.split(" ", maxsplit=2)
116+
initials = "".join(
117+
[(name.capitalize()[0] if len(name) > 0 else "") for name in names]
118+
)
119+
chat_user_kwargs = {
120+
# set in case IdentityProvider doesn't return initials, e.g.
121+
# JupyterHub (#302)
122+
"initials": initials,
123+
**asdict(self.current_user),
124+
}
125+
return ChatUser(**chat_user_kwargs)
116126

117127
login = getpass.getuser()
128+
initials = login[0].capitalize()
118129
return ChatUser(
119130
username=login,
120-
initials=login[0].capitalize(),
131+
initials=initials,
121132
name=login,
122133
display_name=login,
123134
color=None,

0 commit comments

Comments
 (0)