Skip to content

Commit

Permalink
fix: change from ghcr to docker; resolved some issue
Browse files Browse the repository at this point in the history
  • Loading branch information
teilomillet committed Dec 22, 2024
1 parent d13ef65 commit e4829a3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .env.example
# ANTHROPIC_API_KEY=
# OPENAI_API_KEY=
18 changes: 5 additions & 13 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,31 @@ on:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Important for version tags
fetch-depth: 0 # Ensures all tags are fetched for versioning

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: teilomillet/hapax
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
Expand Down
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ RUN apk add --no-cache ca-certificates tzdata curl
# Set working directory
WORKDIR /app

# Copy binary from builder
# Copy binary and configuration files
COPY --from=builder /app/hapax .

# Copy default config file
COPY config.example.yaml ./config.yaml
COPY docker-compose.yml ./docker-compose.yml
COPY prometheus.yml ./prometheus.yml

# Use non-root user
USER hapax

# Expose ports
EXPOSE 8080

# Set healthcheck that waits for initial startup
# Set healthcheck
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1

# Run the application
ENTRYPOINT ["./hapax"]
CMD ["--config", "config.yaml"]

CMD ["--config", "config.yaml"]
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,21 @@ routes:
## Getting Started
```bash
# Pull Hapax
docker pull ghcr.io/teilomillet/hapax:latest
# Pull and start Hapax with default configuration
docker run -p 8080:8080 -e ANTHROPIC_API_KEY=your_api_key teilomillet/hapax:latest

# Generate default configuration
docker run --rm -v $(pwd):/output \
ghcr.io/teilomillet/hapax:latest \
cp /app/config.example.yaml /output/config.yaml
# Or, to use a custom configuration with environment variables:
# 1. Extract the default configuration
docker run --rm teilomillet/hapax:latest cat /app/config.yaml > config.yaml

# Launch Hapax
# 2. Create a .env file to store your environment variables
echo "ANTHROPIC_API_KEY=your_api_key" > .env

# 3. Start Hapax with your configuration and environment variables
docker run -p 8080:8080 \
-v $(pwd)/config.yaml:/app/config.yaml \
ghcr.io/teilomillet/hapax:latest
--env-file .env \
teilomillet/hapax:latest
```

## What's Next
Expand Down
37 changes: 31 additions & 6 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ server:
max_header_bytes: 1048576
shutdown_timeout: 5s

llm:
provider: anthropic
model: claude-3.5-haiku-latest
api_key: ${ANTHROPIC_API_KEY}
max_context_tokens: 100000
retry:
max_retries: 3
initial_delay: 100ms
max_delay: 2s
multiplier: 2.0
retryable_errors: ["rate_limit", "timeout", "server_error"]

providers:
openai:
type: openai
model: gpt-4o-mini
api_key: ${OPENAI_API_KEY}
anthropic:
type: anthropic
model: claude-3.5-haiku-latest
Expand All @@ -19,9 +27,7 @@ providers:
model: llama3
api_key: ""

# Order of provider preference for failover
provider_preference:
- openai
- anthropic
- ollama

Expand All @@ -33,3 +39,22 @@ metrics:
enabled: true
prometheus:
enabled: true

routes:
- path: /v1/completions
handler: completion
version: v1
methods: [POST]
- path: /health
handler: health
version: v1
methods: [GET]

processing:
request_templates:
default: "{{.Input}}"
chat: "{{range .Messages}}{{.Role}}: {{.Content}}\n{{end}}"
response_formatting:
clean_json: true
trim_whitespace: true
max_length: 1048576
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
hapax:
build: .
container_name: hapax
ports:
- "8080:8080"
volumes:
Expand Down

0 comments on commit e4829a3

Please sign in to comment.