-
Notifications
You must be signed in to change notification settings - Fork 7
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
Coinflip agent deployment #64
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e089da2
Coinflip agent deployment
kongzii 0a301c5
update repo
kongzii 520a34a
fix
kongzii 430dc7f
Merge branch 'main' into peter/deployment
kongzii 202aade
fix docker
kongzii da074ee
Merge branch 'main' into peter/deployment
kongzii fdfd533
Update build.sh
kongzii 4b4cdd1
lint
kongzii 37c117e
fixes
kongzii abe8ecb
update docker
kongzii a6ef95f
fix
kongzii 45973f2
rename
kongzii fc07332
lint
kongzii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Docker specific ignores: | ||
.git | ||
|
||
# .gitignore ignores: | ||
.env | ||
.agents_workspace | ||
.cache | ||
__pycache__ | ||
*.egg-info | ||
logs | ||
.mypy_cache | ||
.pytest_cache |
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,5 +1,3 @@ | ||
requirements.txt | ||
.venv | ||
.env | ||
.agents_workspace | ||
.cache | ||
|
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,31 @@ | ||
# Install Poetry and create venv in the builder step, | ||
# then copy the venv to the runtime image, so that the runtime image is as small as possible. | ||
FROM --platform=linux/amd64 python:3.10.14-slim-bookworm AS builder | ||
|
||
RUN pip install poetry==1.8.2 | ||
|
||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
||
WORKDIR /app | ||
|
||
COPY pyproject.toml poetry.lock ./ | ||
|
||
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root --only main | ||
|
||
FROM --platform=linux/amd64 python:3.10.14-slim-bookworm AS runtime | ||
|
||
ENV VIRTUAL_ENV=/app/.venv \ | ||
PATH="/app/.venv/bin:$PATH" | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} | ||
|
||
COPY prediction_market_agent ./prediction_market_agent | ||
|
||
ENV PYTHONPATH=/app | ||
|
||
CMD ["bash", "-c", "python prediction_market_agent/run_agent.py ${runnable_agent_name} ${market_type}"] |
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,3 @@ | ||
#!/bin/bash | ||
# TODO: This should be automated as part of CI/CD pipeline, but for now, execute it locally on the main branch. | ||
kongzii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
docker build . -t ghcr.io/gnosis/pma:latest && docker push ghcr.io/gnosis/pma:latest |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
import random | ||
import typing as t | ||
|
||
from prediction_market_agent_tooling.deploy.agent import DeployableAgent | ||
from prediction_market_agent_tooling.markets.agent_market import AgentMarket | ||
|
||
|
||
class DeployableCoinFlipAgent(DeployableAgent): | ||
def pick_markets(self, markets: t.Sequence[AgentMarket]) -> t.Sequence[AgentMarket]: | ||
return random.sample(markets, 1) | ||
|
||
evangriffiths marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def answer_binary_market(self, market: AgentMarket) -> bool | None: | ||
return random.choice([True, False]) | ||
evangriffiths marked this conversation as resolved.
Show resolved
Hide resolved
|
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,33 @@ | ||
""" | ||
Entrypoint for running the agent in GKE. | ||
If the agent adheres to PMAT standard (subclasses DeployableAgent), | ||
simply add the agent to the `RunnableAgent` enum and then `RUNNABLE_AGENTS` dict. | ||
|
||
Can also be executed locally, simply by running `python prediction_market_agent/run_agent.py <agent> <market_type>`. | ||
""" | ||
|
||
from enum import Enum | ||
|
||
import typer | ||
from prediction_market_agent_tooling.markets.markets import MarketType | ||
|
||
from prediction_market_agent.agents.coinflip_agent.deploy import ( | ||
DeployableCoinFlipAgent, | ||
) | ||
|
||
|
||
class RunnableAgent(str, Enum): | ||
coinflip = "coinflip" | ||
|
||
|
||
RUNNABLE_AGENTS = { | ||
RunnableAgent.coinflip: DeployableCoinFlipAgent, | ||
} | ||
|
||
|
||
def main(agent: RunnableAgent, market_type: MarketType) -> None: | ||
RUNNABLE_AGENTS[agent]().run(market_type) | ||
|
||
|
||
if __name__ == "__main__": | ||
typer.run(main) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a
CMD
/ENTRYPOINT
here or is that done in the Kubernetes config? I guess if we're building this in CI then we want to test running it too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, command is easily changeable and I put it into Terraform https://github.com/gnosis/gnosisai-infrastructure/pull/3/files#diff-fa25fb4ef6fa67ec2382f07d26b9039099ce7a314a7e98517370a8439a0d0365R42
But if I put it here, it's easier to change it without the need for updating Terraform 🤔 I'll give it a try!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also support @evangriffiths suggestion, the Entrypoint seems to me something that should be part of the image definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep works fine, updated 🙏