camparchimedes commited on
Commit
8b77feb
·
verified ·
1 Parent(s): 85af1d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -23
app.py CHANGED
@@ -1,3 +1,11 @@
 
 
 
 
 
 
 
 
1
 
2
  # ===========================================
3
  # aha-----app.py
@@ -13,7 +21,9 @@ import chainlit as cl
13
  from dotenv import load_dotenv
14
 
15
  from langchain_community.tools.requests.tool import RequestsPostTool
16
- from langchain_community.utilities.requests import TextRequestsWrapper
 
 
17
 
18
 
19
  from langchain import hub
@@ -112,7 +122,7 @@ def setup_multiple_chains():
112
 
113
  cl.user_session.set("api_chain", api_chain)
114
 
115
- requests_wrapper = TextRequestsWrapper(
116
  headers={
117
  "Authorization": f"Bearer <auth_token>",
118
  "Content-Type": "application/json"
@@ -155,27 +165,32 @@ async def handle_message(message: cl.Message):
155
  )
156
 
157
  if response:
158
- try:
159
- booking_data = json.loads(response)
160
- formatted_response = f"""
161
- | Field | Value |
162
- |-------|--------|
163
- | Booking ID | {booking_data.get('booking_id', 'N/A')} |
164
- | Name | {booking_data.get('full_name', 'N/A')} |
165
- | Amount | {booking_data.get('amount', 'N/A')} kr |
166
- | Check-in | {booking_data.get('checkin', 'N/A')} |
167
- | Check-out | {booking_data.get('checkout', 'N/A')} |
168
- | Address | {booking_data.get('address', 'N/A')} |
169
- | User ID | {booking_data.get('user_id', 'N/A')} |
170
- | Info | {booking_data.get('infotext', 'N/A')} |
171
- | Included | {booking_data.get('included', 'N/A')} |
172
- """
173
- await cl.Message(formatted_response).send()
174
-
175
- except json.JSONDecodeError as e:
176
- await cl.Message("Error: Could not parse the booking information.").send()
177
-
178
-
 
 
 
 
 
179
 
180
  else:
181
  response = await llm_chain.ainvoke(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
 
1
+ # ---------------------------------------------------for backend looks-------------------------------------------------
2
+
3
+ #with open('/usr/local/lib/python3.10/site-packages/transformers/utils/chat_template_utils.py', 'r') as file:
4
+ #content = file.read()
5
+ #print("base.py:", content)
6
+ # ------------------------------------------------------the end--------------------------------------------------------
7
+
8
+
9
 
10
  # ===========================================
11
  # aha-----app.py
 
21
  from dotenv import load_dotenv
22
 
23
  from langchain_community.tools.requests.tool import RequestsPostTool
24
+ #from langchain_community.utilities.requests import TextRequestsWrapper
25
+ from langchain_community.utilities.requests import JsonRequestsWrapper
26
+
27
 
28
 
29
  from langchain import hub
 
122
 
123
  cl.user_session.set("api_chain", api_chain)
124
 
125
+ requests_wrapper = JsonRequestsWrapper( # TextRequestsWrapper
126
  headers={
127
  "Authorization": f"Bearer <auth_token>",
128
  "Content-Type": "application/json"
 
165
  )
166
 
167
  if response:
168
+ try:
169
+ booking_info = response
170
+ table = "| Field | Information |\n|---|---|\n"
171
+
172
+ fields_mapping = [
173
+ ('booking_id', 'Booking ID'),
174
+ ('full_name', 'Full Name'),
175
+ ('amount', 'Amount'),
176
+ ('checkin', 'Check-in'),
177
+ ('checkout', 'Check-out'),
178
+ ('address', 'Address'),
179
+ ('user_id', 'User ID'),
180
+ ('infotext', 'Info Text'),
181
+ ('included', 'Included')
182
+ ]
183
+
184
+ for field, display_name in fields_mapping:
185
+ value = booking_info.get(field, 'N/A')
186
+ table += f"| {display_name} | {value} |\n"
187
+
188
+
189
+ await cl.Message(content=table, markdown=True).send()
190
+
191
+ except Exception as e:
192
+ error_msg = f"Error: Could not parse the booking information. Details: {str(e)}"
193
+ await cl.Message(error_msg).send()
194
 
195
  else:
196
  response = await llm_chain.ainvoke(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])