Shreyas094 commited on
Commit
536a45b
·
verified ·
1 Parent(s): d55e623

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -53
app.py CHANGED
@@ -672,60 +672,65 @@ class ChatBot:
672
  return f"Error occurred: {str(e)}"
673
 
674
  async def get_response(self,
675
- query: str,
676
- history: List[List[str]],
677
- num_results: int,
678
- max_chars: int,
679
- score_threshold: float,
680
- temperature: float,
681
- scoring_method: str,
682
- selected_engines: List[str],
683
- safe_search: str,
684
- language: str,
685
- force_web_search: bool = False) -> str:
686
- """Determine query type and route to appropriate handler with context."""
687
- logger.info(f'Processing query: {query}')
688
- try:
689
- # Update conversation history
690
- formatted_history = self.format_chat_history(history)
691
- logger.info(f'Current conversation context:\n{formatted_history}')
692
-
693
- # If force_web_search is True, skip query type determination
694
- if force_web_search:
695
- logger.info('Force web search mode enabled - bypassing query type determination')
696
- query_type = QueryType.WEB_SEARCH
697
- else:
698
- # Determine query type with context
699
- query_type = await determine_query_type(query, history, temperature)
700
-
701
- if query_type == QueryType.KNOWLEDGE_BASE and not force_web_search:
702
- logger.info('Using knowledge base to answer query')
703
- response = await process_knowledge_base_query(
704
- query=query,
705
- chat_history=history,
706
- temperature=temperature
707
- )
708
- else:
709
- logger.info('Using web search to answer query')
710
- response = await self.get_search_results(
711
- query=query,
712
- history=history,
713
- num_results=num_results,
714
- max_chars=max_chars,
715
- score_threshold=score_threshold,
716
- temperature=temperature,
717
- scoring_method=scoring_method,
718
- selected_engines=selected_engines,
719
- safe_search=safe_search,
720
- language=language
721
- )
722
-
723
- logger.info(f'Generated response type: {query_type}')
724
- return response
 
 
725
 
726
- except Exception as e:
727
- logger.error(f'Error in get_response: {e}')
728
- return f"I apologize, but I encountered an error: {str(e)}"
 
 
 
729
 
730
  def chat(self,
731
  message: str,
 
672
  return f"Error occurred: {str(e)}"
673
 
674
  async def get_response(self,
675
+ query: str,
676
+ history: List[List[str]],
677
+ num_results: int,
678
+ max_chars: int,
679
+ score_threshold: float,
680
+ temperature: float,
681
+ scoring_method: str,
682
+ selected_engines: List[str],
683
+ safe_search: str,
684
+ language: str,
685
+ force_web_search: bool = False) -> str:
686
+ """Determine query type and route to appropriate handler with context."""
687
+ logger.info(f'Processing query: {query}')
688
+ try:
689
+ # Update conversation history
690
+ formatted_history = self.format_chat_history(history)
691
+ logger.info(f'Current conversation context:\n{formatted_history}')
692
+
693
+ # Convert the force_web_search radio button value to boolean
694
+ force_web_search = force_web_search == "Web Search Only"
695
+ logger.info(f'Force web search mode: {force_web_search}')
696
+
697
+ # If force_web_search is True, skip query type determination
698
+ if force_web_search:
699
+ logger.info('Force web search mode enabled - bypassing query type determination')
700
+ query_type = QueryType.WEB_SEARCH
701
+ else:
702
+ # Determine query type with context
703
+ query_type = await determine_query_type(query, history, temperature)
704
+ logger.info(f'Query type determined as: {query_type}')
705
+
706
+ if query_type == QueryType.KNOWLEDGE_BASE and not force_web_search:
707
+ logger.info('Using knowledge base to answer query')
708
+ response = await process_knowledge_base_query(
709
+ query=query,
710
+ chat_history=history,
711
+ temperature=temperature
712
+ )
713
+ else:
714
+ logger.info('Using web search to answer query')
715
+ response = await self.get_search_results(
716
+ query=query,
717
+ history=history,
718
+ num_results=num_results,
719
+ max_chars=max_chars,
720
+ score_threshold=score_threshold,
721
+ temperature=temperature,
722
+ scoring_method=scoring_method,
723
+ selected_engines=selected_engines,
724
+ safe_search=safe_search,
725
+ language=language
726
+ )
727
 
728
+ logger.info(f'Generated response type: {query_type}')
729
+ return response
730
+
731
+ except Exception as e:
732
+ logger.error(f'Error in get_response: {e}')
733
+ return f"I apologize, but I encountered an error: {str(e)}"
734
 
735
  def chat(self,
736
  message: str,