Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,14 +53,47 @@ BOOKING_KEYWORDS = [
|
|
53 |
|
54 |
|
55 |
daysoff_assistant_template = """
|
56 |
-
You are a customer support assistant for Daysoff named "Agrippa".
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
Chat History: {chat_history}
|
61 |
Question: {question}
|
62 |
Answer:
|
63 |
"""
|
|
|
64 |
daysoff_assistant_prompt= PromptTemplate(
|
65 |
input_variables=["chat_history", "question"],
|
66 |
template=daysoff_assistant_template
|
@@ -145,13 +178,50 @@ def setup_multiple_chains():
|
|
145 |
cl.user_session.set("api_chain", api_chain)
|
146 |
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
@cl.on_message
|
149 |
async def handle_message(message: cl.Message):
|
150 |
user_message = message.content.lower()
|
151 |
llm_chain = cl.user_session.get("llm_chain")
|
152 |
api_chain = cl.user_session.get("api_chain")
|
153 |
|
154 |
-
#if any(keyword in user_message for keyword in ["firmahytteordning","
|
155 |
|
156 |
|
157 |
#def is_booking_query(user_message):
|
@@ -174,3 +244,5 @@ async def handle_message(message: cl.Message):
|
|
174 |
response_key = "output" if "output" in response else "text"
|
175 |
await cl.Message(response.get(response_key, "")).send()
|
176 |
return message.content
|
|
|
|
|
|
53 |
|
54 |
|
55 |
daysoff_assistant_template = """
|
56 |
+
You are a customer support assistant (โkundeservice AI assistentโ) for Daysoff named "Agrippa".
|
57 |
+
Your primary objective is to provide exceptional, empathetic, and efficient customer service.
|
58 |
+
This includes retrieving booking details for a given booking ID and answering questions about
|
59 |
+
Daysoff's personvernspolicy and firmahytteordning.
|
60 |
+
|
61 |
+
Core Operational Guidelines:
|
62 |
+
- By default, you respond in Norwegian language
|
63 |
+
- Prioritize customer satisfaction and question-answering
|
64 |
+
- Provide clear, concise, and helpful responses
|
65 |
+
- Use a friendly, professional, and approachable tone
|
66 |
+
|
67 |
+
Interaction Protocol:
|
68 |
+
4. Never fabricate information
|
69 |
+
5. Ask clarifying questions if the query is ambiguous
|
70 |
+
6. Always transparent about information limitations
|
71 |
+
7. Prioritize precision over verbosity
|
72 |
+
|
73 |
+
Persona Characteristics:
|
74 |
+
- Gender: female
|
75 |
+
- Role: customer support assistant for Dayoff.no
|
76 |
+
- Communication Style: Warm, direct, solution-oriented
|
77 |
+
- Brand Personality: Helpful, efficient, trustworthy
|
78 |
+
|
79 |
+
Response Structure:
|
80 |
+
- Directly address the user's question
|
81 |
+
- Provide step-by-step guidance if applicable
|
82 |
+
|
83 |
+
Ethical Constraints:
|
84 |
+
- Stay within the scope of Dayoff.no's services
|
85 |
+
- Maintain customer privacy
|
86 |
+
- Avoid sharing sensitive personal information
|
87 |
+
- Refer complex issues to human support at [email protected] when necessary
|
88 |
+
|
89 |
+
Special Instructions:
|
90 |
+
- Adapt communication complexity to the customer's apparent technical understanding
|
91 |
+
- Proactively suggest solutions based on contextual information
|
92 |
Chat History: {chat_history}
|
93 |
Question: {question}
|
94 |
Answer:
|
95 |
"""
|
96 |
+
|
97 |
daysoff_assistant_prompt= PromptTemplate(
|
98 |
input_variables=["chat_history", "question"],
|
99 |
template=daysoff_assistant_template
|
|
|
178 |
cl.user_session.set("api_chain", api_chain)
|
179 |
|
180 |
|
181 |
+
|
182 |
+
|
183 |
+
import logging
|
184 |
+
|
185 |
+
@cl.on_message
|
186 |
+
async def handle_message(message: cl.Message):
|
187 |
+
user_message = message.content
|
188 |
+
llm_chain = cl.user_session.get("llm_chain")
|
189 |
+
api_chain = cl.user_session.get("api_chain")
|
190 |
+
|
191 |
+
api_keywords = ["firmahytteordning", "personvernspolicy"]
|
192 |
+
|
193 |
+
# --check message for a booking ID
|
194 |
+
try:
|
195 |
+
# --check message for booking ID
|
196 |
+
if re.search(r'\b[A-Z]{6}\d{6}\b', user_message):
|
197 |
+
logging.debug(f"Booking ID detected in message: {user_message}")
|
198 |
+
response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
199 |
+
|
200 |
+
# --check message for API keywords
|
201 |
+
elif any(keyword in user_message.lower() for keyword in api_keywords):
|
202 |
+
logging.debug(f"API keyword detected in message: {user_message}")
|
203 |
+
response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
204 |
+
|
205 |
+
else:
|
206 |
+
logging.debug("Triggering LLMChain for everything else.")
|
207 |
+
response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
|
208 |
+
|
209 |
+
except Exception as e:
|
210 |
+
logging.error(f"Error in processing message: {str(e)}")
|
211 |
+
response = {"output": "Beklager, jeg kunne ikke behandle forespรธrselen din akkurat nรฅ."}
|
212 |
+
|
213 |
+
response_key = "output" if "output" in response else "text"
|
214 |
+
await cl.Message(response.get(response_key, "")).send()
|
215 |
+
return message.content
|
216 |
+
|
217 |
+
"""
|
218 |
@cl.on_message
|
219 |
async def handle_message(message: cl.Message):
|
220 |
user_message = message.content.lower()
|
221 |
llm_chain = cl.user_session.get("llm_chain")
|
222 |
api_chain = cl.user_session.get("api_chain")
|
223 |
|
224 |
+
#if any(keyword in user_message for keyword in ["firmahytteordning","personvernspolicy"]):
|
225 |
|
226 |
|
227 |
#def is_booking_query(user_message):
|
|
|
244 |
response_key = "output" if "output" in response else "text"
|
245 |
await cl.Message(response.get(response_key, "")).send()
|
246 |
return message.content
|
247 |
+
"""
|
248 |
+
|