camparchimedes commited on
Commit
a01015d
ยท
verified ยท
1 Parent(s): 994cff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -27
app.py CHANGED
@@ -1,6 +1,6 @@
1
 
2
  # ===========================================
3
- # ver01.01-5.workload-----app.py
4
  # ===========================================
5
 
6
  import asyncio
@@ -22,10 +22,8 @@ from langchain.memory.buffer import ConversationBufferMemory
22
  from langchain.memory import ConversationTokenBufferMemory
23
  from langchain.memory import ConversationSummaryMemory
24
 
25
-
26
  from api_docs_mck import api_docs_str
27
- #from faq_data import ansatte_faq_data, utleiere_faq_data
28
- #from personvernspolicy import personvernspolicy_data
29
 
30
  OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
31
 
@@ -58,7 +56,6 @@ API URL:
58
  api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
59
  template=api_url_template)
60
 
61
- # If the response includes booking information, provide the information verbatim (do not summarize it.)
62
 
63
  api_response_template = """
64
  With the API Documentation for Daysoff's official API: {api_docs} in mind,
@@ -138,11 +135,6 @@ def setup_multiple_chains():
138
  cl.user_session.set("api_chain", api_chain)
139
 
140
 
141
-
142
-
143
-
144
-
145
-
146
  @cl.on_message
147
  async def handle_message(message: cl.Message):
148
  user_message = message.content #.lower()
@@ -166,28 +158,38 @@ async def handle_message(message: cl.Message):
166
 
167
 
168
  if re.search(booking_pattern, user_message):
169
- bestillingskode = re.search(booking_pattern, user_message).group(0)
170
- question = f"Retrieve information for booking ID {endpoint_url}?search={bestillingskode}"
171
 
172
- response = await api_chain.acall(
173
- {
174
- "bestillingskode": bestillingskode,
175
- "question": question
176
-
177
- },
178
- callbacks=[cl.AsyncLangchainCallbackHandler()])
179
 
180
  elif any(keyword.lower() in user_message.lower() for keyword in all_keywords):
181
-
 
182
  for qa_entry in personvernspolicy_qa + faq_qa:
183
  if qa_entry['question'].lower() in user_message.lower():
184
-
185
- response = llm_chain.acall(f"User Question: {user_message}\nMatched FAQ:\n{qa_entry}")
186
- return response
187
-
188
- else:
189
- response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
190
-
 
 
 
 
 
 
 
 
 
191
  else:
192
  response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
193
 
 
1
 
2
  # ===========================================
3
+ # ver02.02-Zeta.workload-----app.py
4
  # ===========================================
5
 
6
  import asyncio
 
22
  from langchain.memory import ConversationTokenBufferMemory
23
  from langchain.memory import ConversationSummaryMemory
24
 
 
25
  from api_docs_mck import api_docs_str
26
+
 
27
 
28
  OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
29
 
 
56
  api_url_prompt = PromptTemplate(input_variables=['api_docs', 'question'],
57
  template=api_url_template)
58
 
 
59
 
60
  api_response_template = """
61
  With the API Documentation for Daysoff's official API: {api_docs} in mind,
 
135
  cl.user_session.set("api_chain", api_chain)
136
 
137
 
 
 
 
 
 
138
  @cl.on_message
139
  async def handle_message(message: cl.Message):
140
  user_message = message.content #.lower()
 
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
+ {
185
+ "question": question
186
+ },
187
+ callbacks=[cl.AsyncLangchainCallbackHandler()]
188
+ )
189
+ else:
190
+
191
+ response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
192
+
193
  else:
194
  response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
195