Spaces:
Sleeping
Sleeping
Update app.py
Browse files18 unmodified lines192021222324252627282930313233343536373816 unmodified lines5556575859606118 unmodified linesreturn "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:"""A tool that fetches the current local time in a specified timezone.Args:timezone: A string representing a valid timezone (e.g., 'America/New_York')."""try:# Create timezone objecttz = pytz.timezone(timezone)# Get current time in that timezonelocal_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")return f"The current local time in {timezone} is: {local_time}"except Exception as e:return f"Error fetching time for timezone '{timezone}': {str(e)}"final_answer = FinalAnswerTool()16 unmodified linesagent = CodeAgent(model=model,tools=[final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,18 unmodified lines1920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818216 unmodified lines9910010110210310410510610710810911011118 unmodified linesreturn "What magic will you build ?"@tooldef reflect_and_summarize(thought: str) -> str:"""Condenses reasoning or intermediate thoughts into a concise summary.Args:thought: Intermediate reasoning or notes from the agent"""summary = thought.strip()if len(summary) > 300:summary = summary[:300] + "..."return f"Key insight: {summary}"@tooldef fetch_json(url: str) -> str:"""Fetches JSON data from a public API endpoint.Args:url: A publicly accessible API endpoint returning JSON"""try:response = requests.get(url, timeout=5)response.raise_for_status()return response.text[:2000] # prevent token explosionexcept Exception as e:return f"Failed to fetch data: {str(e)}"@tooldef list_prompt_templates() -> str:"""Lists available prompt templates loaded from prompts.yaml."""try:return yaml.dump(prompt_templates, sort_keys=False)except Exception as e:return f"Error reading prompts: {str(e)}"@tooldef get_current_time(timezone: str = "UTC",fmt: str = "%Y-%m-%d %H:%M:%S") -> str:"""Returns current time in a specified timezone.Args:timezone: Timezone name (default: UTC)fmt: Datetime format string"""try:tz = pytz.timezone(timezone)return datetime.datetime.now(tz).strftime(fmt)except Exception as e:return f"Invalid timezone or format: {e}"@tooldef validate_final_answer(answer: str) -> str:"""Checks final answer for clarity and completeness."""issues = []if len(answer) < 20:issues.append("Answer too short")if "I don't know" in answer:issues.append("Uncertain response detected")if not issues:return "Answer looks good."return "Potential issues: " + ", ".join(issues)final_answer = FinalAnswerTool()16 unmodified linesagent = CodeAgent(model=model,tools = [reflect_and_summarize,fetch_json,get_current_time,list_prompt_templates,validate_final_answer,final_answer ], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,
app.py+60-10