File size: 662 Bytes
2e5aca2 42cef40 2e5aca2 42cef40 2e5aca2 2fc16c3 2e5aca2 2fc16c3 2e5aca2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os
import chainlit as cl
from dotenv import load_dotenv
from graph import create_graph
from langchain_core.runnables import RunnableConfig
from starters import set_starters
load_dotenv()
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
graph = create_graph()
@cl.on_message
async def main(message: cl.Message):
"""
This function will be called every time a message is recieved from a session.
"""
msg = cl.Message(content="")
res = graph.invoke(
{"question": message.content},
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
)
msg.content = res["generation"].content
await msg.send()
|