camparchimedes commited on
Commit
6c97556
·
verified ·
1 Parent(s): 77ba750

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -28
app.py CHANGED
@@ -18,16 +18,13 @@ from langchain_core.prompts import PromptTemplate
18
  from langchain.memory.buffer import ConversationBufferMemory
19
 
20
  from api_docs_mck import api_docs_str
21
- from faq_data import help1, ansatte_faq_data, utleiere_faq_data
22
- from personvernspolicy import help2, personvernspolicy_data
23
 
24
  OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
25
 
26
  daysoff_assistant_template = """
27
  You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.no
28
  By default, you respond in Norwegian language, using a warm, direct and professional tone.
29
- You can provide information associated with a given booking ID, and with {help1} in mind, you
30
- can also answer frequently asked questions (FAQ) about DaysOff firmahytteordning for
31
  employees: {ansatte_faq_data} and for employers:{utleiere_faq_data}.
32
  To understand how best to answer queries about privacy policy,
33
  refer to {help2} and {personvernspolicy_data}
@@ -36,7 +33,7 @@ Question: {question}
36
  Answer:
37
  """
38
  daysoff_assistant_prompt = PromptTemplate(
39
- input_variables=['chat_history', 'help1', 'question', 'utleiere_faq_data', 'personvernspolicy_data', 'ansatte_faq_data'],
40
  template=daysoff_assistant_template
41
  )
42
 
@@ -53,16 +50,21 @@ api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
53
  template=api_url_template)
54
 
55
  api_response_template = """
56
- With the API Documentation for Daysoff's official API: {api_docs} in mind,
57
- and user question: {question} in mind,
58
  and given this API URL: {api_url} for querying,
59
- and if the response from Daysoff's API is information associated with
60
- a booking ID (’bestillingskode’): {api_response},
61
- please directly address the user's question (in Norwegian) and focus on delivering the
62
- the response from Daysoff's API in a markdown table with clarity
63
- and conciseness.
64
- Response:
65
  """
 
 
 
 
 
 
66
 
67
  api_response_prompt = PromptTemplate(
68
  input_variables=['api_docs', 'question', 'api_url', 'api_response'],
@@ -113,7 +115,6 @@ async def handle_message(message: cl.Message):
113
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
114
  base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
115
 
116
-
117
  if re.search(booking_pattern, user_message):
118
  bestillingskode = re.search(booking_pattern, user_message).group(0)
119
  question = f"Retrieve information for booking ID {base_url}?search={bestillingskode}"
@@ -126,20 +127,8 @@ async def handle_message(message: cl.Message):
126
  },
127
  callbacks=[cl.AsyncLangchainCallbackHandler()])
128
 
129
- else:
130
- response = await llm_chain.acall(
131
- {
132
- 'chat_history': chat_history,
133
- 'question': user_message,
134
- 'help1': help1(), # --call function w/arguments to get the instruction
135
- 'ansatte_faq_data': ansatte_faq_data,
136
- 'utleiere_faq_data': utleiere_faq_data,
137
- 'personvernspolicy_data': personvernspolicy_data,
138
- 'help2': help2()
139
- },
140
- callbacks=[cl.AsyncLangchainCallbackHandler()])
141
-
142
- #response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
143
 
144
  response_key = "output" if "output" in response else "text"
145
  await cl.Message(response.get(response_key, "")).send()
 
18
  from langchain.memory.buffer import ConversationBufferMemory
19
 
20
  from api_docs_mck import api_docs_str
 
 
21
 
22
  OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
23
 
24
  daysoff_assistant_template = """
25
  You are a customer support assistant (’kundeservice AI assistent’) for Daysoff.no
26
  By default, you respond in Norwegian language, using a warm, direct and professional tone.
27
+ You can provide information associated with a given booking ID, answer frequently asked questions (FAQ) about DaysOff firmahytteordning for
 
28
  employees: {ansatte_faq_data} and for employers:{utleiere_faq_data}.
29
  To understand how best to answer queries about privacy policy,
30
  refer to {help2} and {personvernspolicy_data}
 
33
  Answer:
34
  """
35
  daysoff_assistant_prompt = PromptTemplate(
36
+ input_variables=['chat_history', 'question'],
37
  template=daysoff_assistant_template
38
  )
39
 
 
50
  template=api_url_template)
51
 
52
  api_response_template = """
53
+ With the API Documentation for Daysoff's official API: {api_docs} in mind,
54
+ and the specific user question: {question} in mind,
55
  and given this API URL: {api_url} for querying,
56
+ here is the response from Daysoff's API: {api_response}.
57
+ Please provide an summary (in Norwegian) that directly addresses the user's question,
58
+ and focusing on delivering the answer with clarity and conciseness,
59
+ as if a human customer service agent is providing this information.
60
+ Summary:
 
61
  """
62
+ ## --"default"
63
+ #Please provide an summary (in Norwegian) that directly addresses the user's question,
64
+ #and focusing on delivering the answer with clarity and conciseness,
65
+ #as if a human customer service agent is providing this information.
66
+ #Summary:
67
+
68
 
69
  api_response_prompt = PromptTemplate(
70
  input_variables=['api_docs', 'question', 'api_url', 'api_response'],
 
115
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
116
  base_url = "https://670dccd0073307b4ee447f2f.mockapi.io/daysoff/api/V1/booking"
117
 
 
118
  if re.search(booking_pattern, user_message):
119
  bestillingskode = re.search(booking_pattern, user_message).group(0)
120
  question = f"Retrieve information for booking ID {base_url}?search={bestillingskode}"
 
127
  },
128
  callbacks=[cl.AsyncLangchainCallbackHandler()])
129
 
130
+ else:
131
+ response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  response_key = "output" if "output" in response else "text"
134
  await cl.Message(response.get(response_key, "")).send()