Spaces:
Sleeping
Sleeping
hqblock
commited on
Commit
·
cbe220b
1
Parent(s):
c8c70df
Add own tool
Browse files- app.py +32 -8
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,23 +1,47 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, OpenAIServerModel,load_tool,tool
|
2 |
import os
|
3 |
import datetime
|
4 |
-
import requests
|
5 |
import pytz
|
6 |
import yaml
|
7 |
from tools.final_answer import FinalAnswerTool
|
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
|
|
|
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
Args:
|
16 |
arg1: the first argument
|
17 |
arg2: the second argument
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
|
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
23 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -49,10 +73,10 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
49 |
|
50 |
with open("prompts.yaml", 'r') as stream:
|
51 |
prompt_templates = yaml.safe_load(stream)
|
52 |
-
|
53 |
agent = CodeAgent(
|
54 |
model=model,
|
55 |
-
tools=[image_generation_tool,get_current_time_in_timezone,final_answer,DuckDuckGoSearchTool()],
|
56 |
max_steps=6,
|
57 |
verbosity_level=1,
|
58 |
grammar=None,
|
@@ -63,4 +87,4 @@ agent = CodeAgent(
|
|
63 |
)
|
64 |
|
65 |
|
66 |
-
GradioUI(agent).launch()
|
|
|
1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, load_tool, tool
|
2 |
import os
|
3 |
import datetime
|
4 |
+
# import requests
|
5 |
import pytz
|
6 |
import yaml
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
+
from alpha_vantage.timeseries import TimeSeries
|
9 |
|
10 |
from Gradio_UI import GradioUI
|
11 |
|
12 |
+
alpha_api_key = os.getenv("alpha_api_key")
|
13 |
+
|
14 |
+
|
15 |
@tool
|
16 |
+
def get_stock_price(ticker: str) -> str:
|
17 |
+
"""A tool that gets stock price
|
18 |
+
Args:
|
19 |
+
ticker: A string representing a valid stock symbol (e.g. NVDA)
|
20 |
+
"""
|
21 |
+
ticker_symbol = ticker.upper()
|
22 |
+
# Create a TimeSeries object
|
23 |
+
ts = TimeSeries(key=alpha_api_key, output_format='pandas')
|
24 |
+
# Get the latest stock data
|
25 |
+
data, meta_data = ts.get_intraday(symbol=ticker_symbol, interval='1min', outputsize='compact')
|
26 |
+
if not data.empty:
|
27 |
+
# Print the latest closing price (intraday data)
|
28 |
+
# print(f"The current price of {ticker_symbol} is ${data['4. close'][0]:.2f}")
|
29 |
+
return (f"${data['4. close'][0]:.2f}")
|
30 |
+
else:
|
31 |
+
return ("Error: Failed to retrieve stock data.")
|
32 |
+
|
33 |
+
|
34 |
+
@tool
|
35 |
+
def hqtool(arg1: str, arg2: int) -> str: # it's import to specify the return type
|
36 |
+
# Keep this format for the description / args / args description but feel free to modify the tool
|
37 |
+
"""A tool that does nothing yet
|
38 |
Args:
|
39 |
arg1: the first argument
|
40 |
arg2: the second argument
|
41 |
"""
|
42 |
return "What magic will you build ?"
|
43 |
|
44 |
+
|
45 |
@tool
|
46 |
def get_current_time_in_timezone(timezone: str) -> str:
|
47 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
73 |
|
74 |
with open("prompts.yaml", 'r') as stream:
|
75 |
prompt_templates = yaml.safe_load(stream)
|
76 |
+
|
77 |
agent = CodeAgent(
|
78 |
model=model,
|
79 |
+
tools=[get_stock_price, image_generation_tool, get_current_time_in_timezone, final_answer, DuckDuckGoSearchTool()], # add or remove tools here
|
80 |
max_steps=6,
|
81 |
verbosity_level=1,
|
82 |
grammar=None,
|
|
|
87 |
)
|
88 |
|
89 |
|
90 |
+
GradioUI(agent).launch()
|
requirements.txt
CHANGED
@@ -4,3 +4,4 @@ requests
|
|
4 |
duckduckgo_search
|
5 |
pandas
|
6 |
smolagents[openai]
|
|
|
|
4 |
duckduckgo_search
|
5 |
pandas
|
6 |
smolagents[openai]
|
7 |
+
alpha_vantage
|