S
Solara•11mo ago
Exodia

Communicate with app from a different file

Hello, What would be the best way to call my solara app from another? I need be able lto launch or connect to update the webapp from another library, hence need to be able to launch and call it in a modular manner. Does anyone know the best way to do this? E. G. chat_ui() # create solara app message = <other package> chat_ui.send_message(message) response = chat_ui.get_response() # wait till user sends response then retrieve it as str Appreicate your help!
9 Replies
MaartenBreddels
MaartenBreddels•11mo ago
Hi, could you elaborate a bit more (also I'm interested in understanding what you want to make). How do you envision multiple browser tabs connecting to solara. It would be easier to do it the other way around (call your library from a solara component), but maybe you can convince me it has to be done this way 🙂
Exodia
ExodiaOP•11mo ago
Hey Maarten, So in this case I wouldn't have multiple browser tabs. It would act as a simple UI interface on a much larger system. More context: Unfortunately the requirement to use it as follows hasn't been set by me, , since I'll need it to be portable into various parts of a larger system, rather than have it act as an entry point.
I need to be able to write a line of code like user_input: str = chat_app.get() that blocks execution of some test until a user of the UI enters a prompt and sends it to chat. When it happens, the user's promot gets recorded in user_input variable as string, Previous solution: For example, I previously used a websocket data server and nicegui client, so that the server could make data available to the UI as in the example above, through a websocket the UI would use to update itself with, but explicitly handling async and websocket reconnections is proving to be to much trouble. Some additional reasons I chose Solara as a potential solution - as I move to a microservice Arch, it seems like a good candidate to ingest a Kafka topic for live streaming - built in async support - good examples with very similar use cases https://github.com/widgetti/wanderlust
GitHub
GitHub - widgetti/wanderlust: Wanderlust OpenAI example using Solara
Wanderlust OpenAI example using Solara. Contribute to widgetti/wanderlust development by creating an account on GitHub.
Exodia
ExodiaOP•11mo ago
TLDR So due to business requirements, I need to be able to import, create and launch a solara chat ui app, as well as interact with it through its instantiated object (E. G. By sending or receiving data in a potentially blocking manner) But perhaps there's another library better suited for all this? Any idea?
MaartenBreddels
MaartenBreddels•11mo ago
it's using some undocumented api, but maybe this helps: I've included comments to explain what is going on, let me know if this solves your problem or not
MaartenBreddels
MaartenBreddels•11mo ago
the reason we'se using the HasTraits object, is that we need something observable that is not scoped to a kernel (like reactive variables). In the future we plan to support other scopes, so you could do this with reactive variables.
Exodia
ExodiaOP•11mo ago
Thanks a lot! will dig into this today So it's quite close to the functionality we desire I think. I'd await the two async functions from an external test to achieve the get functionality I would create a traitless object I assume for both the user and system inputs, recording them all. But I think by default traitless observes any change, is there a way to tie this into an IconButton? So that only when the user hits submit changes are observed Here is the code I currently have based of a chat bot in solara example to help clarify
Exodia
ExodiaOP•11mo ago
MaartenBreddels
MaartenBreddels•11mo ago
you could add a clicks trait and increase that on every button click, does that make sense?
Exodia
ExodiaOP•11mo ago
Yes I think that makes sense, I'd add a new trait class and have 'on_submit' inside the button update it somehow
Want results from more Discord servers?
Add your server