-
-
Notifications
You must be signed in to change notification settings - Fork 14
Mention users in messages (using @) #190
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
Conversation
The current implementation creates the user list every time the mention command is requested (typing It seems to be quite reactive with a few users, but may become problematic if a lot of users are involved/connected to the chat. The Maybe we should wait for existing issues before implementing this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brichet Thank you for working on this! This is a huge contribution.
I left some feedback below. Not sure how much of it we want to address in this PR. I think you're in a better position to judge what can / can't be addressed here.
BTW, does this allow typing @Jupyternaut
when Jupyter AI is installed?
python/jupyterlab-chat/src/chat-commands/providers/user-mention.ts
Outdated
Show resolved
Hide resolved
…e any string to a user mention
@dlqqq I added a chat context to the chat input as discussed #190 (comment) The main idea to be able send a context (read-only subset of the chat model) to the chat input. This context is sent only if the |
Yes, Jupyternaut is connected to the chat as a regular user: https://github.com/jupyterlab/jupyter-ai/blob/a82eecc220a032b9bfbef9beb3da900a8bfd4e59/packages/jupyter-ai/jupyter_ai/extension.py#L272 |
IIUC the default rendermime registry has a sanitizer, which doesn't allow The additional span is displayed using the markdown renderer, so it should be sanitized. I did a test and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brichet Love the new chat context! I thought it would be a second argument, but placing it under InputModel
still makes sense & keeps the API smaller. 🤗
I'm not able to give a full review today, but I was able to find an opportunity to simplify the code further. Let me know what you think! 👋
packages/jupyterlab-chat-extension/src/chat-commands/providers/user-mention.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates @brichet! There are still some unsafe type casts being introduced by this branch, and I think we should continue exploring ways to keep the code safe before merging.
/** | ||
* The chat context to be sent to the input model. | ||
*/ | ||
export class LabChatContext extends ChatContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to provide both LabChatContext
and ChatContext
? There are other areas in this branch where we are unsafely casting IChatContext
objects as LabChatContext
to access the users
property defined here. If we require this property, then it doesn't seem to make sense to have the IChatContext
exclude that property.
I recommend that the users
property be added to the IChatContext
interface to remove the type casts. I also suggest we merge ChatContext
and LabChatContext
together, since one interface will only require one implementation. Is this possible? If not, what is the reason for providing 2 implementations in 2 different packages?
Documenting some usability issues I noticed while testing this branch. No need to address these in the same PR, just making a list so we can open an issue later.
|
Thanks @dlqqq for opening it. With this "double" implementation of the
This is why I found it simpler to provide a default For example, the
if (inputModel.chatContext implements ILabChatContext): |
@brichet JupyterLite can either just return an empty array or an array with one item describing the current user. For example: class LiteChatContext extends AbstractChatContext implements IChatContext {
/**
* The list of users who have connected to this chat.
*/
get users(): IUser[] {
return []; // or, return a one-item array like [this.user]
}
} Even though it doesn't seem like JupyterLite needs to implement |
Add suggested changes from review of PR 190
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🎉 🎉 Thank you! We can revert some of the changes concerning chat context later, if we find a better way to provide a list of users to chat commands.
This PR allows to mention users in messages.
Fixes #184
record-2025-03-20_10.55.07.webm
General workflow
@username
in the input.@username
) is replaced by a span to add style on it.Some details on the changes
IChatCommandProvider
methods receive also theChatModel
in arguments. It's required to find the users of the chat.IUser
interface has now an optional attributemention_name
(string), used to find the mention in the message and to replace it with the span on the fly.mention_name
, for a better user experience.user_mention
in real time. Therefore, when the message is sent (or updated), the mention list of the input is checked to make sure that the message still contains themention_name
.