camparchimedes commited on
Commit
b18743f
ยท
verified ยท
1 Parent(s): 6c03605

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -25
app.py CHANGED
@@ -1,12 +1,7 @@
1
  # ===================================================
2
- # "the-very-latest-latest-POST-it"-----app.pyโœ๐Ÿฝ ๐Ÿ‘พ
3
  # ===================================================
4
- """
5
- Change from APIChain to EnhancedRequestsPostTool was heisted by the need to handle POST requests.
6
- APIChain internally was responsible for URL construction, API interaction, and response formatting:
7
- EnhancedRequestsPostTool is an enabler for POST handling@RequestsPostTool.
8
- Routing mechanisms for prompts (api_url_prompt+api_response_prompt) remain are being used across distinct components.
9
- """
10
  import asyncio
11
  import os
12
  import re
@@ -189,25 +184,32 @@ async def handle_message(message: cl.Message):
189
 
190
  if response:
191
  try:
192
- booking_data = json.loads(response)
193
-
194
- table = 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(table).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(
 
1
  # ===================================================
2
+ # "the-very-latest-latest-POST-it"-----app.py
3
  # ===================================================
4
+
 
 
 
 
 
5
  import asyncio
6
  import os
7
  import re
 
184
 
185
  if response:
186
  try:
187
+ booking_data = json.loads(response)
188
+ table = "| Field | Information |\n|---|---|\n"
189
+
190
+ # Add each field with proper formatting
191
+ fields_mapping = [
192
+ ('booking_id', 'Booking ID'),
193
+ ('full_name', 'Full Name'),
194
+ ('amount', 'Amount'),
195
+ ('checkin', 'Check-in'),
196
+ ('checkout', 'Check-out'),
197
+ ('address', 'Address'),
198
+ ('user_id', 'User ID'),
199
+ ('infotext', 'Info Text'),
200
+ ('included', 'Included')
201
+ ]
202
+
203
+ for field, display_name in fields_mapping:
204
+ value = booking_data.get(field, 'N/A')
205
+ table += f"| {display_name} | {value} |\n"
206
+
207
+
208
+ await cl.Message(content=table).send()
209
 
210
+ except Exception as e:
211
+ error_msg = f"Error: Could not parse the booking information. Details: {str(e)}"
212
+ await cl.Message(error_msg).send()
213
 
214
  else:
215
  response = await llm_chain.ainvoke(