Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP for tools #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added examples/tools/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions examples/tools/application.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions examples/tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yfinance
Loading