camparchimedes commited on
Commit
e06eacc
ยท
verified ยท
1 Parent(s): 3892162

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -37
app.py CHANGED
@@ -31,7 +31,6 @@ BOOKING_KEYWORDS = [
31
  "rezerwacji",
32
  "bookingreferanse",
33
  "rezerwacja",
34
- "logg inn",
35
  "booket",
36
  "reservation number",
37
  "bestilling",
@@ -41,19 +40,19 @@ BOOKING_KEYWORDS = [
41
  ]
42
 
43
 
44
- daysoff_assistant_booking_template = """
45
- You are a Norwegian customer support AI assistant for Daysoff.no. By default,
46
- you respond in Norwegian to user question: {question}. In all other cases,
47
  adapt to user's language and respond accordingly.
48
- You can retrieving booking information for a given booking ID and provide
49
- general helpful info about Daysoff's services."
50
  Chat History: {chat_history}
51
  Question: {question}
52
  Answer:
53
  """
54
- daysoff_assistant_booking_prompt= PromptTemplate(
55
  input_variables=["chat_history", "question"],
56
- template=daysoff_assistant_booking_template
57
  )
58
 
59
  api_url_template = """
@@ -69,15 +68,15 @@ api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
69
  template=api_url_template)
70
 
71
  api_response_template = """
72
- With the API Documentation for Daysoff's official API: {api_docs}
73
- in mind, and IF {question} contains keywords from:{BOOKING_KEYWORDS},
74
- and given this API URL: {api_url} for querying, here is the
75
  response from Daysoff's API: {api_response}.
76
- Please provide a summary that directly addresses the user's question,
77
  omitting technical details like response format, and
78
  focusing on delivering the answer with clarity and conciseness,
79
- as if Daysoff's kundeservice is providing this information themselves.
80
- Booking Info:
81
  """
82
 
83
  api_response_prompt = PromptTemplate(
@@ -119,40 +118,24 @@ def setup_multiple_chains():
119
 
120
  cl.user_session.set("api_chain", api_chain)
121
 
122
- import re
123
 
124
- def extract_booking_id(user_message):
125
- # Extract booking ID from user message
126
- match = re.search(r'\b[A-Z]{6}\d{6}\b', user_message)
127
- return match.group(0) if match else None
128
-
129
  @cl.on_message
130
  async def handle_message(message: cl.Message):
131
  user_message = message.content.lower()
132
  llm_chain = cl.user_session.get("llm_chain")
133
  api_chain = cl.user_session.get("api_chain")
134
 
135
- # booking_id = extract_booking_id(user_message)
 
136
 
137
-
138
- #is_booking_query = any(
139
- #re.search(keyword, user_message, re.IGNORECASE) # re.search(keyword, r'\b[A-Z]{6}\d{6}\b', user_message, re.IGNORECASE)
140
- #for keyword in BOOKING_KEYWORDS + [BOOKING_ID]
141
- #)
142
- if any(keyword in user_message for keyword in ["BOOKING_KEYWORDS"]): # could be(?): if any(keyword in user_message for keyword in BOOKING_KEYWORDS + [BOOKING_ID]
143
-
144
- # <f any of the keywords are in user_message>, use api_chain
145
- response = await api_chain.acall(user_message,
146
- callbacks=[cl.AsyncLangchainCallbackHandler()])
147
 
148
- elif:
149
- # <or if the booking_id regex format is discovered in user message>, use api_chain
150
- re.search(keyword, r'\b[A-Z]{6}\d{6}\b', user_message):
151
- response = await api_chain.acall(user_message,
152
  callbacks=[cl.AsyncLangchainCallbackHandler()])
153
 
154
- else:
155
-
156
  response = await llm_chain.acall(user_message,
157
  callbacks=[cl.AsyncLangchainCallbackHandler()])
158
 
 
31
  "rezerwacji",
32
  "bookingreferanse",
33
  "rezerwacja",
 
34
  "booket",
35
  "reservation number",
36
  "bestilling",
 
40
  ]
41
 
42
 
43
+ daysoff_assistant_system_template = """
44
+ You are an AI customer support assistant for Daysoff. By default,
45
+ you respond in Norwegian to {question}. In all other cases,
46
  adapt to user's language and respond accordingly.
47
+ You can retrieving booking information for a given booking ID. In addition,
48
+ you can inform on Daysoff's personvernspolicy and verticals."
49
  Chat History: {chat_history}
50
  Question: {question}
51
  Answer:
52
  """
53
+ daysoff_assistant_system_prompt= PromptTemplate(
54
  input_variables=["chat_history", "question"],
55
+ template=daysoff_assistant_system_template
56
  )
57
 
58
  api_url_template = """
 
68
  template=api_url_template)
69
 
70
  api_response_template = """
71
+ IF and only IF {question} contains alphanumeric identifier:{BOOKING_ID},
72
+ with the API Documentation for Daysoff's official API: {api_docs}
73
+ in mind, and given this API URL: {api_url} for querying, here is the
74
  response from Daysoff's API: {api_response}.
75
+ Please provide only information that directly addresses the user's question,
76
  omitting technical details like response format, and
77
  focusing on delivering the answer with clarity and conciseness,
78
+ as if Daysoff's human customer service agent is providing this information themselves.
79
+ Her er informasjon om bestilligen:
80
  """
81
 
82
  api_response_prompt = PromptTemplate(
 
118
 
119
  cl.user_session.set("api_chain", api_chain)
120
 
 
121
 
122
+
 
 
 
 
123
  @cl.on_message
124
  async def handle_message(message: cl.Message):
125
  user_message = message.content.lower()
126
  llm_chain = cl.user_session.get("llm_chain")
127
  api_chain = cl.user_session.get("api_chain")
128
 
129
+ def is_booking_query(user_message):
130
+ match = re.search(r'\b[A-Z]{6}\d{6}\b', user_message)
131
 
132
+ return match
 
 
 
 
 
 
 
 
 
133
 
134
+ if match:
135
+ response = await api_chain.acall(user_message,
 
 
136
  callbacks=[cl.AsyncLangchainCallbackHandler()])
137
 
138
+ else:
 
139
  response = await llm_chain.acall(user_message,
140
  callbacks=[cl.AsyncLangchainCallbackHandler()])
141