-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_langchain_agents.py
More file actions
37 lines (29 loc) · 999 Bytes
/
06_langchain_agents.py
File metadata and controls
37 lines (29 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from langchain.agents import initialize_agent, AgentType
from langchain_google_genai import GoogleGenerativeAI
from langchain.tools import tool
import os
from dotenv import load_dotenv
load_dotenv()
# Initialize the LLM with GoogleGenerativeAI
llm = GoogleGenerativeAI(model="gemini-1.5-flash",
google_api_key=os.getenv("GEMINI_API_KEY"))
# tool creating for addition of two numbers
@tool
def add_numbers_tool(input_data: str) -> str:
""" addition of two numbers. """
print("add_numbers_tool input_data",input_data)
try:
numbers = input_data.split(',')
except Exception as e:
return input_data
num1, num2 = int(numbers[0]), int(numbers[1])
result = num1 + num2
return f"The Sum of {num1} and {num2} is {result}"
agent = initialize_agent(
tools=[add_numbers_tool],
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
llm=llm,
verbose=True,
max_iterations=1,
)
agent.run("first number is 10 second is 5")