Update app.py
Browse files
app.py
CHANGED
@@ -198,37 +198,36 @@ async def handle_message(message: cl.Message):
|
|
198 |
#auth_token = f"Bearer {auth_token}
|
199 |
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
"
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
"
|
215 |
-
"booking_id": bestillingskode,
|
216 |
-
},
|
217 |
-
"question": question,
|
218 |
},
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
|
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
|
228 |
# --concurrent execution@ThreadPoolExecutor, resolve the ’Could not reach the server' error?
|
229 |
-
loop = asyncio.get_running_loop()
|
230 |
-
with concurrent.futures.ThreadPoolExecutor() as pool:
|
231 |
-
await loop.run_in_executor(pool, lambda: asyncio.run(process_message()))
|
232 |
|
233 |
|
234 |
|
|
|
198 |
#auth_token = f"Bearer {auth_token}
|
199 |
|
200 |
|
201 |
+
if re.search(booking_pattern, user_message):
|
202 |
+
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
203 |
+
question = f"Retrieve information for booking ID {bestillingskode}"
|
204 |
+
|
205 |
+
response = await api_chain.acall( # ~ainvoke
|
206 |
+
{
|
207 |
+
"url": endpoint_url,
|
208 |
+
"method": "POST",
|
209 |
+
"headers": {
|
210 |
+
"Authorization": f"Bearer {auth_token}",
|
211 |
+
"Content-Type": "application/json",
|
212 |
+
},
|
213 |
+
"body": {
|
214 |
+
"booking_id": bestillingskode,
|
|
|
|
|
|
|
215 |
},
|
216 |
+
"question": question,
|
217 |
+
},
|
218 |
+
callbacks=[cl.AsyncLangchainCallbackHandler()],
|
219 |
+
)
|
220 |
+
else:
|
221 |
+
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
222 |
|
223 |
+
response_key = "output" if "output" in response else "text"
|
224 |
+
await cl.Message(response.get(response_key, "")).send()
|
225 |
+
return message.content
|
226 |
|
227 |
# --concurrent execution@ThreadPoolExecutor, resolve the ’Could not reach the server' error?
|
228 |
+
#loop = asyncio.get_running_loop()
|
229 |
+
#with concurrent.futures.ThreadPoolExecutor() as pool:
|
230 |
+
#await loop.run_in_executor(pool, lambda: asyncio.run(process_message()))
|
231 |
|
232 |
|
233 |
|