Spaces:
Runtime error
Runtime error
add tool function to query price of asset
Browse files2 unmodified lines34567891011121314151617181920212223 unmodified lines464748495051522 unmodified linesimport requestsimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type#Keep this format for the description / args / args description but feel free to modify the tool"""A tool that does nothing yetArgs:arg1: the first argumentarg2: the second argument"""return "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:23 unmodified linescustom_role_conversions=None,)# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)2 unmodified lines34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878823 unmodified lines1121131141151161172 unmodified linesimport requestsimport pytzimport yamlimport jsonfrom tools.final_answer import FinalAnswerToolimport yfinance as yffrom Gradio_UI import GradioUI@tooldef query_market_asset(symbol: str) -> str:"""A universal market data tool to query the current price or level of ANY asset.Supported asset classes include major indices, stocks, ETFs, crypto, and forex.Args:symbol: The specific ticker symbol used by Yahoo Finance. Examples:- Indices (requires '^'): '^GSPC' (S&P 500), '^VIX' (Volatility Index), '^DJI' (Dow Jones), '^IXIC' (Nasdaq)- Equities / ETFs: 'AAPL' (Apple), 'SPY' (SPDR S&P 500 ETF), 'TLT' (20+ Yr Treasury Bond)- Crypto: 'BTC-USD' (Bitcoin), 'ETH-USD' (Ethereum)- Forex: 'EURUSD=X' (EUR/USD rate), 'USDCNH=X' (USD/Offshore RMB)Returns:A JSON-formatted string containing the current price, high/low, timestamp, and asset info."""symbol = symbol.strip().upper()try:ticker = yf.Ticker(symbol)data = ticker.history(period="1d", interval="1m")if not data.empty:latest_row = data.iloc[-1]current_price = float(latest_row['Close'])open_price = float(latest_row['Open'])high_price = float(latest_row['High'])low_price = float(latest_row['Low'])volume = int(latest_row['Volume'])timestamp = str(data.index[-1])result = {"status": "success","symbol": symbol,"current_price": round(current_price, 4),"open": round(open_price, 4),"high": round(high_price, 4),"low": round(low_price, 4),"volume": volume,"timestamp": timestamp,"data_type": "intraday_1m"}else:info = ticker.infocurrent_price = info.get("regularMarketPrice") or info.get("previousClose") or info.get("ask") or info.get("bid")if current_price:result = {"status": "success","symbol": symbol,"current_price": round(float(current_price), 4),"open": info.get("regularMarketOpen") or info.get("open"),"high": info.get("regularMarketDayHigh") or info.get("dayHigh"),"low": info.get("regularMarketDayLow") or info.get("dayLow"),"volume": info.get("regularMarketVolume") or info.get("volume", 0),"short_name": info.get("shortName", ""),"data_type": "cached_info"}else:result = {"status": "error","symbol": symbol,"message": "No price data could be resolved for this asset."}except Exception as e:result = {"status": "error","symbol": symbol,"message": f"Exception occurred while querying: {str(e)}"}return json.dumps(result, ensure_ascii=False, indent=2)@tooldef get_current_time_in_timezone(timezone: str) -> str:23 unmodified linescustom_role_conversions=None,)# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
app.py+75-10