Update app.py
Browse files
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 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
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()])
|