taha454 commited on
Commit
9adc62a
·
verified ·
1 Parent(s): 74bceba

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +31 -21
agent.py CHANGED
@@ -197,30 +197,40 @@ def get_answer(state: InfoState) -> InfoState :
197
  state["final_answer"] = get_gpt_and_answer(prompt)
198
 
199
  return state
200
-
201
  def get_type(state: InfoState) -> InfoState:
202
  """Choose which tool to use based on question type (WIKI, SEARCH, CODE)."""
203
- print("Getting Type (Gemini)...")
204
-
205
- prompt = f"""
206
- You are a strict classifier.
207
- Your job is to classify the following question into ONE of four categories:
208
-
209
- - WIKI → informative, factual, or science question
210
- - WebInfo → up-to-date, news, or current event question
211
- - MATH → math, numeric, date, or time calculation
212
- - LLM → all others, including links, reasoning, and file-related tasks
213
-
214
- Question: "{state['question']}"
215
-
216
- Rules:
217
- - Reply with exactly one of these words: WIKI, WebInfo, MATH, or LLM
218
- - Output nothing else. No punctuation, no quotes, no explanation.
219
- - If unsure, default to LLM.
220
- """
221
-
222
- state["answer_type"] = get_gpt_and_answer(prompt)
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  return state
225
 
226
 
 
197
  state["final_answer"] = get_gpt_and_answer(prompt)
198
 
199
  return state
200
+
201
  def get_type(state: InfoState) -> InfoState:
202
  """Choose which tool to use based on question type (WIKI, SEARCH, CODE)."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
+ print("Getting Type (Gemini/OpenAI)...")
205
+ q = state["question"].lower()
206
+ if any(w in q for w in ["calculate", "sum", "add", "price", "how much", "date", "time"]):
207
+ state["answer_type"] = "MATH"
208
+ elif any(w in q for w in ["latest", "current", "today", "news"]):
209
+ state["answer_type"] = "WebInfo"
210
+ elif any(w in q for w in ["who", "where", "what", "when", "why", "how many", "which"]):
211
+ state["answer_type"] = "WIKI"
212
+ else:
213
+ try:
214
+ prompt = f"""
215
+ You are a strict classifier.
216
+ Your job is to classify the following question into ONE of four categories:
217
+
218
+ - WIKI → informative, factual, or science question
219
+ - WebInfo → up-to-date, news, or current event question
220
+ - MATH → math, numeric, date, or time calculation
221
+ - LLM → all others, including links, reasoning, and file-related tasks
222
+
223
+ Question: "{state['question']}"
224
+
225
+ Rules:
226
+ - Reply with exactly one of these words: WIKI, WebInfo, MATH, or LLM
227
+ - Output nothing else. No punctuation, no quotes, no explanation.
228
+ - If unsure, default to LLM.
229
+ """
230
+ resp = get_gpt_and_answer(prompt)
231
+ state["answer_type"] = resp.split()[0].strip()
232
+ except:
233
+ state["answer_type"] = "LLM"
234
  return state
235
 
236