add tools.py
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Utility module that defines the tool(s) used by the streaming agent.
|
||||
|
||||
The project currently contains a single mock ``get_price`` function. The
|
||||
implementation is intentionally tiny – it simply looks up a hard‑coded price
|
||||
in a dictionary. In real projects this would be replaced with an API call or
|
||||
database query.
|
||||
"""
|
||||
|
||||
from langchain.tools import tool
|
||||
|
||||
@tool
|
||||
def get_price(product: str, city: str) -> str:
|
||||
"""Return a fake price for *product* in *city*.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
product : str
|
||||
Name of the product (e.g. ``milk``).
|
||||
city : str
|
||||
City where the price is requested.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
A string describing the price, e.g. ``"89 rubles"``.
|
||||
"""
|
||||
prices = {
|
||||
("milk", "kazan"): "89",
|
||||
("bread", "kazan"): "45",
|
||||
("coffee", "moscow"): "120",
|
||||
}
|
||||
key = (product.lower(), city.lower())
|
||||
price = prices.get(key, "unknown")
|
||||
return f"{price} rubles"
|
||||
|
||||
# End of tools.py
|
||||
Reference in New Issue
Block a user