-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Copilot: Collect metadata and add to message before sending #2533
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
base: main
Are you sure you want to change the base?
Copilot: Collect metadata and add to message before sending #2533
Conversation
FYI previously we'd been using @cl.on_message
async def main(message: cl.Message):
if cl.context.session.client_type == "copilot":
print("Copilot detected.")
# Check for received system message that tells us to use guidance
# from the chainlit widget copilot. This just sets the session state
# and awaits a user message to process the query.
if message.type == "system_message":
# Store guidance metadata in the user session
cl.user_session.set(SESS_CLIENT_STATE, message.metadata)
print(f"Setting Client App State via system message: {message.metadata}")
# Don't show the message to the user, this is a system message
await message.remove()
return
# Determine guidance source and extract questionnaire information
print(f"Fetching Client App State from user session: {cl.user_session.get(SESS_CLIENT_STATE)}")
copilot_guidance = cl.user_session.get(SESS_CLIENT_STATE)
# Update the prompts for different questions But as we could not listen for amount event this meant the first question asked by a user could not be preceded by setting this metadata. |
@profpylons Could you elaborate a bit? I think the docs are talking about |
With an iFrame, yes, that seems to be the way. Using the copilot. the docs recommend system_message. There are two drawbacks to this message sending.
I considered adding an event to fire when the copilot is mounted. But this just requires extra plumbing and tracking in the client app. In any case, I think it is still a good idea to send the state in metadata rather than the with This led me to here: Keep the necessary state locally in the widget and pass it with each
|
This PR is stale because it has been open for 14 days with no activity. |
Allow copilot clients to send contextual information with a message about the state of the client.
eg.
The function
setChainlitMetadata()
is available before the widget is mounted in order that the first question asked has the state/metadata available immediately. This bypasses the difficulty of listening for when the widget is mounted.In the backend this can read out and used to format queries to the downstream LLM