cmagganas commited on
Commit
0f4ecd0
1 Parent(s): 4e948c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -3,22 +3,22 @@ from extract_app import extract_information
3
 
4
 
5
  @cl.on_chat_start
6
- def start():
7
  """
8
  This is called when the Chainlit chat is started!
9
  """
10
- cl.Message("Welcome to the information extraction chat!").send()
 
11
 
12
  @cl.on_message
13
  async def main(message: cl.Message):
14
  """
15
  This is called when a message is received!
16
  """
17
- # res = await extract_information().ainvoke({"input": message})["text"]
18
- res = await extract_information().ainvoke({"input": message})
19
  res = res["text"]
20
-
21
- # res = await cl.make_async(extract_information().invoke)(
22
- # input=message.content, callbacks=[cl.LangchainCallbackHandler()]
23
- # )
24
- await cl.Message(content=res).send()
 
3
 
4
 
5
  @cl.on_chat_start
6
+ async def start():
7
  """
8
  This is called when the Chainlit chat is started!
9
  """
10
+ cl.user_session.set("chain", extract_information())
11
+ await cl.Message("Welcome to the information extraction chat!").send()
12
 
13
  @cl.on_message
14
  async def main(message: cl.Message):
15
  """
16
  This is called when a message is received!
17
  """
18
+ chain = cl.user_session.get("chain")
19
+ res = await chain.ainvoke({"input": message})
20
  res = res["text"]
21
+ out = "Name \tAge\n" + ''.join(
22
+ [f"{person.name}\t{person.age}\n" for person in res]
23
+ )
24
+ await cl.Message(content=out).send()