Skip to content

Commit

Permalink
0.16.4: Added optional postgres remote storage backend (#1)
Browse files Browse the repository at this point in the history
* Added initial API mode with PG backend

* Added PG connection and scaling parameters

* Added PG connection and scaling parameters

* Added PG connection and scaling parameters

* 0.16.0: Minimal fixes

* 0.16.0: Minimal fixes

* 0.16.0: Minimal fixes

* 0.16.0: Minimal fixes

* 0.16.0: Minimal fixes

* 0.16.0: Minimal fixes

* 0.16.0: Minimal fixes

* 0.16.0: Minimal fixes

* 0.16.1: Minimal fixes

* 0.16.2: Minimal fixes

* 0.16.2: Minimal fixes

* 0.16.2: Minimal fixes

* 0.16.3: Tests validated

* 0.16.4: Loader on settings page and updated title

* Updated documentation

* 0.16.4: Loader on settings page and updated title
  • Loading branch information
flavienbwk authored Sep 13, 2024
1 parent 4b5e665 commit 3b7ee76
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 450 deletions.
9 changes: 7 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ INTERFACE_PASSWORD=repochat # leave empty for no password on interface
OPENAI_API_KEY=XXX
MODEL_TYPE_INFERENCE=gpt-4o-mini
MODEL_TYPE_EMBEDDING=text-embedding-3-small
CLEAR_DB_AT_RESTART=false
MODE=directory # or "api" for stateless ingestion

# State management
MODE=directory # "directory" or "api" for stateless ingestion
CLEAR_DB_AT_RESTART=false # clears the database at startup on "directory" mode
## For persistent cross-container state, use PostgreSQL instead of ChromaDB ;
## Leave empty for using ChromaDB (file-based DB).
## PG_CONNECTION_STRING=postgresql://postgres:[email protected]:5432/postgres
32 changes: 0 additions & 32 deletions .github/workflows/deploy.yml

This file was deleted.

102 changes: 102 additions & 0 deletions .github/workflows/push-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: "Build, push and deploy Repochat for this repo"

on:
push:
branches:
- main
- beta/*
- f/pg-backend

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@v3

- name: Get version from package.json
id: package-version
uses: martinbeentjes/[email protected]

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.package-version.outputs.current-version}}
type=raw,value={{date 'YYYYMMDDHHmmss'}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.package-version.outputs.current-version}}
cache-to: type=inline

- name: Extract metadata (tags, labels) for Docker (latest)
id: meta_latest
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
- name: Build and push Docker image (latest)
uses: docker/build-push-action@v6
if: ${{ github.ref == 'refs/heads/main' }}
with:
context: .
push: true
tags: ${{ steps.meta_latest.outputs.tags }}
labels: ${{ steps.meta_latest.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.package-version.outputs.current-version}}
cache-to: type=inline

deploy:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- uses: actions/checkout@v2
- uses: ./
name: 'Deploy Repochat'
id: deploy_repochat
with:
dirs_to_scan: "README.md,package.json,Dockerfile,api,action,app"
interface_password: ${{ secrets.INTERFACE_PASSWORD }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
openai_model_type_inference: "gpt-4o-mini"
openai_model_type_embedding : "text-embedding-3-small"
provider_name: 'scaleway'
provider_key_id: ${{ secrets.PROVIDER_KEY_ID }}
provider_key_secret: ${{ secrets.PROVIDER_KEY_SECRET }}
provider_project_id: ${{ secrets.PROVIDER_PROJECT_ID }}
provider_default_region: 'fr-par'
provider_default_zone: 'fr-par-2'
pg_connection_string: ${{ secrets.PG_CONNECTION_STRING }}
min_scale: 0
max_scale: 2

- name: Get repochat domain
run: echo "DOMAIN=${{ steps.deploy_repochat.outputs.domain }}" >> $GITHUB_OUTPUT
id: repochat_domain
53 changes: 0 additions & 53 deletions .github/workflows/push-to-registry.yml

This file was deleted.

63 changes: 26 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Features:

- :sparkles: A nice web UI
- :octocat: Available as a GitHub Action
- :floppy_disk: Stateful ingestion mode ([directory mode](./dir.docker-compose.yml#L6))
- :arrows_counterclockwise: Sateless ingestion via API ([api mode](./api.docker-compose.yml#L6))
- :arrows_counterclockwise: Sateless ingestion via API
- :floppy_disk: Optional state persisted to PostgreSQL or ChromaDB
- :closed_lock_with_key: Optional password on web UI

![RepoChat interface example](./media/screenshot.png)
Expand Down Expand Up @@ -63,7 +63,26 @@ jobs:
id: repochat_domain
```
Get a practical implementation example with [`.github/workflows/deploy.yml`](./.github/workflows/deploy.yml).
| Name | Required | Secret | Description |
| --------------------------- | -------- | ------ | -------------------------------------------------------------------------------------------------------- |
| dirs_to_scan | Yes | No | Comma-separated glob directories to analyze |
| openai_api_key | Yes | Yes | OpenAI API key for authentication |
| openai_model_type_inference | Yes | No | OpenAI model type for inference (e.g., "gpt-4o-mini") |
| openai_model_type_embedding | Yes | No | OpenAI model type for embedding (e.g., "text-embedding-3-small") |
| provider_name | Yes | No | Name of the cloud provider (e.g., 'scaleway') |
| provider_key_id | Yes | Yes | Cloud provider API key ID |
| provider_key_secret | Yes | Yes | Cloud provider API key secret |
| provider_project_id | Yes | Yes | Cloud provider project ID |
| provider_default_region | Yes | No | Default region for the cloud provider (e.g., 'fr-par') |
| provider_default_zone | Yes | No | Default zone for the cloud provider (e.g., 'fr-par-2') |
| interface_password | No | Yes | Optional password for the interface |
| pg_connection_string | No | Yes | Enables storage to external PG DB (format: 'postgresql://username:password@hostname:port/database_name') |
| cpu_limit | No | No | Default to 1000 (1 vCPU). Capabilities depend on the Cloud provider. |
| memory_limit | No | No | Default to 1024. Capabilities depend on the Cloud provider. |
| min_scale | No | No | Default to 1. Must be left to 1 if not using the PG connection. |
| max_scale | No | No | Default to 1. Must be left to 1 if not using the PG connection. |
Get a practical implementation example with [`.github/workflows/push-deploy.yml`](./.github/workflows/push-deploy.yml#L76).

You can restrict your OpenAI API key permissions to:

Expand All @@ -89,30 +108,7 @@ You can restrict your OpenAI API key permissions to:

## Other deployments

### Deploy for local directory

<details>
<summary>👉 Deploy locally for directory serving...</summary>

1. Copy repo/documents/files to be ingested under `./api/example/`

2. Copy and update env variables

```bash
cp .env.example .env
```

3. Run the Docker container

```bash
docker compose -f dir.docker-compose.yml up -d
```

4. Access the app at `http://localhost:3001`

</details>

### Deploy as stateless API
### Deploy with Docker

<details>
<summary>👉 Deploy locally as a stateless API...</summary>
Expand All @@ -126,7 +122,7 @@ You can restrict your OpenAI API key permissions to:
2. Run the Docker container

```bash
docker compose -f api.docker-compose.yml up -d
docker compose up --build -d
```

3. Inject data taking example on the [Python](./scripts/ingest-docs-api.py) or [JS](./scripts/ingest-docs-api.js) scripts
Expand Down Expand Up @@ -158,6 +154,8 @@ You can restrict your OpenAI API key permissions to:
make dev
```

4. Access the app at `http://127.0.0.1:3000`

</details>

## Release Action
Expand All @@ -175,15 +173,6 @@ You can restrict your OpenAI API key permissions to:

This will create a release based on `package.json` and push the `:latest` Docker image.

## Features

- [x] Directory data chat
- [x] API data chat
- [x] GitHub Actions release
- [x] Secure ingestion endpoint (/api/ingest)
- [x] Secure RepoChat with optional password
- [ ] Maintain state over S3 (would allow containers autoscaling)

## Why not use Vercel ?

Vercel is very limited when it comes to deploying everything but JS. First, ChromaDB (and any sqlite-based library) [is not supported in Vercel](https://vercel.community/t/is-vercel-incompatible-with-chromadb-sqlite/787). Then, this project uses a FastAPI Python API that requires more storage than [Vercel's 250MB bundle limit](https://vercel.com/docs/functions/runtimes#bundle-size-limits).
20 changes: 20 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ inputs:
provider_project_id:
description: 'Cloud provider project ID (Scaleway specific)'
required: false
pg_connection_string:
description: 'PostgreSQL connection string'
required: false
default: ''
cpu_limit:
description: 'CPU limit for the container'
required: false
default: '1000'
memory_limit:
description: 'Memory limit for the container'
required: false
default: '1024'
min_scale:
description: 'Minimum scale for the container'
required: false
default: '1'
max_scale:
description: 'Maximum scale for the container'
required: false
default: '1'
runs:
using: 'node16'
main: 'lib/index.js'
Expand Down
Loading

0 comments on commit 3b7ee76

Please sign in to comment.