21 lines
659 B
Python
21 lines
659 B
Python
import os
|
||
from langchain.tools import tool
|
||
|
||
@tool
|
||
def get_price(symbol: str) -> str:
|
||
"""Return the current price for a given stock symbol.
|
||
For demo purposes, this function returns a mocked value.
|
||
In a real implementation you would query an API such as Yahoo Finance or Alpha Vantage.
|
||
"""
|
||
# Mocked response – replace with real API call
|
||
prices = {
|
||
"AAPL": 150.12,
|
||
"GOOG": 2750.45,
|
||
"MSFT": 299.87,
|
||
"TSLA": 720.33,
|
||
}
|
||
price = prices.get(symbol.upper(), None)
|
||
if price is None:
|
||
return f"Price for {symbol} not found."
|
||
return f"The current price of {symbol.upper()} is ${price:.2f}."
|