Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,26 +9,47 @@ import os
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
|
|
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
-
def get_equity_symbol(keyword:str)->
|
| 15 |
"""A tool that search the symbol of equity (company).
|
| 16 |
Args:
|
| 17 |
equity_name: name of the equity or company
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
url = f'https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords={keyword}&apikey={AlPHA_VANTAGE_KEY}'
|
| 21 |
response = requests.get(url)
|
| 22 |
data = response.json()
|
| 23 |
filtered_data = []
|
| 24 |
for data in data:
|
| 25 |
-
filtered_data.append({'symbol':data['1. symbol'],'
|
| 26 |
|
| 27 |
return filtered_data
|
| 28 |
|
| 29 |
|
| 30 |
@tool
|
| 31 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 34 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -66,7 +87,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 66 |
|
| 67 |
agent = CodeAgent(
|
| 68 |
model=model,
|
| 69 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 70 |
max_steps=6,
|
| 71 |
verbosity_level=1,
|
| 72 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
+
AlPHA_VANTAGE_KEY = os.getenv('ALPHA_VANTAGE_KEY')
|
| 13 |
+
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
+
def get_equity_symbol(keyword:str)-> list:
|
| 17 |
"""A tool that search the symbol of equity (company).
|
| 18 |
Args:
|
| 19 |
equity_name: name of the equity or company
|
| 20 |
+
Returns:
|
| 21 |
+
filtered_data: a list of dicts which included highly similar symbol of the equity and its region
|
| 22 |
"""
|
| 23 |
+
|
| 24 |
url = f'https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords={keyword}&apikey={AlPHA_VANTAGE_KEY}'
|
| 25 |
response = requests.get(url)
|
| 26 |
data = response.json()
|
| 27 |
filtered_data = []
|
| 28 |
for data in data:
|
| 29 |
+
filtered_data.append({'symbol':data['1. symbol'],'region':data['4. region']})
|
| 30 |
|
| 31 |
return filtered_data
|
| 32 |
|
| 33 |
|
| 34 |
@tool
|
| 35 |
+
def get_daily_timeseries(symbol:str) -> pd.DataFrame:
|
| 36 |
+
"""A tool that fetches the daily time series data for the equity.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
symbol: A string representing a valid equity symbol ( e.g., IBM)
|
| 40 |
+
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
url = f'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={symbol}&apikey={AlPHA_VANTAGE_KEY}'
|
| 44 |
+
r = requests.get(url)
|
| 45 |
+
data = r.json()
|
| 46 |
+
timeseries = (pd.DataFrame(data['Time Series (Daily)']).T).set_index(pd.to_datetime(timeseries.index, format="%Y-%m-%d"), inplace=True)
|
| 47 |
+
columns = [columns.split(' ')[-1] for columns in timeseries.columns]
|
| 48 |
+
timeseries.columns = columns
|
| 49 |
+
|
| 50 |
+
return timeseries.iloc[:1,:]
|
| 51 |
+
|
| 52 |
+
|
| 53 |
@tool
|
| 54 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 55 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 87 |
|
| 88 |
agent = CodeAgent(
|
| 89 |
model=model,
|
| 90 |
+
tools=[final_answer, get_equity_symbol,get_daily_timeseries], ## add your tools here (don't remove final answer)
|
| 91 |
max_steps=6,
|
| 92 |
verbosity_level=1,
|
| 93 |
grammar=None,
|