mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
21.71k stars 1.98k forks source link

Add support to pass Callback Handlers #1285

Open ramnathv opened 6 months ago

ramnathv commented 6 months ago

🚀 The feature

Langchain supports callbacks to be passed to the function invoking the LLM. Support passing these to Langchain.

Motivation, pitch

This allows tools like Chainlit to display step by step outputs.

@cl.on_message
async def on_message(message: cl.Message):
    runnable = cl.user_session.get("runnable")  # type: Runnable

    msg = cl.Message(content="")

    async for chunk in runnable.astream(
        {"question": message.content},
        config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
    ):
        await msg.stream_token(chunk)

    await msg.send()
deshraj commented 6 months ago

Thank you for opening this issue, @ramnathv! We're looking into it. 🌟

If you're interested, we'd welcome your contribution on this. Feel free to ask for any guidance you need.

Happy coding! 🚀