Ritesh-hf commited on
Commit
997d850
·
verified ·
1 Parent(s): 685977b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -542,6 +542,29 @@ def answer_formatter_node(question, context):
542
  res = response.content
543
  return res
544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
  CURR_CONTEXT = ''
546
 
547
  # @spaces.GPU
@@ -666,11 +689,17 @@ def handle_message(data):
666
  'input': message,
667
  'context': json.dumps(CURR_CONTEXT)
668
  }
669
- response = json_answer_generator(message, context)
670
  emit('response', response, room=session_id)
671
- else:
672
  response = recommendation_node(message)
673
  # response = answer_formatter_node(message, recipes)
 
 
 
 
 
 
674
  if response is None:
675
  response = {'content':"An error occurred while processing your request."}
676
  emit('json_response', response, room=session_id)
 
542
  res = response.content
543
  return res
544
 
545
+ def reguar_answer_node(question, context):
546
+ prompt = f""" You are an highly clever question-answering assistant trained to provide clear and concise answers based on the user query and provided context.
547
+ Your task is to generated answers for the user query based on the context provided.
548
+ Instructions for your response:
549
+ 1. Directly answer the user query. Make use of provided context if necessary.
550
+ 2. Ensure your response is clear and concise.
551
+ 3. Give the answer in json format with a single key named 'content' with value as your response.
552
+ 4. It is important to give response in json format, otherwise the chat may terminate.
553
+
554
+ Please format an answer based on the following user question and context provided:
555
+
556
+ User Question:
557
+ {question}
558
+
559
+ Context:
560
+ {context}
561
+ """
562
+ response = answer_formatter.invoke(
563
+ [SystemMessage(content=prompt)]
564
+ )
565
+ res = response.content
566
+ return res
567
+
568
  CURR_CONTEXT = ''
569
 
570
  # @spaces.GPU
 
689
  'input': message,
690
  'context': json.dumps(CURR_CONTEXT)
691
  }
692
+ response = answer_generator(formated_input, session_id=session_id)
693
  emit('response', response, room=session_id)
694
+ elif task == "recommendation":
695
  response = recommendation_node(message)
696
  # response = answer_formatter_node(message, recipes)
697
+ if response is None:
698
+ response = {'content':"An error occurred while processing your request."}
699
+
700
+ emit('json_response', response, room=session_id)
701
+ else:
702
+ response = reguar_answer_node(message, CURR_CONTEXT)
703
  if response is None:
704
  response = {'content':"An error occurred while processing your request."}
705
  emit('json_response', response, room=session_id)