Spaces:
Build error
Build error
Delete test_agent.py
Browse files- test_agent.py +0 -29
test_agent.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 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 |
-
|
| 5 |
-
# Make sure OpenAI key is set in your environment
|
| 6 |
-
import os
|
| 7 |
-
os.environ["OPENAI_API_KEY"] = ""
|
| 8 |
-
|
| 9 |
-
# Define tools
|
| 10 |
-
tools = [
|
| 11 |
-
Tool(
|
| 12 |
-
name="GetStockPrice",
|
| 13 |
-
func=get_price,
|
| 14 |
-
description="Get the current price of a stock by its ticker symbol, e.g., 'AAPL'"
|
| 15 |
-
),
|
| 16 |
-
Tool(
|
| 17 |
-
name="BuyingPowerCalculator",
|
| 18 |
-
func=lambda q: buying_power_tool(q.split(',')[0], float(q.split(',')[1])),
|
| 19 |
-
description="Calculate how many shares you can buy. Input format: 'AAPL,5000'"
|
| 20 |
-
)
|
| 21 |
-
]
|
| 22 |
-
|
| 23 |
-
# Create agent
|
| 24 |
-
llm = ChatOpenAI(model="gpt-4", temperature=0)
|
| 25 |
-
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
| 26 |
-
|
| 27 |
-
# Run a test
|
| 28 |
-
response = agent.run("How much is AAPL?")
|
| 29 |
-
print(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|