camparchimedes commited on
Commit
8e535ba
·
verified ·
1 Parent(s): b7402a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -35
app.py CHANGED
@@ -11,8 +11,6 @@ import torch
11
  import logging
12
 
13
  from api_docs_mck import api_docs_str
14
- #from daysoff import daysoff_str ## make daysoff.py, put json info in dict.
15
- #from personvernpolicy import personvernpolicy_str ## make personvernpolicy.py, put json info in dict.
16
 
17
  import chainlit as cl
18
 
@@ -28,7 +26,6 @@ from langchain_huggingface import HuggingFacePipeline
28
  from langchain_huggingface import HuggingFaceEndpoint
29
  from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
30
 
31
- #logging.basicConfig(level=logging.DEBUG)
32
  HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
33
  OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
34
  #HF_INFERENCE_ENDPOINT =
@@ -51,7 +48,6 @@ BOOKING_KEYWORDS = [
51
  "identyfikacyjny płatności"
52
  ]
53
 
54
-
55
  daysoff_assistant_template = """
56
  You are a customer support assistant (’kundeservice AI assistent’) for Daysoff named "Agrippa".
57
  Your primary objective is to provide exceptional, empathetic, and efficient customer service.
@@ -177,9 +173,6 @@ def setup_multiple_chains():
177
 
178
  cl.user_session.set("api_chain", api_chain)
179
 
180
-
181
-
182
-
183
  import logging
184
 
185
  @cl.on_message
@@ -190,7 +183,6 @@ async def handle_message(message: cl.Message):
190
 
191
  api_keywords = ["firmahytteordning", "personvernspolicy"]
192
 
193
- # --check message for a booking ID
194
  try:
195
  # --check message for booking ID
196
  if re.search(r'\b[A-Z]{6}\d{6}\b', user_message):
@@ -214,35 +206,13 @@ async def handle_message(message: cl.Message):
214
  await cl.Message(response.get(response_key, "")).send()
215
  return message.content
216
 
217
- """
218
- @cl.on_message
219
- async def handle_message(message: cl.Message):
220
- user_message = message.content.lower()
221
- llm_chain = cl.user_session.get("llm_chain")
222
- api_chain = cl.user_session.get("api_chain")
223
 
224
- #if any(keyword in user_message for keyword in ["firmahytteordning","personvernspolicy"]):
225
-
226
-
227
- #def is_booking_query(user_message):
228
  #match = re.search(r'\b[A-Z]{6}\d{6}\b', user_message)
229
  #return match is not None # --works boolean
230
  #booked = is_booking_query(user_message)
231
- #if booked:
232
-
233
- if re.search(r'\b[A-Z]{6}\d{6}\b', user_message): # ex. "EQJLCQ362149"
234
-
235
- response = await api_chain.ainvoke(user_message,
236
- callbacks=[cl.AsyncLangchainCallbackHandler()])
237
-
238
- else:
239
- response = await llm_chain.ainvoke(user_message,
240
- callbacks=[cl.AsyncLangchainCallbackHandler()])
241
-
242
-
243
-
244
- response_key = "output" if "output" in response else "text"
245
- await cl.Message(response.get(response_key, "")).send()
246
- return message.content
247
- """
248
 
 
11
  import logging
12
 
13
  from api_docs_mck import api_docs_str
 
 
14
 
15
  import chainlit as cl
16
 
 
26
  from langchain_huggingface import HuggingFaceEndpoint
27
  from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
28
 
 
29
  HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
30
  OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
31
  #HF_INFERENCE_ENDPOINT =
 
48
  "identyfikacyjny płatności"
49
  ]
50
 
 
51
  daysoff_assistant_template = """
52
  You are a customer support assistant (’kundeservice AI assistent’) for Daysoff named "Agrippa".
53
  Your primary objective is to provide exceptional, empathetic, and efficient customer service.
 
173
 
174
  cl.user_session.set("api_chain", api_chain)
175
 
 
 
 
176
  import logging
177
 
178
  @cl.on_message
 
183
 
184
  api_keywords = ["firmahytteordning", "personvernspolicy"]
185
 
 
186
  try:
187
  # --check message for booking ID
188
  if re.search(r'\b[A-Z]{6}\d{6}\b', user_message):
 
206
  await cl.Message(response.get(response_key, "")).send()
207
  return message.content
208
 
 
 
 
 
 
 
209
 
210
+
211
+ #def is_booking_query(user_message):
 
 
212
  #match = re.search(r'\b[A-Z]{6}\d{6}\b', user_message)
213
  #return match is not None # --works boolean
214
  #booked = is_booking_query(user_message)
215
+ #if booked:
216
+ #response = await api_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
217
+ # etc..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218