Update app.py
Browse files
app.py
CHANGED
@@ -123,36 +123,26 @@ async def handle_message(message: cl.Message):
|
|
123 |
|
124 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
125 |
endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
|
126 |
-
headers = {
|
127 |
-
"Authorization": f"Bearer {auth_token}",
|
128 |
-
"Content-Type": "application/json"
|
129 |
-
}
|
130 |
|
|
|
|
|
131 |
|
132 |
# --GET method
|
133 |
if re.search(booking_pattern, user_message):
|
134 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
135 |
-
question = f"Retrieve information for booking ID {endpoint_url}?search={bestillingskode}"
|
|
|
136 |
response = await api_chain.acall(
|
137 |
{
|
138 |
"bestillingskode": bestillingskode,
|
139 |
"question": question,
|
140 |
-
"
|
141 |
|
142 |
},
|
143 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
144 |
-
|
145 |
-
else:
|
146 |
-
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
147 |
-
|
148 |
-
response_key = "output" if "output" in response else "text"
|
149 |
-
await cl.Message(response.get(response_key, "")).send()
|
150 |
-
return message.content
|
151 |
-
|
152 |
-
#endpoint_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
153 |
-
|
154 |
-
|
155 |
"""
|
|
|
156 |
# --POST method, booking_id@body
|
157 |
if re.search(booking_pattern, user_message):
|
158 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
@@ -173,5 +163,19 @@ async def handle_message(message: cl.Message):
|
|
173 |
},
|
174 |
callbacks=[cl.AsyncLangchainCallbackHandler()]
|
175 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
"""
|
|
|
123 |
|
124 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
125 |
endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
|
|
|
|
|
|
|
|
|
126 |
|
127 |
+
"""
|
128 |
+
auth_token = f"Bearer {auth_token}
|
129 |
|
130 |
# --GET method
|
131 |
if re.search(booking_pattern, user_message):
|
132 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
133 |
+
question = f"Retrieve information for booking ID {endpoint_url}?search={bestillingskode}&auth_token={auth_token}"
|
134 |
+
"
|
135 |
response = await api_chain.acall(
|
136 |
{
|
137 |
"bestillingskode": bestillingskode,
|
138 |
"question": question,
|
139 |
+
"auth_token": auth_token
|
140 |
|
141 |
},
|
142 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
143 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
"""
|
145 |
+
|
146 |
# --POST method, booking_id@body
|
147 |
if re.search(booking_pattern, user_message):
|
148 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
|
|
163 |
},
|
164 |
callbacks=[cl.AsyncLangchainCallbackHandler()]
|
165 |
)
|
166 |
+
|
167 |
+
else:
|
168 |
+
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
169 |
+
|
170 |
+
|
171 |
+
response_key = "output" if "output" in response else "text"
|
172 |
+
await cl.Message(response.get(response_key, "")).send()
|
173 |
+
return message.content
|
174 |
+
|
175 |
+
#endpoint_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
176 |
+
|
177 |
+
|
178 |
+
"""
|
179 |
+
|
180 |
|
181 |
"""
|