camparchimedes commited on
Commit
8a1955c
·
verified ·
1 Parent(s): fef7cfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -4
app.py CHANGED
@@ -157,13 +157,48 @@ async def handle_message(message: cl.Message):
157
  llm_chain = cl.user_session.get("llm_chain")
158
  post_tool = cl.user_session.get("post_tool")
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  # --------------------------------AD VAL.II.7--------------------------------
161
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
162
  endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
163
-
164
- if re.search(booking_pattern, user_message):
165
- bestillingskode = re.search(booking_pattern, user_message).group(0)
166
-
167
 
168
  post_data = {
169
  "url": endpoint_url,
@@ -185,6 +220,10 @@ async def handle_message(message: cl.Message):
185
  )
186
 
187
  response_key = "output" if "output" in response else "text"
 
 
188
  await cl.Message(response.get(response_key, "")).send()
189
  return message.content
190
 
 
 
 
157
  llm_chain = cl.user_session.get("llm_chain")
158
  post_tool = cl.user_session.get("post_tool")
159
 
160
+ # Match booking pattern
161
+ booking_pattern = r'\b[A-Z]{6}\d{6}\b'
162
+ endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
163
+
164
+ match = re.search(booking_pattern, user_message)
165
+ if match:
166
+ bestillingskode = match.group(0)
167
+ post_data = {
168
+ "url": endpoint_url,
169
+ "body": {
170
+ "booking_id": bestillingskode
171
+ }
172
+ }
173
+ try:
174
+ response = await post_tool.acall(
175
+ json.dumps(post_data),
176
+ callbacks=[cl.AsyncLangchainCallbackHandler()]
177
+ )
178
+ response_key = "output" if "output" in response else "text"
179
+ await cl.Message(content=response.get(response_key, "")).send()
180
+ except Exception as e:
181
+ await cl.Message(content=f"Error: {str(e)}").send()
182
+ else:
183
+ response = await llm_chain.ainvoke(
184
+ {"chat_history": "", "question": user_message},
185
+ callbacks=[cl.AsyncLangchainCallbackHandler()]
186
+ )
187
+ await cl.Message(content=response).send()
188
+
189
+ """
190
+ async def handle_message(message: cl.Message):
191
+ user_message = message.content
192
+ llm_chain = cl.user_session.get("llm_chain")
193
+ cl.user_session.set("post_tool", post_tool)
194
+
195
  # --------------------------------AD VAL.II.7--------------------------------
196
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
197
  endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
198
+
199
+ match = re.search(booking_pattern, user_message)
200
+ if match:
201
+ bestillingskode = match.group(0)
202
 
203
  post_data = {
204
  "url": endpoint_url,
 
220
  )
221
 
222
  response_key = "output" if "output" in response else "text"
223
+
224
+
225
  await cl.Message(response.get(response_key, "")).send()
226
  return message.content
227
 
228
+
229
+ """