-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
python/examples/miscellaneous/runtime_tools/langchain_math.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Initialise imports | ||
# Import from composio_langchain | ||
from composio_langchain import Action, App, ComposioToolSet | ||
from composio import action | ||
from langchain import hub | ||
from langchain.agents import AgentExecutor, create_openai_functions_agent | ||
from langchain_openai import ChatOpenAI | ||
|
||
@action(toolname="math", requires=["smtplib"]) | ||
def multiply(a: int, b: int, c: int) -> int: | ||
""" | ||
Multiply three numbers | ||
:param a: Number a | ||
:param b: Number b | ||
:param c: Number c | ||
:return result: Result of the multiplication | ||
""" | ||
return a * b * c | ||
|
||
|
||
llm = ChatOpenAI(model="gpt-4-turbo") | ||
|
||
prompt = hub.pull("hwchase17/openai-functions-agent") | ||
|
||
# Get All the tools | ||
tools = ComposioToolSet().get_tools(actions=[multiply]) | ||
task = "Calculate the formula 445*669*8886" | ||
|
||
agent = create_openai_functions_agent(llm, tools, prompt) | ||
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) | ||
|
||
# Execute using agent_executor | ||
agent_executor.invoke({"input": task}) |