camparchimedes commited on
Commit
bb451be
·
verified ·
1 Parent(s): 06d7469

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -27
app.py CHANGED
@@ -116,38 +116,35 @@ async def handle_message(message: cl.Message):
116
  api_chain = cl.user_session.get("api_chain")
117
 
118
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
119
- base_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
120
- headers = {
121
- "Authorization": f"Bearer {auth_token}",
122
- "Content-Type": "application/json"
123
- }
124
-
125
- #from langchain.requests import Requests
126
-
127
- #requests = Requests(
128
- #headers=headers,
129
- #verify=True # @SSL verification
130
- #)
131
-
132
  if re.search(booking_pattern, user_message):
133
- bestillingskode = re.search(booking_pattern, user_message).group(0)
134
- question = f"Retrieve information for booking ID {bestillingskode}"
135
- # ~ainvoke
136
- response = await api_chain.acall(
137
- {
138
- "question": question,
139
- "input": {
140
- "url": base_url,
141
- "method": "POST",
142
- "headers": headers,
143
- "body": {"booking_id": bestillingskode}
144
- }
145
- },
146
  callbacks=[cl.AsyncLangchainCallbackHandler()])
 
 
147
 
148
  else:
149
  response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
150
 
151
  response_key = "output" if "output" in response else "text"
152
  await cl.Message(response.get(response_key, "")).send()
153
- return message.content
 
 
 
 
 
 
 
 
 
 
 
 
116
  api_chain = cl.user_session.get("api_chain")
117
 
118
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
119
+ endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
120
+
 
 
 
 
 
 
 
 
 
 
 
121
  if re.search(booking_pattern, user_message):
122
+ booking_id = re.search(booking_pattern, user_message).group(0)
123
+ headers = {"Authorization": f"Bearer {auth_token}", "Content-Type": "application/json"}
124
+
125
+ # --------------------------------ALT 3--------------------------------
126
+ response = await api_chain.acall({
127
+ "booking_id": booking_id,
128
+ "headers": headers #{"Authorization": f"Bearer {auth_token}"},
129
+ }),
 
 
 
 
 
130
  callbacks=[cl.AsyncLangchainCallbackHandler()])
131
+ # ----------------------------------------------------------------------
132
+
133
 
134
  else:
135
  response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
136
 
137
  response_key = "output" if "output" in response else "text"
138
  await cl.Message(response.get(response_key, "")).send()
139
+ return message.content
140
+
141
+
142
+
143
+ #from langchain.requests import Requests
144
+
145
+ #requests = Requests(
146
+ #headers=headers,
147
+ #verify=True # @SSL verification
148
+ #)
149
+
150
+ #response = requests.get(f"{endpoint_url}?booking_id={bestillingskode}", headers=headers)