Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import os
|
|
8 |
import re
|
9 |
import time
|
10 |
import json
|
|
|
11 |
|
12 |
import chainlit as cl
|
13 |
|
@@ -136,15 +137,34 @@ def setup_multiple_chains():
|
|
136 |
|
137 |
cl.user_session.set("api_chain", api_chain)
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
@cl.on_message
|
140 |
async def handle_message(message: cl.Message):
|
141 |
user_message = message.content #.lower()
|
142 |
llm_chain = cl.user_session.get("llm_chain")
|
143 |
api_chain = cl.user_session.get("api_chain")
|
144 |
|
|
|
145 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
|
|
146 |
endpoint_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
|
|
148 |
if re.search(booking_pattern, user_message):
|
149 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
150 |
question = f"Retrieve information for booking ID {endpoint_url}?search={bestillingskode}"
|
@@ -157,6 +177,17 @@ async def handle_message(message: cl.Message):
|
|
157 |
},
|
158 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
else:
|
161 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
162 |
|
|
|
8 |
import re
|
9 |
import time
|
10 |
import json
|
11 |
+
import pandas as pd
|
12 |
|
13 |
import chainlit as cl
|
14 |
|
|
|
137 |
|
138 |
cl.user_session.set("api_chain", api_chain)
|
139 |
|
140 |
+
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
@cl.on_message
|
147 |
async def handle_message(message: cl.Message):
|
148 |
user_message = message.content #.lower()
|
149 |
llm_chain = cl.user_session.get("llm_chain")
|
150 |
api_chain = cl.user_session.get("api_chain")
|
151 |
|
152 |
+
# --regex
|
153 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
154 |
+
# --endpoint
|
155 |
endpoint_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
156 |
+
# --dataframe
|
157 |
+
personvernspolicy_df = pd.read_csv('personvernspolicy.csv')
|
158 |
+
faq_df = pd.read_csv('faq.csv')
|
159 |
+
# --dictionaries
|
160 |
+
personvernspolicy_qa = personvernspolicy_df.to_dict(orient='records')
|
161 |
+
faq_qa = faq_df.to_dict(orient='records')
|
162 |
+
# --keywords
|
163 |
+
personvernspolicy_keywords = personvernspolicy_df['question'].tolist()
|
164 |
+
faq_keywords = faq_df['question'].tolist()
|
165 |
+
all_keywords = personvernspolicy_keywords + faq_keywords
|
166 |
|
167 |
+
|
168 |
if re.search(booking_pattern, user_message):
|
169 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
170 |
question = f"Retrieve information for booking ID {endpoint_url}?search={bestillingskode}"
|
|
|
177 |
},
|
178 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
179 |
|
180 |
+
elif any(keyword.lower() in user_message.lower() for keyword in all_keywords):
|
181 |
+
|
182 |
+
for qa_entry in personvernspolicy_qa + faq_qa:
|
183 |
+
if qa_entry['question'].lower() in user_message.lower():
|
184 |
+
|
185 |
+
response = llm_chain.acall(f"User Question: {user_message}\nMatched FAQ:\n{qa_entry}")
|
186 |
+
return response
|
187 |
+
|
188 |
+
else:
|
189 |
+
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
190 |
+
|
191 |
else:
|
192 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
193 |
|