Shreyas094 commited on
Commit
1a40e01
·
verified ·
1 Parent(s): b2fec0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -67,28 +67,33 @@ similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
67
 
68
 
69
  def determine_query_type(query: str, chat_history: str, llm_client) -> str:
70
- system_prompt = """You are Sentinel, an intelligent AI agent tasked with determining whether a user query requires a web search or can be answered using your existing knowledge base. Your task is to analyze the query and decide on the appropriate action.
71
 
72
  Instructions for Sentinel:
73
- 1. If the query is a general conversation starter, greeting, providing Instructions given below, or can be answered without real-time information, classify it as "knowledge_base".
74
- 2. If the query requires up-to-date information, news, or specific data that might change over time, classify it as "web_search".
75
- 3. Consider the chat history when making your decision.
76
- 4. Respond with ONLY "knowledge_base" or "web_search".
 
77
 
78
  Instructions for users (include this in your first interaction):
79
  "Hello! I'm Sentinel, your AI assistant. I can help you with various tasks and answer your questions. Here's how to get the best results:
80
- - For general knowledge questions or conversational topics, just ask normally.
81
- - For recent news, current events, or real-time data, mention that you need up-to-date information.
82
- - If you're unsure, you can ask 'Do you need to search the web for this?'
83
  - Feel free to ask follow-up questions or request clarification on any topic.
 
84
 
85
  How can I assist you today?"
86
 
87
  Examples:
88
  - "Hi, how are you?" -> "knowledge_base"
 
89
  - "What's the latest news in the US?" -> "web_search"
90
  - "Can you explain quantum computing?" -> "knowledge_base"
91
  - "What are the current stock prices for Apple?" -> "web_search"
 
 
92
  """
93
 
94
  user_prompt = f"""
@@ -115,7 +120,7 @@ def determine_query_type(query: str, chat_history: str, llm_client) -> str:
115
  return "web_search" if decision == "web_search" else "knowledge_base"
116
  except Exception as e:
117
  logger.error(f"Error determining query type: {e}")
118
- return "web_search" # Default to web search if there's an error # Default to web search if there's an error
119
 
120
  def generate_ai_response(query: str, chat_history: str, llm_client, model: str) -> str:
121
  system_prompt = """You are a helpful AI assistant. Provide a concise and informative response to the user's query based on your existing knowledge. Do not make up information or claim to have real-time data."""
 
67
 
68
 
69
  def determine_query_type(query: str, chat_history: str, llm_client) -> str:
70
+ system_prompt = """You are Sentinel, an intelligent AI agent tasked with determining whether a user query requires a web search or can be answered using your existing knowledge base. Your knowledge cutoff date is 2023, and the current year is 2024. Your task is to analyze the query and decide on the appropriate action.
71
 
72
  Instructions for Sentinel:
73
+ 1. If the query is a general conversation starter, greeting, or can be answered with information from 2023 or earlier, classify it as "knowledge_base".
74
+ 2. If the query requires information from 2024, up-to-date news, current events, or real-time data, classify it as "web_search".
75
+ 3. For queries about ongoing events, trends, or situations that likely have significant updates in 2024, classify as "web_search".
76
+ 4. Consider the chat history when making your decision.
77
+ 5. Respond with ONLY "knowledge_base" or "web_search".
78
 
79
  Instructions for users (include this in your first interaction):
80
  "Hello! I'm Sentinel, your AI assistant. I can help you with various tasks and answer your questions. Here's how to get the best results:
81
+ - My knowledge base is current up to 2023. For information up to that year, I can answer directly.
82
+ - For any information, events, or data from 2024 onwards, I'll need to search the web for the most up-to-date results.
83
+ - If you're asking about ongoing situations or need the very latest information, please mention that you need current data.
84
  - Feel free to ask follow-up questions or request clarification on any topic.
85
+ - If you're unsure whether I need to search, you can ask 'Do you need to search the web for this?'
86
 
87
  How can I assist you today?"
88
 
89
  Examples:
90
  - "Hi, how are you?" -> "knowledge_base"
91
+ - "What were the major events of 2023?" -> "knowledge_base"
92
  - "What's the latest news in the US?" -> "web_search"
93
  - "Can you explain quantum computing?" -> "knowledge_base"
94
  - "What are the current stock prices for Apple?" -> "web_search"
95
+ - "Who won the 2024 Super Bowl?" -> "web_search"
96
+ - "What were the key findings of the 2022 climate report?" -> "knowledge_base"
97
  """
98
 
99
  user_prompt = f"""
 
120
  return "web_search" if decision == "web_search" else "knowledge_base"
121
  except Exception as e:
122
  logger.error(f"Error determining query type: {e}")
123
+ return "web_search" # Default to web search if there's an error
124
 
125
  def generate_ai_response(query: str, chat_history: str, llm_client, model: str) -> str:
126
  system_prompt = """You are a helpful AI assistant. Provide a concise and informative response to the user's query based on your existing knowledge. Do not make up information or claim to have real-time data."""