chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

Add Callback for Command autocomplete

Open eiseleMichael opened this issue 9 months ago • 2 comments

When starting a /command there should be a way to listen to it on the server and provide completions for it. These completions could then be used in the frontend to guide the user

A possible solution might look like this:


@cl.on_command_autocomplete
async def on_command_autocomplete(msg: cl.Message) -> list[str] | None:
     if msg.command == "list_languages":
          languages = ["javascript", "python","typescript", "go", "rust"]
          return [lang for lang in languages if lang.startswith(msg.content)
     return None

eiseleMichael avatar Jul 22 '25 11:07 eiseleMichael

Just type a slash / in the message input and the auto complete popup is displayed

hayescode avatar Jul 22 '25 23:07 hayescode

Thanks for the fast reply @hayescode and sorry for the confusion - I'm not talking about autocompleting the commands (in my example "/list_languages") but the message that comes after it.

My inspiration for this comes from the MCP spec for completions: https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/completion#message-flow and ChatGPT's suggestions:

Image

So maybe Command Suggestions would be a more appropriate term?

eiseleMichael avatar Jul 23 '25 06:07 eiseleMichael