camparchimedes commited on
Commit
a4fe116
ยท
verified ยท
1 Parent(s): d7c6c42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -102,6 +102,20 @@ def setup_multiple_chains():
102
  cl.user_session.set("api_chain", api_chain)
103
 
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  # --wrapper function around the @cl.on_message decorator; chain trigger(s)
106
  @cl.on_message
107
  async def handle_message(message: cl.Message):
@@ -109,18 +123,20 @@ async def handle_message(message: cl.Message):
109
  llm_chain = cl.user_session.get("llm_chain")
110
  api_chain = cl.user_session.get("api_chain")
111
 
112
- if any(keyword in user_message for keyword in ["booking_id", "full_name", "amount", # + "bestillingsnummer", "checkin", "checkout" for api_docs
113
- "date", "address", "amount", "user_id"]):
114
- # --if any keywords in user_message, use api_chain
 
 
 
115
  response = await api_chain.acall(user_message,
116
  callbacks=[cl.AsyncLangchainCallbackHandler()])
117
  else:
118
- # --defaults to llm_chain4general queries
119
  response = await llm_chain.acall(user_message,
120
  callbacks=[cl.AsyncLangchainCallbackHandler()])
 
121
  response_key = "output" if "output" in response else "text"
122
  await cl.Message(response.get(response_key, "")).send()
123
  return message.content
124
 
125
 
126
-
 
102
  cl.user_session.set("api_chain", api_chain)
103
 
104
 
105
+ # --regex for alphanum. "LLLLLLxxxxxx", i.e. booking_id |==> 308.9 trillion unique possibilities
106
+ BOOKING_ID = r'\b[A-Z]{6}\d{6}\b'
107
+
108
+ # TODO: add all booking-related keywords from JSON data
109
+ BOOKING_KEYWORDS = [
110
+ "booking", "bestilling", "bestillingsnummer",
111
+ "booking_id", "booking ID","booking nummer",
112
+ "navn", "etternavn", "kunde", "customer",
113
+ "utestรฅende belรธp", "faktura", "cost", "price",
114
+ "date", "dato", "checkin", "checkout",
115
+ "address", "adresse", "user id", "bruker_id", "bruker id",
116
+ ]
117
+
118
+
119
  # --wrapper function around the @cl.on_message decorator; chain trigger(s)
120
  @cl.on_message
121
  async def handle_message(message: cl.Message):
 
123
  llm_chain = cl.user_session.get("llm_chain")
124
  api_chain = cl.user_session.get("api_chain")
125
 
126
+ is_booking_query = any(
127
+ re.search(keyword, user_message, re.IGNORECASE)
128
+ for keyword in BOOKING_KEYWORDS + [BOOKING_ID]
129
+ )
130
+
131
+ if is_booking_query:
132
  response = await api_chain.acall(user_message,
133
  callbacks=[cl.AsyncLangchainCallbackHandler()])
134
  else:
 
135
  response = await llm_chain.acall(user_message,
136
  callbacks=[cl.AsyncLangchainCallbackHandler()])
137
+
138
  response_key = "output" if "output" in response else "text"
139
  await cl.Message(response.get(response_key, "")).send()
140
  return message.content
141
 
142