-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from gnosis/evan/deploy-agent
Add agent deployment tooling
- Loading branch information
Showing
13 changed files
with
1,762 additions
and
189 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
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,24 @@ | ||
from flask.wrappers import Request | ||
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: Request) -> str: | ||
DeployableCoinFlipAgent().run(market_type=MarketType.MANIFOLD, api_keys=get_keys()) | ||
return "Success" |
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,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) |
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.