Update app.py
Browse files
app.py
CHANGED
@@ -164,11 +164,17 @@ async def handle_message(message: cl.Message):
|
|
164 |
config={"callbacks": [cl.AsyncLangchainCallbackHandler()]}
|
165 |
)
|
166 |
|
|
|
|
|
|
|
167 |
## PS:
|
168 |
#json.dumps(post_data) converts a Python dictionary (post_data) into a JSON string.
|
169 |
#json.loads(post_data) takes a JSON string and converts it back into a Python dictionary.
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
172 |
try:
|
173 |
booking_info = json.loads(response)
|
174 |
|
@@ -185,8 +191,17 @@ async def handle_message(message: cl.Message):
|
|
185 |
f"| Info Text | `{booking_info.get('infotext')}` |\n"
|
186 |
f"| Included | `{booking_info.get('included')}` |"
|
187 |
)
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
table = "| Field | Information |\n|---|---|\n"
|
191 |
|
192 |
fields_mapping = [
|
@@ -206,12 +221,6 @@ async def handle_message(message: cl.Message):
|
|
206 |
table += f"| {display_name} | {value} |\n"
|
207 |
"""
|
208 |
|
209 |
-
await cl.Message(content=table).send()
|
210 |
-
|
211 |
-
except Exception as e:
|
212 |
-
error_msg = f"Error: Could not parse the booking information. Details: {str(e)}"
|
213 |
-
await cl.Message(error_msg).send()
|
214 |
-
|
215 |
else:
|
216 |
response = await llm_chain.ainvoke(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
217 |
|
|
|
164 |
config={"callbacks": [cl.AsyncLangchainCallbackHandler()]}
|
165 |
)
|
166 |
|
167 |
+
if response:
|
168 |
+
await cl.Message(content=str(response)).send()
|
169 |
+
|
170 |
## PS:
|
171 |
#json.dumps(post_data) converts a Python dictionary (post_data) into a JSON string.
|
172 |
#json.loads(post_data) takes a JSON string and converts it back into a Python dictionary.
|
173 |
+
|
174 |
+
|
175 |
+
"""
|
176 |
+
## OPTION I
|
177 |
+
if response:
|
178 |
try:
|
179 |
booking_info = json.loads(response)
|
180 |
|
|
|
191 |
f"| Info Text | `{booking_info.get('infotext')}` |\n"
|
192 |
f"| Included | `{booking_info.get('included')}` |"
|
193 |
)
|
194 |
+
|
195 |
+
await cl.Message(content=table).send()
|
196 |
+
|
197 |
+
except Exception as e:
|
198 |
+
error_msg = f"Error: Could not parse the booking information. Details: {str(e)}"
|
199 |
+
await cl.Message(error_msg).send()
|
200 |
+
|
201 |
+
# info: ↑™ returns a ’None’ response for values
|
202 |
+
|
203 |
+
|
204 |
+
## OPTION II
|
205 |
table = "| Field | Information |\n|---|---|\n"
|
206 |
|
207 |
fields_mapping = [
|
|
|
221 |
table += f"| {display_name} | {value} |\n"
|
222 |
"""
|
223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
else:
|
225 |
response = await llm_chain.ainvoke(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
226 |
|