FrederickSundeep commited on
Commit
cc7609b
Β·
1 Parent(s): f112ebb

commit 000432

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -52,18 +52,19 @@ parser = StrOutputParser()
52
 
53
  basic_chain = prompt | llm | parser # This is a Runnable
54
 
55
- # Define a function to decide if we need web search
 
 
56
  def should_search(input_dict):
57
  question = input_dict.get("question", "").lower()
58
- keywords = ["latest", "current", "news", "today", "price", "time", "live", "recent"]
59
- return any(k in question for k in keywords)
60
 
61
  search_tool = DuckDuckGoSearchRun()
62
 
63
- # Chain that runs DuckDuckGo search
64
  search_chain = (
65
  RunnableLambda(lambda q: {"question": search_tool.run(q["question"])}) |
66
- RunnableLambda(lambda d: f"Search result: {d['question']}")
67
  )
68
 
69
  # Main chain with conditional logic
 
52
 
53
  basic_chain = prompt | llm | parser # This is a Runnable
54
 
55
+ # βœ… Enhanced keyword detection
56
+ REAL_TIME_KEYWORDS = {"latest", "current", "news", "today", "price", "time", "live", "trending", "update", "happening"}
57
+
58
  def should_search(input_dict):
59
  question = input_dict.get("question", "").lower()
60
+ return any(kw in question for kw in REAL_TIME_KEYWORDS)
 
61
 
62
  search_tool = DuckDuckGoSearchRun()
63
 
64
+ # βœ… Refined search chain returns clean results
65
  search_chain = (
66
  RunnableLambda(lambda q: {"question": search_tool.run(q["question"])}) |
67
+ RunnableLambda(lambda d: f"(Live info) {d['question']}")
68
  )
69
 
70
  # Main chain with conditional logic