Spaces:
Build error
Build error
Merge branch 'main' of https://huggingface.co/spaces/Shipmaster1/Agent_Langgraph into main
Browse files- test_agent.py +30 -0
test_agent.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.chat_models import ChatOpenAI
|
| 2 |
+
from langchain.agents import initialize_agent, Tool, AgentType
|
| 3 |
+
from tools import get_price, buying_power_tool
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Load environment variables from .env file
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Define tools
|
| 11 |
+
tools = [
|
| 12 |
+
Tool(
|
| 13 |
+
name="GetStockPrice",
|
| 14 |
+
func=get_price,
|
| 15 |
+
description="Get the current price of a stock by its ticker symbol, e.g., 'AAPL'"
|
| 16 |
+
),
|
| 17 |
+
Tool(
|
| 18 |
+
name="BuyingPowerCalculator",
|
| 19 |
+
func=lambda q: buying_power_tool(q.split(',')[0], float(q.split(',')[1])),
|
| 20 |
+
description="Calculate how many shares you can buy. Input format: 'AAPL,5000'"
|
| 21 |
+
)
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
# Create agent
|
| 25 |
+
llm = ChatOpenAI(model="gpt-4", temperature=0)
|
| 26 |
+
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
| 27 |
+
|
| 28 |
+
# Run a test
|
| 29 |
+
response = agent.run("How much is AAPL?")
|
| 30 |
+
print(response)
|