Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 1543fb6

Browse files
authored
Merge branch 'main' into codegate_system_prompt
2 parents 1ea2401 + b8a6e80 commit 1543fb6

38 files changed

Lines changed: 2549 additions & 321 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
- name: Run linting
4949
run: make lint
5050

51+
- name: Run formatting
52+
run: make format
53+
5154
- name: Run tests
5255
run: make test
5356

Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Builder stage: Install dependencies and build the application
2+
FROM python:3.12-slim AS builder
3+
4+
# Install system dependencies
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
gcc \
7+
g++ \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Set environment variable to ensure Python modules are installed in the correct location
11+
ENV PYTHONPATH=/app
12+
13+
# Install Poetry
14+
RUN pip install poetry==1.8.4
15+
16+
# Create a non-root user and switch to it
17+
RUN adduser --system --no-create-home codegate --uid 1000
18+
19+
# Set the working directory
20+
WORKDIR /app
21+
22+
# Copy only the files needed for installing dependencies
23+
COPY pyproject.toml poetry.lock* /app/
24+
25+
# Configure Poetry and install dependencies
26+
RUN poetry config virtualenvs.create false && \
27+
poetry install --no-dev
28+
29+
# Copy the rest of the application
30+
COPY . /app
31+
32+
# Runtime stage: Create the final lightweight image
33+
FROM python:3.12-slim AS runtime
34+
35+
# Install runtime system dependencies
36+
RUN apt-get update && apt-get install -y --no-install-recommends \
37+
libgomp1 \
38+
&& rm -rf /var/lib/apt/lists/*
39+
40+
# Create a non-root user and switch to it
41+
RUN adduser --system --no-create-home codegate --uid 1000
42+
USER codegate
43+
44+
# Copy necessary artifacts from the builder stage
45+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
46+
COPY --from=builder /app /app
47+
48+
# Set the working directory
49+
WORKDIR /app
50+
51+
# Set the PYTHONPATH environment variable
52+
ENV PYTHONPATH=/app/src
53+
54+
# Allow to expose weaviate_data volume
55+
VOLUME ["/app/weaviate_data"]
56+
57+
# Set the container's default entrypoint
58+
EXPOSE 8989
59+
#ENTRYPOINT ["python", "-m", "src.codegate.cli", "serve", "--port", "8989", "--host", "0.0.0.0"]
60+
CMD ["python", "-m", "src.codegate.cli", "serve", "--port", "8989", "--host", "0.0.0.0"]

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.PHONY: clean install format lint test security build all
2+
CONTAINER_BUILD?=docker buildx build
3+
VER?=0.1.0
24

35
clean:
46
rm -rf build/
@@ -27,4 +29,8 @@ security:
2729
build: clean test
2830
poetry build
2931

32+
image-build:
33+
$(CONTAINER_BUILD) -f Dockerfile -t codegate . -t ghcr.io/stacklok/codegate:$(VER) --load
34+
35+
3036
all: clean install format lint test security build

README.md

Lines changed: 86 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,146 @@
22

33
[![CI](https://github.com/stacklok/codegate/actions/workflows/ci.yml/badge.svg)](https://github.com/stacklok/codegate/actions/workflows/ci.yml)
44

5-
A configurable Generative AI gateway, protecting developers from the dangers of AI.
5+
Codegate is a local gateway that makes AI coding assistants safer. Acting as a security checkpoint, Codegate ensures AI-generated recommendations adhere to best practices, while safeguarding your code's integrity, and protecting your individual privacy. With Codegate, you can confidently leverage AI in your development workflow without compromising security or control.
66

7-
## Features
7+
## ✨ Why Codegate?
88

9-
- Secrets exflitration prevention
10-
- Secure Coding recommendations
11-
- Preventing AI from recommending deprecated and / or malicious libraries
9+
In today's world where AI coding assistants are becoming ubiquitous, security can't be an afterthought. Codegate sits between you and AI, actively protecting your development process by:
1210

11+
- 🔒 Preventing accidental exposure of secrets and sensitive data
12+
- 🛡️ Ensuring AI suggestions follow secure coding practices
13+
- ⚠️ Blocking recommendations of known malicious or deprecated libraries
14+
- 🔍 Providing real-time security analysis of AI suggestions
1315

14-
### Installation
16+
## 🌟 Features
1517

16-
#### Requirements
18+
### Supported AI Providers
19+
Codegate works seamlessly with leading AI providers:
20+
- 🤖 Anthropic (Claude)
21+
- 🧠 OpenAI
22+
- ⚡ vLLM
23+
- 💻 Local LLMs (run AI completely offline!)
24+
- 🔮 Many more on the way!
1725

18-
- [Docker](https://docs.docker.com/get-docker/)
19-
- [Docker Compose](https://docs.docker.com/compose/install/)
20-
- [jq](https://stedolan.github.io/jq/download/)
21-
- [vscode](https://code.visualstudio.com/download)
26+
### Run AI Your Way
27+
- 🌐 Cloud Providers: Use leading AI services like OpenAI and Anthropic
28+
- 🏠 Local LLMs: Keep everything offline with local model support
29+
- 🔄 Hybrid Mode: Mix and match cloud and local providers as needed
2230

23-
#### Steps
31+
### AI Coding Assistants
32+
We're starting with Continue VSCode extension support, with many more AI coding assistants coming soon!
2433

25-
Download the installation script docker-compose.yml
34+
### Privacy First
35+
Unlike E.T., your code never phones home! 🛸 Codegate is designed with privacy at its core:
36+
- 🏠 Everything stays on your machine
37+
- 🚫 No external data collection
38+
- 🔐 No calling home or telemetry
39+
- 💪 Complete control over your data
2640

27-
Run the installation script
41+
## 🚀 Quick Start
42+
43+
### Prerequisites
44+
45+
Make sure you have these tools installed:
46+
47+
- 🐳 [Docker](https://docs.docker.com/get-docker/)
48+
- 🔧 [Docker Compose](https://docs.docker.com/compose/install/)
49+
- 🛠️ [jq](https://stedolan.github.io/jq/download/)
50+
- 💻 [VSCode](https://code.visualstudio.com/download)
51+
52+
### One-Command Setup
2853

2954
```bash
3055
chmod +x install.sh && ./install.sh
3156
```
3257

33-
The script will download the Continue VSCode extension, create
34-
a configuration file. The script will also create a docker-compose.yml file and start the services.
58+
This script will:
59+
1. Install the Continue VSCode extension
60+
2. Set up your configuration
61+
3. Create and start necessary Docker services
3562

36-
### Usage
63+
## 🎯 Usage
3764

38-
Tap the Continue button in the VSCode editor to start the service
39-
to bring up a chat window. The chat window will be displayed in the
40-
VSCode editor.
65+
### VSCode Integration with Continue
4166

42-
![Continue Chat](./static/image.png)
67+
Simply tap the Continue button in your VSCode editor to start chatting with your AI assistant - now protected by Codegate!
4368

44-
## Usage
69+
![Continue Chat Interface](./static/image.png)
4570

46-
### Basic Usage (Manual)
47-
48-
Start the server with default settings:
71+
### Manual Configuration
4972

73+
#### Basic Server Start
5074
```bash
5175
codegate serve
5276
```
5377

54-
### Custom Configuration
55-
56-
Start with custom settings:
57-
78+
#### Custom Settings
5879
```bash
5980
codegate serve --port 8989 --host localhost --log-level DEBUG
6081
```
6182

62-
### Configuration File
63-
64-
Use a YAML configuration file:
65-
66-
```bash
67-
codegate serve --config my_config.yaml
68-
```
69-
70-
Example `config.yaml`:
71-
83+
#### Using Config File
84+
Create a `config.yaml`:
7285
```yaml
7386
port: 8989
7487
host: "localhost"
7588
log_level: "DEBUG"
7689
```
7790
78-
### Environment Variables
79-
80-
Configure using environment variables:
91+
Then run:
92+
```bash
93+
codegate serve --config config.yaml
94+
```
8195

96+
#### Environment Variables
8297
```bash
8398
export CODEGATE_APP_PORT=8989
8499
export CODEGATE_APP_HOST=localhost
85100
export CODEGATE_APP_LOG_LEVEL=DEBUG
86101
codegate serve
87102
```
88103

89-
## Development
90-
91-
### Setup
104+
## 🛠️ Development
92105

106+
### Local Setup
93107
```bash
94-
# Clone the repository
108+
# Get the code
95109
git clone https://github.com/stacklok/codegate.git
96110
cd codegate
97111

98-
# Create and activate a virtual environment
112+
# Set up virtual environment
99113
python -m venv venv
100114
source venv/bin/activate # On Windows: venv\Scripts\activate
101115

102-
# Install development dependencies
116+
# Install dev dependencies
103117
pip install -e ".[dev]"
104118
```
105119

106120
### Testing
107-
108121
```bash
109122
pytest
110123
```
124+
125+
## 🐳 Docker Deployment
126+
127+
### Build the Image
128+
```bash
129+
make image-build
130+
```
131+
132+
### Run the Container
133+
```bash
134+
# Basic usage
135+
docker run -p 8989:8989 codegate:latest
136+
137+
# With persistent data
138+
docker run -p 8989:8989 -v /path/to/volume:/app/weaviate_data codegate:latest
139+
```
140+
141+
## 🤝 Contributing
142+
143+
We welcome contributions! Whether it's bug reports, feature requests, or code contributions, please feel free to contribute to making Codegate better.
144+
145+
## 📜 License
146+
147+
This project is licensed under the terms specified in the [LICENSE](LICENSE) file.

config.yaml.example

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
1-
# Example configuration file
2-
# Copy this file to config.yaml and modify as needed
1+
# Codegate Example Configuration
32

4-
# Server configuration
5-
port: 8989
6-
host: "localhost"
3+
# Network settings
4+
port: 8989 # Port to listen on (1-65535)
5+
host: "localhost" # Host to bind to (use localhost for all interfaces)
76

87
# Logging configuration
9-
log_level: "INFO" # ERROR, WARNING, INFO, DEBUG
10-
log_format: "JSON" # JSON, TEXT
8+
log_level: "INFO" # One of: ERROR, WARNING, INFO, DEBUG
119

12-
# Prompts configuration
13-
# Option 1: Define prompts directly in the config file
14-
prompts:
15-
my_system_prompt: "Custom system prompt defined in config"
16-
another_prompt: "Another custom prompt"
10+
# Note: This configuration can be overridden by:
11+
# 1. CLI arguments (--port, --host, --log-level)
12+
# 2. Environment variables (CODEGATE_APP_PORT, CODEGATE_APP_HOST, CODEGATE_APP_LOG_LEVEL)
1713

18-
# Option 2: Reference a separate prompts file
19-
# prompts: "prompts.yaml" # Path to prompts file (relative to config file or absolute)
14+
# Provider URLs
15+
provider_urls:
16+
openai: "https://api.openai.com/v1"
17+
anthropic: "https://api.anthropic.com/v1"
18+
vllm: "http://localhost:8000" # Base URL without /v1 path, it will be added automatically
19+
20+
# Note: Provider URLs can be overridden by environment variables:
21+
# CODEGATE_PROVIDER_OPENAI_URL
22+
# CODEGATE_PROVIDER_ANTHROPIC_URL
23+
# CODEGATE_PROVIDER_VLLM_URL
24+
# Or by CLI flags:
25+
# --vllm-url
26+
# --openai-url
27+
# --anthropic-url
28+
29+
# Embedding model configuration
30+
31+
####
32+
# Inference model configuration
33+
##
34+
35+
# Model to use for chatting
36+
chat_model_path: "./models/qwen2.5-coder-1.5b-instruct-q5_k_m.gguf"
37+
38+
# Context length of the model
39+
chat_model_n_ctx: 32768
40+
41+
# Number of layers to offload to GPU. If -1, all layers are offloaded.
42+
chat_model_n_gpu_layers: -1

docs/cli.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ codegate serve [OPTIONS]
4646
- Must be a valid YAML file
4747
- Overrides default prompts and configuration file prompts
4848

49+
- `--vllm-url TEXT`: vLLM provider URL (default: http://localhost:8000)
50+
- Optional
51+
- Base URL for vLLM provider (/v1 path is added automatically)
52+
- Overrides configuration file and environment variables
53+
54+
- `--openai-url TEXT`: OpenAI provider URL (default: https://api.openai.com/v1)
55+
- Optional
56+
- Base URL for OpenAI provider
57+
- Overrides configuration file and environment variables
58+
59+
- `--anthropic-url TEXT`: Anthropic provider URL (default: https://api.anthropic.com/v1)
60+
- Optional
61+
- Base URL for Anthropic provider
62+
- Overrides configuration file and environment variables
63+
4964
### show-prompts
5065

5166
Display the loaded system prompts:
@@ -100,6 +115,11 @@ Start server with custom prompts:
100115
codegate serve --prompts my-prompts.yaml
101116
```
102117

118+
Start server with custom vLLM endpoint:
119+
```bash
120+
codegate serve --vllm-url https://vllm.example.com
121+
```
122+
103123
Show default system prompts:
104124
```bash
105125
codegate show-prompts

0 commit comments

Comments
 (0)