Spaces:
Sleeping
Sleeping
Update app.py
Browse files40 unmodified lines4142434445469 unmodified lines56575859606162636465666768697071727374756 unmodified lines8283848586878889909192939495969798991001011022 unmodified lines10510610710810940 unmodified linesreturn f"Error fetching time for timezone '{timezone}': {str(e)}"final_answer = FinalAnswerTool()# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:9 unmodified lineslitellm.drop_params = Truegemini_key = (os.getenv("GEMINI_API_KEY") or "").strip(" '\"\n\r\t") or Noneif gemini_key:os.environ["GEMINI_API_KEY"] = gemini_keymoonshot_key = (os.getenv("MOONSHOT_API_KEY") or "").strip(" '\"\n\r\t") or Noneif moonshot_key:os.environ["MOONSHOT_API_KEY"] = moonshot_keyimport litellmfrom smolagents import LiteLLMModellitellm.drop_params = Trueopenrouter_key = (os.getenv("OPENROUTER_API_KEY") or "").strip(" '\"\n\r\t") or Noneif openrouter_key:os.environ["OPENROUTER_API_KEY"] = openrouter_key6 unmodified linestimeout=30,)# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)with open("prompts.yaml", 'r') as stream:prompt_templates = yaml.safe_load(stream)agent = CodeAgent(model=model,tools=[final_answer,DuckDuckGoSearchTool(),get_current_time_in_timezone,image_generation_tool,],max_steps=6,verbosity_level=1,grammar=None,planning_interval=None,2 unmodified linesprompt_templates=prompt_templates,)GradioUI(agent).launch()40 unmodified lines414243444546474849505152535455565758596061626364659 unmodified lines7576777879806 unmodified lines878889909192939495969798991001011021031041051061071081091101111121131141151161172 unmodified lines12012112212340 unmodified linesreturn f"Error fetching time for timezone '{timezone}': {str(e)}"@tooldef fetch_url_text(url: str) -> str:"""Fetches readable text snippet from a given URL.Args:url: The HTTP/HTTPS URL to fetch."""try:response = requests.get(url,timeout=15,headers={"User-Agent": "Mozilla/5.0"},)response.raise_for_status()text = response.textreturn text[:4000]except Exception as e:return f"Error fetching URL '{url}': {str(e)}"final_answer = FinalAnswerTool()# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:9 unmodified lineslitellm.drop_params = Trueopenrouter_key = (os.getenv("OPENROUTER_API_KEY") or "").strip(" '\"\n\r\t") or Noneif openrouter_key:os.environ["OPENROUTER_API_KEY"] = openrouter_key6 unmodified linestimeout=30,)with open("prompts.yaml", "r") as stream:prompt_templates = yaml.safe_load(stream) or {}exact_match_rule = ("\n\nCRITICAL OUTPUT RULES FOR EXACT MATCH EVALUATION:\n""- When calling final_answer, pass ONLY the concise exact answer value itself ""(e.g. a number, date, name, or short phrase).\n""- NEVER include introductory text, explanations, markdown formatting, or the phrase 'FINAL ANSWER'.\n""- Do not wrap the answer in a dictionary like {'answer': ...}; pass the plain answer string directly.")if isinstance(prompt_templates, dict) and "system_prompt" in prompt_templates:prompt_templates["system_prompt"] = str(prompt_templates["system_prompt"]) + exact_match_ruleelse:prompt_templates = {"system_prompt": exact_match_rule.strip()}agent = CodeAgent(model=model,tools=[final_answer,DuckDuckGoSearchTool(),fetch_url_text,get_current_time_in_timezone,],max_steps=10,verbosity_level=1,grammar=None,planning_interval=None,2 unmodified linesprompt_templates=prompt_templates,)GradioUI(agent).launch()
app.py+36-22