Update app.py
Browse files
app.py
CHANGED
@@ -151,9 +151,39 @@ def setup_multiple_chains():
|
|
151 |
)
|
152 |
|
153 |
cl.user_session.set("api_chain", api_chain)
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
-
|
|
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
@cl.on_message
|
158 |
async def handle_message(message: cl.Message):
|
159 |
user_message = message.content
|
@@ -161,6 +191,9 @@ async def handle_message(message: cl.Message):
|
|
161 |
api_chain = cl.user_session.get("api_chain")
|
162 |
|
163 |
# api_keywords = ["firmahytteordning", "personvernspolicy"]
|
|
|
|
|
|
|
164 |
|
165 |
try:
|
166 |
# --check message for booking ID
|
@@ -168,13 +201,13 @@ async def handle_message(message: cl.Message):
|
|
168 |
logging.debug(f"Booking ID detected in message: {user_message}")
|
169 |
response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
170 |
|
171 |
-
# --check message for
|
172 |
-
elif any(keyword in user_message for keyword in ["firmahytteordning", "personvernspolicy"]): # any(keyword in user_message for keyword in api_keywords):
|
173 |
-
logging.debug(f"API keyword detected in message: {user_message}")
|
174 |
-
response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
175 |
|
176 |
else:
|
177 |
-
logging.debug("
|
178 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
179 |
|
180 |
except Exception as e:
|
@@ -185,6 +218,9 @@ async def handle_message(message: cl.Message):
|
|
185 |
await cl.Message(response.get(response_key, "")).send()
|
186 |
return message.content
|
187 |
|
|
|
|
|
|
|
188 |
|
189 |
|
190 |
#def is_booking_query(user_message):
|
|
|
151 |
)
|
152 |
|
153 |
cl.user_session.set("api_chain", api_chain)
|
154 |
+
|
155 |
+
@cl.on_message
|
156 |
+
async def handle_message(message: cl.Message):
|
157 |
+
user_message = message.content
|
158 |
+
llm_chain = cl.user_session.get("llm_chain")
|
159 |
+
api_chain = cl.user_session.get("api_chain")
|
160 |
|
161 |
+
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
162 |
+
base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
163 |
|
164 |
+
try:
|
165 |
+
if re.search(booking_pattern, user_message):
|
166 |
+
booking_id = re.search(booking_pattern, user_message).group(0)
|
167 |
+
logging.debug(f"Booking ID detected: {booking_id}")
|
168 |
+
|
169 |
+
url = f"{base_url}?search={booking_id}"
|
170 |
+
logging.debug(f"Constructed API URL: {url}")
|
171 |
+
|
172 |
+
response = await api_chain.acall({"booking_id": booking_id}, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
173 |
+
else:
|
174 |
+
logging.debug("Triggered LLMChain for <booking-related>")
|
175 |
+
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
176 |
+
|
177 |
+
except Exception as e:
|
178 |
+
logging.error(f"Error in processing message: {str(e)}")
|
179 |
+
response = {"output": "Jeg får desverre ikke fram din informasjon akkurat nå."}
|
180 |
+
|
181 |
+
response_key = "output" if "output" in response else "text"
|
182 |
+
await cl.Message(response.get(response_key, "")).send()
|
183 |
+
return message.content
|
184 |
+
|
185 |
+
|
186 |
+
"""
|
187 |
@cl.on_message
|
188 |
async def handle_message(message: cl.Message):
|
189 |
user_message = message.content
|
|
|
191 |
api_chain = cl.user_session.get("api_chain")
|
192 |
|
193 |
# api_keywords = ["firmahytteordning", "personvernspolicy"]
|
194 |
+
|
195 |
+
#base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
196 |
+
#url = f"{base_url}?search={booking_id}"
|
197 |
|
198 |
try:
|
199 |
# --check message for booking ID
|
|
|
201 |
logging.debug(f"Booking ID detected in message: {user_message}")
|
202 |
response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
203 |
|
204 |
+
# --check message for keywords
|
205 |
+
#elif any(keyword in user_message for keyword in ["firmahytteordning", "personvernspolicy"]): # any(keyword in user_message for keyword in api_keywords):
|
206 |
+
#logging.debug(f"API keyword detected in message: {user_message}")
|
207 |
+
#response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
208 |
|
209 |
else:
|
210 |
+
logging.debug("Triggers LLMChain for everything else.")
|
211 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
212 |
|
213 |
except Exception as e:
|
|
|
218 |
await cl.Message(response.get(response_key, "")).send()
|
219 |
return message.content
|
220 |
|
221 |
+
"""
|
222 |
+
|
223 |
+
|
224 |
|
225 |
|
226 |
#def is_booking_query(user_message):
|