Spaces:
No application file
No application file
Download main.py from aaaasssshish/my-AI-agent-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/aaaasssshish/my-AI-agent-bot/resolve/main/main.py
- Command line
-
hf download hf://spaces/aaaasssshish/my-AI-agent-bot/main.py
-
curl -L -o main.py https://huggingface.co/spaces/aaaasssshish/my-AI-agent-bot/resolve/main/main.py
1.69 kB
| !pip install langchain | |
| !pip install langchain-google-genai | |
| !pip install python-dotenv | |
| !pip install gradio | |
| from dotenv import load_dotenv | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| from langchain_core.tools import tool | |
| from langchain.agents import create_tool_calling_agent, AgentExecutor | |
| from langchain_core.prompts import ChatPromptTemplate | |
| import gradio as gr | |
| load_dotenv() | |
| def calculate(expression: str) -> str: | |
| try: return str(eval(expression)) | |
| except: return "Error" | |
| def calculate(message: str, history: list) ->: | |
| llm= ChatGoogleGenerativeAI(model="gemini-2.5-flash-lite") | |
| system_message= "You are a helpful math assistant. Use the calculator tool when you need to perform calculations." | |
| prompt= ChatPromptTemplate.from_message({("system", system_message), | |
| ("human", "{input}"), | |
| ("placeholder", "{agent_scratchpas}")}) | |
| agent= create_tool_calling_agent | |
| def calculate(message: str, history: list) -> str : | |
| llm= ChatGoogleGenerativeAI(model="gemini-2.5-flash-lite") | |
| system_message= "You are a helpful math assistant. Use the calculator tool when you need to perform calculations." | |
| prompt = ChatPromptTemplate.from_messages([ | |
| ("system", system_message), | |
| ("human", "{input}"), | |
| ("placeholder", "{agent_scratchpad}") | |
| ]) | |
| agent= create_tool_calling_agent(llm, [calculator], prompt) | |
| executer= AgentExecutor(agent=agent, tools=[calculator], verbose=True) | |
| result= executer.invoke({"input": message}) | |
| return result["output"] | |
| if __name__ == "__main__": | |
| print(calculate("2 plus 2", [])) | |