Skip to content

Commit f1bd378

Browse files
authored
Version 0.2.0 with S3, docker, bells and whistles (#1)
This pull request introduces several updates to enhance the Allocator Bot's functionality, improve its deployment process, and streamline its codebase. Key changes include the addition of Docker support, updates to environment configuration, new GitHub Actions workflows, and significant refactoring of the bot's agent logic. ### Deployment and Configuration Enhancements: * Added a `Dockerfile` for multi-stage builds, enabling easy deployment of the Allocator Bot as a Docker container. The runtime stage uses a non-root user for security, and the default port is exposed as `4299`. * Updated `.env.example` to include new configuration options such as S3 storage settings and renamed `API_KEYS_FILE_PATH` to `APP_API_KEY` for clarity. * Added `.dockerignore` to exclude unnecessary files from Docker builds, improving build performance. ### GitHub Actions Workflows: * Introduced a `docker-publish.yml` workflow to build and publish Docker images to GitHub Container Registry on pushes to the `main` branch. * Added a `lint_and_test.yml` workflow to automate linting and testing on pushes and pull requests to the `main` branch. ### Codebase Refactoring: * Refactored `allocator_bot/agent.py` to replace OpenAI models with OpenRouter models, add retry logic, and improve the structure of LLM interactions. Introduced new helper methods such as `make_llm` and updated the `execution_loop` to yield reasoning steps and tables for better SSE responses. [[1]](diffhunk://#diff-cd2fd1f2d0dc7b64130bc7d15a221de93780ea671fd1022f4a7298d23d6d3151L1-R141) [[2]](diffhunk://#diff-cd2fd1f2d0dc7b64130bc7d15a221de93780ea671fd1022f4a7298d23d6d3151L153-R181) * Added logging to `allocator_bot/__main__.py` and implemented a `get_app` function that loads environment variables and initializes the FastAPI app. ### Documentation Updates: * Enhanced `README.md` with Docker setup instructions, environment variable descriptions, and updated usage details for integration with OpenBB Workspace. [[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R3-R14) [[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L24-R98) [[3]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L65-R116) ### Miscellaneous: * Added `.markdownlint.json` to configure markdown linting rules, disabling `MD033` and `MD013`. * Updated `.cursorrules`, `CLAUDE.md`, and `GEMINI.md` to include references to `llms.md`.
1 parent 245f3e3 commit f1bd378

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5135
-2843
lines changed

.cursorrules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
llms.md

.dockerignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
*venv*
2+
.vscode
3+
**/*.env
4+
**/*.pyc
5+
**/data/**/*
6+
*.log
7+
.git
8+
.gitignore
9+
.github
10+
__pycache__
11+
.pytest_cache
12+
*.pyc
13+
*.pyo
14+
*.pyd
15+
.coverage
16+
htmlcov/
17+
.tox/
18+
.mypy_cache/
19+
.DS_Store
20+
Thumbs.db
21+
22+
LICENSE
23+
24+
tests/
25+
.codex/
26+
.claude/
27+
.gemini/
28+
.aider/
29+
llms.md
30+
CLAUDE.md
31+
GEMINI.md
32+
Dockerfile
33+
.dockerignore

.env.example

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# Application configuration
22
HOST_URL=http://localhost:4322 # The host URL and port number where the app is running.
3-
API_KEYS_FILE_PATH=api_keys.txt # The path to the file containing API keys to access the bot.
3+
APP_API_KEY=my_api_key # The API key to access the bot.
44
DATA_FOLDER_PATH=data # The path to the folder that will store the allocation data.
55

66
# AI configuration
7-
OPENAI_API_KEY=<your-openai-key>
8-
MAGENTIC_OPENAI_MAX_TOKENS=4096
9-
MAGENTIC_OPENAI_TEMPERATURE=0.42
10-
MAGENTIC_BACKEND=openai
11-
MAGENTIC_OPENAI_MODEL=gpt-4o
7+
OPENROUTER_API_KEY=
8+
9+
# S3 configuration
10+
S3_ENABLED=false # Set to true to enable S3 storage
11+
S3_ENDPOINT= # S3 endpoint URL
12+
S3_ACCESS_KEY= # S3 access key
13+
S3_SECRET_KEY= # S3 secret key
14+
S3_BUCKET_NAME= # S3 bucket name
15+
ALLOCATION_DATA_FILE=allocations.json # File name to store allocations
16+
TASK_DATA_FILE=tasks.json # File name to store tasks
17+
18+
# Data retrieval configuration
19+
FMP_API_KEY=
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build-and-push:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to Container Registry
27+
if: github.event_name != 'pull_request'
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Extract metadata
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=ref,event=branch
41+
type=ref,event=pr
42+
type=sha,prefix={{branch}}-
43+
type=raw,value=latest,enable={{is_default_branch}}
44+
45+
- name: Build and push Docker image
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: .
49+
platforms: linux/amd64,linux/arm64
50+
push: ${{ github.event_name != 'pull_request' }}
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Run Lints and Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v4
19+
with:
20+
version: "latest"
21+
22+
- name: Set up Python
23+
run: uv python install
24+
25+
- name: Install dependencies
26+
run: uv sync --extra dev
27+
28+
- name: Run linting
29+
run: uv run ruff check .
30+
31+
- name: Check code formatting
32+
run: uv run black --check .
33+
34+
- name: Run tests
35+
run: uv run pytest

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
venv
1+
*venv*
22
.vscode
33
**/*.env
44
**/*.pyc
55
**/data/**/*
66
*.log
7-
*api_keys*.*
7+
.coverage
8+
.claude

.markdownlint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"MD033": false,
3+
"MD013": false
4+
}

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
llms.md

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Multi-stage Dockerfile for allocator-bot
2+
# Build stage
3+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
4+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
5+
ENV UV_PYTHON_DOWNLOADS=0
6+
7+
RUN apt-get update && apt-get install -y build-essential git
8+
9+
WORKDIR /app
10+
COPY . /app
11+
RUN uv sync --locked --no-dev
12+
13+
# Runtime stage
14+
FROM python:3.12-slim-bookworm
15+
WORKDIR /app
16+
17+
# Create non-root user
18+
RUN groupadd --gid 1000 app && useradd --uid 1000 --gid app --shell /bin/bash --create-home app
19+
20+
# Copy application from builder
21+
COPY --from=builder --chown=app:app /app /app
22+
23+
# Switch to non-root user
24+
USER app
25+
26+
# Place executables in PATH
27+
ENV PATH="/app/.venv/bin:$PATH"
28+
29+
# Expose port
30+
EXPOSE 4299
31+
32+
# Run the application
33+
CMD ["openbb-api", "--app", "allocator_bot.__main__:get_app", "--factory", "--host", "0.0.0.0", "--port", "4299"]

GEMINI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
llms.md

0 commit comments

Comments
 (0)