camparchimedes commited on
Commit
51ebcc7
·
verified ·
1 Parent(s): 31db2b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -198,37 +198,36 @@ async def handle_message(message: cl.Message):
198
  #auth_token = f"Bearer {auth_token}
199
 
200
 
201
- async def process_message():
202
- if re.search(booking_pattern, user_message):
203
- bestillingskode = re.search(booking_pattern, user_message).group(0)
204
- question = f"Retrieve information for booking ID {bestillingskode}"
205
-
206
- response = await api_chain.acall( # ~ainvoke
207
- {
208
- "url": endpoint_url,
209
- "method": "POST",
210
- "headers": {
211
- "Authorization": f"Bearer {auth_token}",
212
- "Content-Type": "application/json",
213
- },
214
- "body": {
215
- "booking_id": bestillingskode,
216
- },
217
- "question": question,
218
  },
219
- callbacks=[cl.AsyncLangchainCallbackHandler()],
220
- )
221
- else:
222
- response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
 
 
223
 
224
- response_key = "output" if "output" in response else "text"
225
- await cl.Message(response.get(response_key, "")).send()
226
- return message.content
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