camparchimedes commited on
Commit
6810395
·
verified ·
1 Parent(s): a01015d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -21
app.py CHANGED
@@ -30,11 +30,12 @@ OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
30
  daysoff_assistant_template = """
31
  You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.
32
  By default, you respond in Norwegian language, using a warm, direct, and professional tone.
33
- Your expertise is exclusively in retrieving booking information for a given booking ID assistance related to
34
- to this.
35
- You do not provide information outside of this scope. If a question is not about this topic, respond with
36
- "Ooops da, jeg driver faktisk kun med henvendelser omkring bestillingsinformasjon. Gjelder det andre henvendelser,
37
- kså du nok kontakte kundeservice [email protected]😊"
 
38
  Chat History: {chat_history}
39
  Question: {question}
40
  Answer:
@@ -103,14 +104,12 @@ def setup_multiple_chains():
103
  conversation_memory = ConversationBufferMemory(memory_key="chat_history",
104
  max_len=30, # --retains only the last 30 exchanges
105
  return_messages=True,
106
- )
107
-
108
  # --ConversationTokenBufferMemory
109
  #conversation_memory = ConversationTokenBufferMemory(memory_key="chat_history",
110
  #max_token_limit=1318,
111
  #return_messages=True,
112
  #)
113
-
114
  # --ConversationSummaryMemory
115
  #conversation_memory = ConversationSummaryMemory(memory_key="chat_history",
116
  #return_messages=True,
@@ -158,27 +157,27 @@ async def handle_message(message: cl.Message):
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 {endpoint_url}?search={bestillingskode}"
163
-
164
- response = await api_chain.acall(
165
- {
166
- "bestillingskode": bestillingskode,
167
- "question": question
168
- },
169
- callbacks=[cl.AsyncLangchainCallbackHandler()]
170
- )
 
171
 
172
  elif any(keyword.lower() in user_message.lower() for keyword in all_keywords):
173
- # --match in keywords/iterate
174
  matched_entry = None
175
  for qa_entry in personvernspolicy_qa + faq_qa:
176
  if qa_entry['question'].lower() in user_message.lower():
177
  matched_entry = qa_entry
178
- break # Exit loop once a match is found
179
 
180
  if matched_entry:
181
- # --question@matched entry
182
  question = f"User Question: {user_message}\nMatched FAQ:\n{matched_entry}"
183
  response = await llm_chain.acall(
184
  {
 
30
  daysoff_assistant_template = """
31
  You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.
32
  By default, you respond in Norwegian language, using a warm, direct, and professional tone.
33
+ Your expertise is exclusively in retrieving booking information for a given booking ID and answering
34
+ FAQs about Daysoff firmahytteorning and personvernspolicy.
35
+ If a question is not about these topics, respond with
36
+ "Jeg driver faktisk kun med henvendelser omkring bestillingsinformasjon og ofte-stilte-spørsmål i forbindelse
37
+ med DaysOff firmahytteordning (inkludert personvernspolicyn). Gjelder det andre ting
38
+ så må du nok kontakte kundeservice direkte på [email protected]😊"
39
  Chat History: {chat_history}
40
  Question: {question}
41
  Answer:
 
104
  conversation_memory = ConversationBufferMemory(memory_key="chat_history",
105
  max_len=30, # --retains only the last 30 exchanges
106
  return_messages=True,
107
+ )
 
108
  # --ConversationTokenBufferMemory
109
  #conversation_memory = ConversationTokenBufferMemory(memory_key="chat_history",
110
  #max_token_limit=1318,
111
  #return_messages=True,
112
  #)
 
113
  # --ConversationSummaryMemory
114
  #conversation_memory = ConversationSummaryMemory(memory_key="chat_history",
115
  #return_messages=True,
 
157
 
158
 
159
  if re.search(booking_pattern, user_message):
160
+
161
+ bestillingskode = re.search(booking_pattern, user_message).group(0)
162
+ question = f"Retrieve information for booking ID {endpoint_url}?search={bestillingskode}"
163
+
164
+ response = await api_chain.acall(
165
+ {
166
+ "bestillingskode": bestillingskode,
167
+ "question": question
168
+ },
169
+ callbacks=[cl.AsyncLangchainCallbackHandler()]
170
+ )
171
 
172
  elif any(keyword.lower() in user_message.lower() for keyword in all_keywords):
173
+
174
  matched_entry = None
175
  for qa_entry in personvernspolicy_qa + faq_qa:
176
  if qa_entry['question'].lower() in user_message.lower():
177
  matched_entry = qa_entry
178
+ break
179
 
180
  if matched_entry:
 
181
  question = f"User Question: {user_message}\nMatched FAQ:\n{matched_entry}"
182
  response = await llm_chain.acall(
183
  {