Nitish-py commited on
Commit
1c2c36a
β€’
1 Parent(s): 1d03ff3

comparison option

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -13,7 +13,8 @@ def indexing(llm,path):
13
  query_engine = index.as_query_engine()
14
  cl.user_session.set("engine", query_engine)
15
 
16
- def qa(sp,engine,message):
 
17
  message=message.content
18
  ques=sp+" "+message
19
  response=engine.query(ques)
@@ -47,13 +48,14 @@ async def factory():
47
 
48
  else:
49
  await cl.Message(author="Beast",content="Okay, then you can start asking your questions!!").send()
 
50
 
51
  @cl.on_message
52
  async def main(message: cl.Message):
53
  service_client=cl.user_session.get("service_client")
54
  engine = cl.user_session.get("engine")
55
  llm=cl.user_session.get("llm")
56
- sp=cl.user_session.get("sp")
57
 
58
  if sp==None:
59
  sp=""
@@ -70,25 +72,39 @@ async def main(message: cl.Message):
70
  if go:
71
  msg = cl.Message(author="Beast",content=f"Processing `{pdf.name}`...")
72
  await msg.send()
73
- query_engine = await cl.make_async(indexing)(llm,pdf.path)
74
  msg.content = f"`{pdf.name}` processed."
75
  await msg.update()
76
  msg = cl.Message(author="Beast",content=f"Generating Response...")
77
  await msg.send()
78
- response =await cl.make_async(qa)(sp,query_engine,message)
79
  print(response)
80
  msg.content = str(response)
81
  await msg.update()
 
 
 
 
 
 
 
82
 
83
  elif not message.elements and engine!=None:
84
  msg = cl.Message(author="Beast",content=f"Generating Response...")
85
  await msg.send()
86
- response =await cl.make_async(qa)(sp,engine,message)
87
  print(response)
88
  msg.content = str(response)
89
  await msg.update()
 
 
 
 
 
 
 
90
 
91
- elif not message.elements and engine==None:
92
  msg = cl.Message(author="Beast",content=f"Generating Response...")
93
  await msg.send()
94
  payload = {
@@ -103,8 +119,4 @@ async def main(message: cl.Message):
103
  await msg.update()
104
 
105
  else:
106
- cl.Message(author="Beast",content="Broken ;(")
107
-
108
-
109
-
110
-
 
13
  query_engine = index.as_query_engine()
14
  cl.user_session.set("engine", query_engine)
15
 
16
+ def qa(sp,message):
17
+ engine=cl.user_session.get("engine")
18
  message=message.content
19
  ques=sp+" "+message
20
  response=engine.query(ques)
 
48
 
49
  else:
50
  await cl.Message(author="Beast",content="Okay, then you can start asking your questions!!").send()
51
+
52
 
53
  @cl.on_message
54
  async def main(message: cl.Message):
55
  service_client=cl.user_session.get("service_client")
56
  engine = cl.user_session.get("engine")
57
  llm=cl.user_session.get("llm")
58
+ sp=cl.user_session.get("sp")
59
 
60
  if sp==None:
61
  sp=""
 
72
  if go:
73
  msg = cl.Message(author="Beast",content=f"Processing `{pdf.name}`...")
74
  await msg.send()
75
+ await cl.make_async(indexing)(llm,pdf.path)
76
  msg.content = f"`{pdf.name}` processed."
77
  await msg.update()
78
  msg = cl.Message(author="Beast",content=f"Generating Response...")
79
  await msg.send()
80
+ response =await cl.make_async(qa)(sp,message)
81
  print(response)
82
  msg.content = str(response)
83
  await msg.update()
84
+ comp = await cl.AskActionMessage(author="Beast",
85
+ content="Do you want answer without RAG?",
86
+ actions=[
87
+ cl.Action(name="yes", value="yes", label="βœ… Yes"),
88
+ cl.Action(name="no", value="no", label="❌ No"),
89
+ ],
90
+ ).send()
91
 
92
  elif not message.elements and engine!=None:
93
  msg = cl.Message(author="Beast",content=f"Generating Response...")
94
  await msg.send()
95
+ response =await cl.make_async(qa)(sp,message)
96
  print(response)
97
  msg.content = str(response)
98
  await msg.update()
99
+ comp = await cl.AskActionMessage(author="Beast",
100
+ content="Do you want answer without RAG?",
101
+ actions=[
102
+ cl.Action(name="yes", value="yes", label="βœ… Yes"),
103
+ cl.Action(name="no", value="no", label="❌ No"),
104
+ ],
105
+ ).send()
106
 
107
+ if (not message.elements and engine==None) or (comp.get("value") == "yes"):
108
  msg = cl.Message(author="Beast",content=f"Generating Response...")
109
  await msg.send()
110
  payload = {
 
119
  await msg.update()
120
 
121
  else:
122
+ cl.Message(author="Beast",content="Broken ;(")