Update app.py
Browse files
app.py
CHANGED
@@ -143,30 +143,26 @@ async def handle_message(message: cl.Message):
|
|
143 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
144 |
base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
question = f"Retrieve information for booking ID {booking_id}"
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
except Exception as e:
|
169 |
-
response = {"output": "Jeg fรฅr desverre ikke fram din informasjon akkurat nรฅ."}
|
170 |
|
171 |
response_key = "output" if "output" in response else "text"
|
172 |
await cl.Message(response.get(response_key, "")).send()
|
|
|
143 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
144 |
base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
145 |
|
146 |
+
if re.search(booking_pattern, user_message):
|
147 |
+
booking_id = re.search(booking_pattern, user_message).group(0)
|
148 |
+
question = f"Retrieve information for booking ID {booking_id}"
|
|
|
149 |
|
150 |
+
url = f"{base_url}?search={booking_id}"
|
151 |
+
|
152 |
+
response = await api_chain.acall(
|
153 |
+
{
|
154 |
+
"booking_id": booking_id,
|
155 |
+
"question": question,
|
156 |
+
"url": url
|
157 |
+
},
|
158 |
+
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
159 |
+
|
160 |
+
else
|
161 |
+
##await cl.Message("Vi kan desverre ikke finne noen informasjon for det oppgitte bookingnummeret.").send()
|
162 |
+
|
163 |
+
#response = await api_chain.acall({"booking_id": booking_id}, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
164 |
+
|
165 |
+
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
|
|
|
|
|
|
166 |
|
167 |
response_key = "output" if "output" in response else "text"
|
168 |
await cl.Message(response.get(response_key, "")).send()
|