File size: 678 Bytes
220a7fc
393e1ec
220a7fc
 
 
0f4ecd0
67bc0df
 
 
0f4ecd0
 
220a7fc
 
7a9f5c9
d40a83a
393e1ec
d40a83a
0f4ecd0
 
4e948c7
0f4ecd0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import chainlit as cl
from extract_app import extract_information


@cl.on_chat_start
async def start():
    """
    This is called when the Chainlit chat is started!
    """
    cl.user_session.set("chain", extract_information())
    await cl.Message("Welcome to the information extraction chat!").send()

@cl.on_message
async def main(message: cl.Message):
    """
    This is called when a message is received!
    """
    chain = cl.user_session.get("chain")
    res = await chain.ainvoke({"input": message})
    res = res["text"]
    out = "Name \tAge\n" + ''.join(
        [f"{person.name}\t{person.age}\n" for person in res]
    )
    await cl.Message(content=out).send()