Chainlit / chainlit

Build Conversational AI in minutes ⚡️
https://docs.chainlit.io
Apache License 2.0
7.24k stars 955 forks source link

Send/Stream messages from multiple different processes #1491

Closed MohMaz closed 3 weeks ago

MohMaz commented 3 weeks ago

Is your feature request related to a problem? Please describe. It's a feature that might already be supported somehow.

Describe the solution you'd like I want to have the UI run on one server, and be able to send/stream messages to it from two or more processes (e.g. VMs). I'm trying to integrate chainlit with a Autogen distributed group chat sample

Describe alternatives you've considered N/A

Additional context N/A

dokterbob commented 3 weeks ago

You would probably run chainlit as usual, then forward messages from your VM's to chainlit. So like a normal chainlit app. I.e. it does not require any changes in functionality on chainlit's side.

Does that make sense? If not, feel free to reopen.

MohMaz commented 3 weeks ago

You would probably run chainlit as usual, then forward messages from your VM's to chainlit. So like a normal chainlit app. I.e. it does not require any changes in functionality on chainlit's side.

Thanks for the reply. I'm not sure about how to forward, I was hoping to be able to get a client-ish connected to the server. So if I do this code in two different python files and run with chainlit command, it tried to spin up the server twice and get port binding error.

@cl.on_chat_start  # type: ignore
async def start_chat():
    asyncio.run(main())

If in the second app I just do:

import chainlit as cl
await cl.Message("Hello!").send()

I get an error that context is not properly initialized. I tried to use the functions in chainlit.context like init_* or get_context, but wasn't able to make it work.

So was hoping to get a sample code on to connect.

dokterbob commented 3 weeks ago

User agent (browser) <- (client) Chainlit API (socket.io events over WebSocket) (server) -> Chainlit backend <- (client) custom API (could use parts of Chainlit API) (server) -> Execution backend

So you'd create a FastAPI server within your DMZ which then your Chainlit backend connects to. Some GRPC protocol or maybe just a subset of the Chainlit streaming API.

If you need more support with specific architecture, that's what I do as a freelance consultant -- so beyond the scope of Chainlit maintenance.

dokterbob commented 3 weeks ago

1481 seems related.