Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ from langchain.memory.buffer import ConversationBufferMemory
|
|
19 |
|
20 |
from api_docs_mck import api_docs_str
|
21 |
from faq_data import ansatte_faq_data, utleiere_faq_data
|
22 |
-
from personvernspolicy
|
23 |
|
24 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
25 |
|
@@ -93,7 +93,8 @@ With the API Documentation for Daysoff's official API: {api_docs} in mind,
|
|
93 |
and the specific user question: {question},
|
94 |
and given this API URL: {api_url} for querying,
|
95 |
here is the response from Daysoff's API: {api_response}.
|
96 |
-
If the response includes a booking ID (bestillingskode), present this information
|
|
|
97 |
For all other responses, please provide a clear and concise summary (in Norwegian) that directly addresses the user's question,
|
98 |
delivered in a manner that reflects the professionalism and warmth of a human customer service agent.
|
99 |
Summary:
|
@@ -148,6 +149,14 @@ async def handle_message(message: cl.Message):
|
|
148 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
149 |
base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
if re.search(booking_pattern, user_message):
|
152 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
153 |
question = f"Retrieve information for booking ID {base_url}?search={bestillingskode}"
|
@@ -160,11 +169,10 @@ async def handle_message(message: cl.Message):
|
|
160 |
},
|
161 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
162 |
|
163 |
-
elif any(keyword in user_message for keyword in
|
164 |
-
|
165 |
-
response = await api_chain.acall(user_message,
|
166 |
-
|
167 |
-
|
168 |
else:
|
169 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
170 |
|
|
|
19 |
|
20 |
from api_docs_mck import api_docs_str
|
21 |
from faq_data import ansatte_faq_data, utleiere_faq_data
|
22 |
+
from personvernspolicy import personvernspolicy_data
|
23 |
|
24 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
25 |
|
|
|
93 |
and the specific user question: {question},
|
94 |
and given this API URL: {api_url} for querying,
|
95 |
here is the response from Daysoff's API: {api_response}.
|
96 |
+
If the response includes a booking ID (bestillingskode), consistently present this information
|
97 |
+
directly to the user without summarizing it.
|
98 |
For all other responses, please provide a clear and concise summary (in Norwegian) that directly addresses the user's question,
|
99 |
delivered in a manner that reflects the professionalism and warmth of a human customer service agent.
|
100 |
Summary:
|
|
|
149 |
booking_pattern = r'\b[A-Z]{6}\d{6}\b'
|
150 |
base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
|
151 |
|
152 |
+
faq_keywords = (
|
153 |
+
[item["question"] for item in ansatte_faq_data] +
|
154 |
+
[item["answer"] for item in ansatte_faq_data] +
|
155 |
+
[item["question"] for item in utleiere_faq_data] +
|
156 |
+
[item["answer"] for item in utleiere_faq_data] +
|
157 |
+
[key for key in personvernspolicy_data.keys()]
|
158 |
+
)
|
159 |
+
|
160 |
if re.search(booking_pattern, user_message):
|
161 |
bestillingskode = re.search(booking_pattern, user_message).group(0)
|
162 |
question = f"Retrieve information for booking ID {base_url}?search={bestillingskode}"
|
|
|
169 |
},
|
170 |
callbacks=[cl.AsyncLangchainCallbackHandler()])
|
171 |
|
172 |
+
elif any(keyword in user_message for keyword in faq_keywords):
|
173 |
+
|
174 |
+
response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
175 |
+
|
|
|
176 |
else:
|
177 |
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
178 |
|