-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First commit * Update lock * add benchmakr * add to readme * Review * Added deployment instructions * Unified function calls for local- and remote runner. * Small fixes * Small typo before PR review * Deployment working * Version for hackathon * Fixed mypy * Fixed mypy (2) --------- Co-authored-by: Peter Jung <[email protected]>
- Loading branch information
1 parent
81f6942
commit 5f54e1f
Showing
13 changed files
with
1,173 additions
and
1,336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
OPENAI_API_KEY= | ||
TAVILY_API_KEY= | ||
BET_FROM_PRIVATE_KEY= | ||
GNOSIS_RPC_URL= # Feel free to use Tenderly to overwrite the RPC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from microchain import Function | ||
|
||
|
||
class Sum(Function): | ||
@property | ||
def description(self) -> str: | ||
return "Use this function to compute the sum of two numbers" | ||
|
||
@property | ||
def example_args(self) -> list[float]: | ||
return [2, 2] | ||
|
||
def __call__(self, a: float, b: float) -> float: | ||
return a + b | ||
|
||
|
||
class Product(Function): | ||
@property | ||
def description(self) -> str: | ||
return "Use this function to compute the product of two numbers" | ||
|
||
@property | ||
def example_args(self) -> list[int]: | ||
return [2, 2] | ||
|
||
def __call__(self, a: float, b: float) -> float: | ||
return a * b | ||
|
||
|
||
class GreaterThan(Function): | ||
@property | ||
def description(self) -> str: | ||
return ( | ||
"Use this function to assess if one number is greater than the other number" | ||
) | ||
|
||
@property | ||
def example_args(self) -> list[float]: | ||
return [2, 2] | ||
|
||
def __call__(self, a: float, b: float) -> bool: | ||
return a > b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import typer | ||
from dotenv import load_dotenv | ||
from microchain import OpenAIChatGenerator, LLM, Agent, Engine | ||
from microchain.functions import Reasoning, Stop | ||
from prediction_market_agent_tooling.config import APIKeys | ||
|
||
from general_agent.functions import Sum, Product, GreaterThan | ||
from general_agent.web3_functions import GetBalance, GetOwnWallet | ||
|
||
|
||
def main() -> None: | ||
# Load the environment variables. | ||
load_dotenv() | ||
keys = APIKeys() | ||
generator = OpenAIChatGenerator( | ||
model="gpt-3.5-turbo", | ||
api_key=keys.openai_api_key.get_secret_value(), | ||
api_base="https://api.openai.com/v1", | ||
temperature=0.7, | ||
) | ||
|
||
engine = Engine() | ||
engine.register(Reasoning()) | ||
engine.register(Stop()) | ||
engine.register(Sum()) | ||
engine.register(Product()) | ||
engine.register(GreaterThan()) | ||
engine.register(GetBalance()) | ||
engine.register(GetOwnWallet()) | ||
|
||
agent = Agent(llm=LLM(generator=generator), engine=engine) | ||
|
||
agent.max_tries = 3 | ||
# How much is (2*4 + 3)*5? | ||
agent.prompt = ( | ||
agent.prompt | ||
) = f"""Act as a trader on-chain. You can use the following functions: | ||
{engine.help} | ||
Only output valid Python function calls. | ||
Output the balance of the Gnosis treasury, whose address is 0x458cD345B4C05e8DF39d0A07220feb4Ec19F5e6f. | ||
Assert which balance is greater. | ||
""" | ||
agent.bootstrap = [ | ||
'Reasoning("I need to reason step-by-step")', | ||
] | ||
agent.run(iterations=5) | ||
|
||
|
||
if __name__ == "__main__": | ||
typer.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import pathlib | ||
|
||
from modal import Image, App, Period | ||
from modal.secret import Secret | ||
|
||
from general_agent.main import main | ||
|
||
# Loading env and poetry files | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
path_to_pyproject_toml = pathlib.Path(dir_path).parent.joinpath("pyproject.toml") | ||
path_to_env = pathlib.Path(dir_path).parent.joinpath(".env") | ||
|
||
image = Image.debian_slim().poetry_install_from_file( | ||
poetry_pyproject_toml=path_to_pyproject_toml.as_posix() | ||
) | ||
|
||
app = App(image=image) | ||
|
||
|
||
@app.function( | ||
schedule=Period(minutes=5), secrets=[Secret.from_dotenv(path_to_env.as_posix())] | ||
) | ||
def execute_remote() -> None: | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
|
||
from eth_account import Account | ||
from eth_typing import ChecksumAddress | ||
from web3.types import ( # noqa: F401 # Import for the sake of easy importing with others from here. | ||
Wei, | ||
) | ||
from microchain import Function | ||
from web3 import Web3 | ||
|
||
|
||
class GetBalance(Function): | ||
def __init__(self) -> None: | ||
# We define a web3 connector here using either the ENV or the default RPC. | ||
GNOSIS_RPC_URL = os.getenv( | ||
"GNOSIS_RPC_URL", "https://gnosis-rpc.publicnode.com" | ||
) | ||
self.w3 = Web3(Web3.HTTPProvider(GNOSIS_RPC_URL)) | ||
super().__init__() | ||
|
||
@property | ||
def description(self) -> str: | ||
return "Use this function to fetch the balance of a given account in xDAI" | ||
|
||
@property | ||
def example_args(self) -> list[ChecksumAddress]: | ||
return [Web3.to_checksum_address("0x464A10A122Cb5B47e9B27B9c5286BC27487a6ACd")] | ||
|
||
def __call__(self, address: ChecksumAddress) -> Wei: | ||
return self.w3.eth.get_balance(account=address) | ||
|
||
|
||
class GetOwnWallet(Function): | ||
@property | ||
def description(self) -> str: | ||
return "Use this function to fetch your wallet address" | ||
|
||
@property | ||
def example_args(self) -> list[str]: | ||
return [] | ||
|
||
def __call__(self) -> str: | ||
private_key = os.getenv("BET_FROM_PRIVATE_KEY") | ||
if not private_key: | ||
raise EnvironmentError("BET_FROM_PRIVATE_KEY missing in the environment.") | ||
acc = Account.from_key(private_key) | ||
return str(acc.address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.