STARX33 commited on
Commit
fa3e9dc
·
verified ·
1 Parent(s): 78b3c32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -78,11 +78,14 @@ def get_current_time_in_timezone(timezone: str) -> str:
78
  return f"Error fetching time for timezone '{timezone}': {e}"
79
 
80
  # -----------------------------------------------------------------------------
81
- # 2) LOAD PROMPTS & INSTANTIATE YOUR AGENT (unchanged)
82
  # -----------------------------------------------------------------------------
83
  with open("prompts.yaml", "r") as f:
84
  prompt_templates = yaml.safe_load(f)
85
 
 
 
 
86
  final_answer = FinalAnswerTool()
87
  web_search = DuckDuckGoSearchTool()
88
  # If you need your text-to-image tool, uncomment:
@@ -111,9 +114,23 @@ class BasicAgent:
111
  description="Your friendly AI agent to help you with any task",
112
  prompt_templates=prompt_templates,
113
  )
 
 
114
 
115
  def __call__(self, question: str) -> str:
116
- return self.agent.run(question)
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
  # -----------------------------------------------------------------------------
119
  # 3) EVALUATION LOGIC (unchanged)
 
78
  return f"Error fetching time for timezone '{timezone}': {e}"
79
 
80
  # -----------------------------------------------------------------------------
81
+ # 2) LOAD PROMPTS & INSTANTIATE YOUR AGENT
82
  # -----------------------------------------------------------------------------
83
  with open("prompts.yaml", "r") as f:
84
  prompt_templates = yaml.safe_load(f)
85
 
86
+ # extract the fallback map from YAML
87
+ rag_fallbacks = prompt_templates.get("rag_fallbacks", {})
88
+
89
  final_answer = FinalAnswerTool()
90
  web_search = DuckDuckGoSearchTool()
91
  # If you need your text-to-image tool, uncomment:
 
114
  description="Your friendly AI agent to help you with any task",
115
  prompt_templates=prompt_templates,
116
  )
117
+ # keep the fallback map on the instance
118
+ self.rag_fallbacks = rag_fallbacks
119
 
120
  def __call__(self, question: str) -> str:
121
+ # first, try to run the agent
122
+ try:
123
+ answer = self.agent.run(question)
124
+ except Exception:
125
+ answer = ""
126
+
127
+ # if no answer or clearly failed, look for a keyword in our fallback map
128
+ if not answer or answer.strip().lower().startswith("i'm sorry"):
129
+ q_low = question.lower()
130
+ for key, val in self.rag_fallbacks.items():
131
+ if key in q_low:
132
+ return val
133
+ return answer
134
 
135
  # -----------------------------------------------------------------------------
136
  # 3) EVALUATION LOGIC (unchanged)