camparchimedes commited on
Commit
4e02251
ยท
verified ยท
1 Parent(s): 2b8e181

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -176,31 +176,38 @@ async def handle_message(message: cl.Message):
176
  "url": endpoint_url,
177
  "body": {
178
  "booking_id": bestillingskode
 
179
  }
180
- }
181
 
182
  response = await post_tool.arun(
183
  json.dumps(post_data),
184
  callbacks=[cl.AsyncLangchainCallbackHandler()]
185
  )
186
 
 
 
 
187
  if response:
188
-
189
- booking_data = json.loads(response)
190
- booking_data = f"""
191
- | Field | Value |
192
- |-------|--------|
193
- | Booking ID | {booking_data['booking_id']} |
194
- | Name | {booking_data['full_name']} |
195
- | Amount | {booking_data['amount']} kr |
196
- | Check-in | {booking_data['checkin']} |
197
- | Check-out | {booking_data['checkout']} |
198
- | Address | {booking_data['address']} |
199
- | User ID | {booking_data['user_id']} |
200
- | Info | {booking_data['infotext']} |
201
- | Included | {booking_data['included']} |
202
- """
203
- await cl.Message(booking_data).send()
 
 
 
 
204
 
205
  else:
206
  response = await llm_chain.ainvoke(
 
176
  "url": endpoint_url,
177
  "body": {
178
  "booking_id": bestillingskode
179
+ }
180
  }
 
181
 
182
  response = await post_tool.arun(
183
  json.dumps(post_data),
184
  callbacks=[cl.AsyncLangchainCallbackHandler()]
185
  )
186
 
187
+ # --degug!
188
+ print(f"Raw response: {response}")
189
+
190
  if response:
191
+ try:
192
+ booking_data = json.loads(response)
193
+
194
+ booking_data = f"""
195
+ | Field | Value |
196
+ |-------|--------|
197
+ | Booking ID | {booking_data.get('booking_id', 'N/A')} |
198
+ | Name | {booking_data.get('full_name', 'N/A')} |
199
+ | Amount | {booking_data.get('amount', 'N/A')} kr |
200
+ | Check-in | {booking_data.get('checkin', 'N/A')} |
201
+ | Check-out | {booking_data.get('checkout', 'N/A')} |
202
+ | Address | {booking_data.get('address', 'N/A')} |
203
+ | User ID | {booking_data.get('user_id', 'N/A')} |
204
+ | Info | {booking_data.get('infotext', 'N/A')} |
205
+ | Included | {booking_data.get('included', 'N/A')} |
206
+ """
207
+ await cl.Message(booking_data).send()
208
+
209
+ except json.JSONDecodeError:
210
+ await cl.Message(f"Error: Non-JSON response received. Raw response: {response}").send()
211
 
212
  else:
213
  response = await llm_chain.ainvoke(