Spaces:
Sleeping
Sleeping
Update agent_backend.py
Browse files12344 unmodified lines910111213141517 unmodified lines333435363738394041424344454647484 unmodified lines53545556575859import osfrom dotenv import load_dotenv4 unmodified linesfrom langchain.agents import AgentTypefrom langchain_community.tools import DuckDuckGoSearchRunfrom langchain.chains.llm_math.base import LLMMathChain# -----------------------------------# Load environment variables17 unmodified lines)# -----------------------------------# Calculator Tool# -----------------------------------math_chain = LLMMathChain.from_llm(llm=llm)calculator_tool = Tool(name="Calculator",func=math_chain.run,description="Useful for math calculations.")# -----------------------------------4 unmodified linessearch_tool = Tool(name="Web Search",func=search.run,description="Useful for searching the internet.")# -----------------------------------123454 unmodified lines10111213141517 unmodified lines33343536373839404142434445464748495051525354555657585960616263646566676869704 unmodified lines75767778798081828384import osimport mathfrom dotenv import load_dotenv4 unmodified linesfrom langchain.agents import AgentTypefrom langchain_community.tools import DuckDuckGoSearchRun# -----------------------------------# Load environment variables17 unmodified lines)# -----------------------------------# Simple Calculator Tool# -----------------------------------def calculator(expression):try:allowed_names = {"sqrt": math.sqrt,"pow": pow,"abs": abs,"round": round}result = eval(expression,{"__builtins__": {}},allowed_names)return str(result)except Exception as e:return f"Calculation error: {str(e)}"calculator_tool = Tool(name="Calculator",func=calculator,description=("Useful for solving math calculations. ""Input should be a valid math expression."))# -----------------------------------4 unmodified linessearch_tool = Tool(name="Web Search",func=search.run,description=("Useful for searching current information ""from the internet."))# -----------------------------------
agent_backend.py+33-8