diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..83d34f9 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.12 + +WORKDIR /app + +RUN pip install poetry + +COPY ./pyproject.toml ./poetry.lock ./ + +RUN poetry install + +COPY . . + +CMD ["poetry", "run", "fastapi", "run", "src/main.py", "--host", "0.0.0.0"] \ No newline at end of file diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml new file mode 100644 index 0000000..39fb10f --- /dev/null +++ b/backend/docker-compose.yml @@ -0,0 +1,10 @@ +services: + agents-api: + build: + dockerfile: ./Dockerfile + container_name: libertai-agents + restart: unless-stopped + ports: + - "8082:8000" + env_file: + - .env diff --git a/backend/src/main.py b/backend/src/main.py index 0aca1e5..606db5e 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -222,5 +222,21 @@ async def update( @app.delete("/agent", description="Remove an agent on subscription end") async def delete(body: DeleteAgentBody): - # TODO - pass + agents = await fetch_agents([body.subscription_id]) + + if len(agents) != 1: + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, + detail=f"Agent for subscription ID {body.subscription_id} not found.", + ) + agent = agents[0] + + aleph_account = ETHAccount(config.ALEPH_SENDER_SK) + async with AuthenticatedAlephHttpClient( + account=aleph_account, api_server=config.ALEPH_API_URL + ) as client: + await client.forget( + address=config.ALEPH_OWNER, + hashes=[agent.vm_hash], + reason="LibertAI Agent subscription ended", + )