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

Add agent deployment tooling #24

Merged
merged 15 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ pytest tests

Note: these make actual API calls!

## Deploying

To deploy an agent to google cloud, see the example in `examples/cloud_deployment`.

Requires the gcloud cli (see [here](https://cloud.google.com/sdk/docs/install)), and auth to have been completed (i.e. `gcloud auth login`).

## Frameworks implemented

| Framework | Notes |
Expand Down
23 changes: 23 additions & 0 deletions examples/cloud_deployment/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import functions_framework
import random

from prediction_market_agent.data_models.market_data_models import AgentMarket
from prediction_market_agent.deploy.deploy import DeployableAgent
from prediction_market_agent.markets.all_markets import MarketType
from prediction_market_agent.utils import get_keys


class DeployableCoinFlipAgent(DeployableAgent):
def pick_markets(self, markets: list[AgentMarket]) -> list[AgentMarket]:
if len(markets) > 1:
return random.sample(markets, 1)
return markets

def answer_binary_market(self, market: AgentMarket) -> bool:
return random.choice([True, False])


@functions_framework.http
def main(request):
DeployableCoinFlipAgent().run(market_type=MarketType.MANIFOLD, api_keys=get_keys())
return "Success"
37 changes: 37 additions & 0 deletions examples/cloud_deployment/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

from prediction_market_agent.deploy.deploy import (
deploy_to_gcp,
remove_deployed_gcp_function,
run_deployed_gcp_function,
schedule_deployed_gcp_function,
)
from prediction_market_agent.deploy.utils import gcp_function_is_active
from prediction_market_agent.markets.all_markets import MarketType
from prediction_market_agent.utils import get_keys

if __name__ == "__main__":
current_dir = os.path.dirname(os.path.realpath(__file__))
fname = deploy_to_gcp(
requirements_file=f"{current_dir}/../../pyproject.toml",
extra_deps=[
"git+https://github.com/gnosis/prediction-market-agent.git@evan/deploy-agent"
],
function_file=f"{current_dir}/agent.py",
market_type=MarketType.MANIFOLD,
api_keys={"MANIFOLD_API_KEY": get_keys().manifold},
memory=512,
)

# Check that the function is deployed
assert gcp_function_is_active(fname)

# Run the function
response = run_deployed_gcp_function(fname)
assert response.ok

# Schedule the function
schedule_deployed_gcp_function(fname, cron_schedule="* * * * *")

# Delete the function
remove_deployed_gcp_function(fname)
evangriffiths marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading