camparchimedes commited on
Commit
1542c88
·
verified ·
1 Parent(s): 5e28c86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -65,10 +65,14 @@ PERSONVERNSPOLICY_QUESTIONS = [
65
  # If you do not know the answer, just reply truthfully that you do not have the answer rather than
66
  # giving inaccurate or speculative information.
67
  daysoff_assistant_template = """
68
- You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.no
69
- By default, you respond in Norwegian language, using a warm, direct and professional tone.
70
- You can look up booking information for a booking ID (bestillingskode)
71
- and answer FAQ related to DaysOff firmahytteordning.
 
 
 
 
72
  Chat History: {chat_history}
73
  Question: {question}
74
  Answer:
@@ -90,15 +94,14 @@ API URL:
90
  api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
91
  template=api_url_template)
92
 
93
- # If the response includes a booking ID (bestillingskode), consistently present this information
94
- # directly to the user without summarizing it.
95
  api_response_template = """
96
  With the API Documentation for Daysoff's official API: {api_docs} in mind,
97
  and the specific user question: {question},
98
  and given this API URL: {api_url} for querying,
99
  here is the response from Daysoff's API: {api_response}.
100
- If the response includes booking information, provide the information verbatim (do not summarize it.)
101
- For all other cases, please provide a clear and concise summary (in Norwegian) that directly addresses the user's question,
102
  delivered in a manner that reflects the professionalism and warmth of a human customer service agent.
103
  Summary:
104
  """
@@ -149,7 +152,7 @@ async def handle_message(message: cl.Message):
149
  api_chain = cl.user_session.get("api_chain")
150
 
151
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
152
- base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
153
 
154
  #faq_keywords = (
155
  #[key for key in ansatte_faq_data.keys()] +
@@ -159,7 +162,7 @@ async def handle_message(message: cl.Message):
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}"
163
 
164
  response = await api_chain.acall(
165
  {
@@ -169,9 +172,12 @@ async def handle_message(message: cl.Message):
169
  },
170
  callbacks=[cl.AsyncLangchainCallbackHandler()])
171
 
172
- elif any(keyword in user_message for keyword in (FAQ_ANSATTE + FAQ_UTLEIERE + PERSONVERNSPOLICY_QUESTIONS)):
173
- #elif any(keyword in user_message for keyword in faq_keywords):
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()])
 
65
  # If you do not know the answer, just reply truthfully that you do not have the answer rather than
66
  # giving inaccurate or speculative information.
67
  daysoff_assistant_template = """
68
+ You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.no.
69
+ By default, you respond in Norwegian language, using a warm, direct, and professional tone.
70
+ Your expertise is exclusively in providing information and assistance related to
71
+ (i) retrieving booking information for a given booking ID,
72
+ (ii) answering frequently asked questions (FAQ) about DaysOff firmahytteordning for employees and employers,
73
+ (iii) addressing questions related to Daysoff's personvernspolicy.
74
+ You do not provide information outside of this scope. If a question is not about these topics, respond with,
75
+ "Jeg spesialiserer meg kun på spørsmål relatert til firmahytteordning, bestillingsinformasjon og personvernspolicy for Daysoff.no."
76
  Chat History: {chat_history}
77
  Question: {question}
78
  Answer:
 
94
  api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
95
  template=api_url_template)
96
 
97
+ # If the response includes booking information, provide the information verbatim (do not summarize it.)
98
+
99
  api_response_template = """
100
  With the API Documentation for Daysoff's official API: {api_docs} in mind,
101
  and the specific user question: {question},
102
  and given this API URL: {api_url} for querying,
103
  here is the response from Daysoff's API: {api_response}.
104
+ Please provide a clear and concise summary (in Norwegian) that directly addresses the user's question,
 
105
  delivered in a manner that reflects the professionalism and warmth of a human customer service agent.
106
  Summary:
107
  """
 
152
  api_chain = cl.user_session.get("api_chain")
153
 
154
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
155
+ endpoint_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
156
 
157
  #faq_keywords = (
158
  #[key for key in ansatte_faq_data.keys()] +
 
162
 
163
  if re.search(booking_pattern, user_message):
164
  bestillingskode = re.search(booking_pattern, user_message).group(0)
165
+ question = f"Retrieve information for booking ID {endpoint_url}?search={bestillingskode}"
166
 
167
  response = await api_chain.acall(
168
  {
 
172
  },
173
  callbacks=[cl.AsyncLangchainCallbackHandler()])
174
 
175
+ if any(keyword in user_message for keyword in (FAQ_ANSATTE + FAQ_UTLEIERE + PERSONVERNSPOLICY_QUESTIONS)):
176
+ #elif any(keyword in user_message for keyword in faq_keywords):
177
+ response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
178
+
179
+ else:
180
+ response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
181
 
182
  else:
183
  response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])