diff --git a/examples/tools/__init__.py b/examples/tools/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/tools/application.py b/examples/tools/application.py new file mode 100644 index 00000000..709ca6b7 --- /dev/null +++ b/examples/tools/application.py @@ -0,0 +1,59 @@ +from ast import literal_eval +from typing import Tuple + +import yfinance as yf + +from burr.core import State, action + + +@action(reads=[], writes=["tool_params"]) +def determine_tool(state: State, prompt: str) -> Tuple[dict, State]: + # uses the anthropic API to choose which tool to use + pass + + +@action(reads=["tool_params"], writes=["response"]) +def calculator_tool(state: State) -> Tuple[dict, State]: + # tool to perform calculations + tool_params = state["tool_params"] + result = literal_eval(tool_params["expression"]) + response = { + "raw_result": "result", + "text_response": f"The result of {tool_params['expression']} is {result}", + } + return {"raw_result": result, "response": response}, state.update(response=response) + + +@action(reads=["tool_params"], writes=["response"]) +def stock_lookup_tool(state: State) -> Tuple[dict, State]: + # tool to lookup stock prices + tool_params = state["tool_params"] + ticker = tool_params["ticker"] + stock = yf.Ticker(ticker) + hist = stock.history(period="1d") + current_price = hist["Close"][-1] + return { + "raw_result": current_price, + "response": { + "raw_result": current_price, + "text_response": f"The current price of {ticker} is {current_price}", + }, + }, state.update( + response={ + "raw_result": current_price, + "text_response": f"The current price of {ticker} is {current_price}", + } + ) + + +@action(reads=["tool_params"], writes=["response"]) +def weather_lookup_tool(state: State) -> Tuple[dict, State]: + # tool_params = state["tool_params"] + # city = tool_params["city"] + # TODO -- use this to get the weather: https://pypi.org/project/openmeteo-py/0.0.1/ + pass + + +def fallback_tool(state: State) -> Tuple[dict, State]: + # fallback tool + pass diff --git a/examples/tools/requirements.txt b/examples/tools/requirements.txt new file mode 100644 index 00000000..29d91af4 --- /dev/null +++ b/examples/tools/requirements.txt @@ -0,0 +1 @@ +yfinance