camparchimedes commited on
Commit
fc84509
ยท
verified ยท
1 Parent(s): 383170a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -108,7 +108,6 @@ async def handle_message(message: cl.Message):
108
  match = re.search(booking_pattern, user_message)
109
 
110
  if match:
111
-
112
  bestillingskode = match.group()
113
  headers = {
114
  "Authorization": auth_token,
@@ -117,14 +116,14 @@ async def handle_message(message: cl.Message):
117
  payload = {"booking_id": bestillingskode}
118
 
119
  try:
120
-
121
  response = await async_post_request(API_URL, headers, payload)
122
  response.raise_for_status()
123
  booking_data = response.json()
124
 
125
  if "booking_id" in booking_data:
126
-
127
  try:
 
128
  table = (
129
  "| ๐‘ญ๐’Š๐’†๐’๐’… | ๐—œ๐—ป๐—ณ๐—ผ |\n"
130
  "|:-----------|:---------------------|\n"
@@ -139,28 +138,36 @@ async def handle_message(message: cl.Message):
139
  f"| ๐™„๐™ฃ๐™˜๐™ก๐™ช๐™™๐™š๐™™ | {booking_data.get('included', 'N/A')} |"
140
  )
141
 
 
142
  response = await llm_chain.ainvoke({
143
  "table": table,
144
  "question": user_message,
145
  "chat_history": ""
146
  }, callbacks=[cl.AsyncLangchainCallbackHandler()])
147
 
148
- await cl.Message(content=table).send()
 
 
149
 
150
  except Exception as e:
151
- except requests.exceptions.RequestException as e:
152
- await cl.Message(content=f"Request failed: {str(e)}").send()
153
-
154
 
155
  else:
156
- await cl.Message(content="Booking information not found.").send()
 
 
 
 
157
  else:
158
  try:
 
159
  response = await llm_chain.ainvoke({
160
  "question": user_message,
161
  "chat_history": ""
162
  }, callbacks=[cl.AsyncLangchainCallbackHandler()])
163
 
 
 
164
  await cl.Message(content=response["text"]).send()
165
 
166
  except Exception as e:
 
108
  match = re.search(booking_pattern, user_message)
109
 
110
  if match:
 
111
  bestillingskode = match.group()
112
  headers = {
113
  "Authorization": auth_token,
 
116
  payload = {"booking_id": bestillingskode}
117
 
118
  try:
119
+ # --async POST request
120
  response = await async_post_request(API_URL, headers, payload)
121
  response.raise_for_status()
122
  booking_data = response.json()
123
 
124
  if "booking_id" in booking_data:
 
125
  try:
126
+ # --markdown_table
127
  table = (
128
  "| ๐‘ญ๐’Š๐’†๐’๐’… | ๐—œ๐—ป๐—ณ๐—ผ |\n"
129
  "|:-----------|:---------------------|\n"
 
138
  f"| ๐™„๐™ฃ๐™˜๐™ก๐™ช๐™™๐™š๐™™ | {booking_data.get('included', 'N/A')} |"
139
  )
140
 
141
+ # --invoke LLM w/ table + user_message
142
  response = await llm_chain.ainvoke({
143
  "table": table,
144
  "question": user_message,
145
  "chat_history": ""
146
  }, callbacks=[cl.AsyncLangchainCallbackHandler()])
147
 
148
+ # --send both as combined_message
149
+ combined_message = f"### Booking Details Table:\n\n{table}\n\n### LLM Response:\n\n{response.get('text', 'No response available.')}"
150
+ await cl.Message(content=combined_message).send()
151
 
152
  except Exception as e:
153
+ await cl.Message(content=f"Error processing booking data: {str(e)}").send()
 
 
154
 
155
  else:
156
+ await cl.Message(content="Booking not found or invalid response.").send()
157
+
158
+ except requests.exceptions.RequestException as e:
159
+ await cl.Message(content=f"Request failed: {str(e)}").send()
160
+
161
  else:
162
  try:
163
+ # --invoke LLM w/ user_message
164
  response = await llm_chain.ainvoke({
165
  "question": user_message,
166
  "chat_history": ""
167
  }, callbacks=[cl.AsyncLangchainCallbackHandler()])
168
 
169
+ # Send the LLM response as a message
170
+ #await cl.Message(content=response.get("text")).send()
171
  await cl.Message(content=response["text"]).send()
172
 
173
  except Exception as e: