Skip to content

Commit 5e5f6f7

Browse files
committed
feat: add document support
Signed-off-by: dittops <[email protected]>
1 parent 481aea9 commit 5e5f6f7

21 files changed

+1179
-509
lines changed

PolyLingua/.env.example

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# ================================================
2+
# PolyLingua Environment Configuration
3+
# ================================================
4+
# Copy this file to .env and update with your values
5+
# Run: cp .env.example .env
6+
# Then edit .env with your actual configuration
7+
8+
# ================================================
9+
# HuggingFace Configuration
10+
# ================================================
11+
# Required: Get your token from https://huggingface.co/settings/tokens
12+
# This is needed to download models from HuggingFace Hub
13+
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
14+
15+
# ================================================
16+
# Model Configuration
17+
# ================================================
18+
# LLM model ID from HuggingFace
19+
# Default model supports multilingual translation
20+
LLM_MODEL_ID=swiss-ai/Apertus-8B-Instruct-2509
21+
22+
# Directory to cache downloaded models
23+
# Models can be large (several GB), ensure sufficient disk space
24+
MODEL_CACHE=./data
25+
26+
# ================================================
27+
# Host Configuration
28+
# ================================================
29+
# Your server/machine IP address
30+
# Use 'localhost' for local development
31+
# Use actual IP (e.g., 192.168.1.100) for network access
32+
host_ip=localhost
33+
34+
# ================================================
35+
# Backend Service Configuration
36+
# ================================================
37+
# vLLM (vLLM Inference) endpoint
38+
# This is the LLM inference service endpoint
39+
VLLM_ENDPOINT=http://localhost:8028
40+
41+
# LLM microservice configuration
42+
# Host and port for the LLM microservice
43+
LLM_SERVICE_HOST_IP=localhost
44+
LLM_SERVICE_PORT=9000
45+
46+
# PolyLingua megaservice configuration
47+
# Main translation service host and port
48+
MEGA_SERVICE_HOST_IP=localhost
49+
MEGA_SERVICE_PORT=8888
50+
51+
# Backend service details
52+
BACKEND_SERVICE_NAME=polylingua
53+
BACKEND_SERVICE_IP=localhost
54+
BACKEND_SERVICE_PORT=8888
55+
56+
# ================================================
57+
# Frontend Configuration
58+
# ================================================
59+
# Backend endpoint URL for the frontend
60+
# This is what the UI uses to connect to the backend
61+
BACKEND_SERVICE_ENDPOINT=http://localhost:8888
62+
63+
# Frontend service configuration
64+
# Next.js development server configuration
65+
FRONTEND_SERVICE_IP=localhost
66+
FRONTEND_SERVICE_PORT=5173
67+
68+
# ================================================
69+
# Docker Configuration
70+
# ================================================
71+
# Docker registry for pulling images
72+
# Use 'opea' for official OPEA images
73+
REGISTRY=opea
74+
75+
# Docker image tag
76+
# Use 'latest' for most recent version
77+
TAG=latest
78+
79+
# ================================================
80+
# Nginx Configuration
81+
# ================================================
82+
# Nginx reverse proxy port
83+
# Default HTTP port
84+
NGINX_PORT=80
85+
86+
# ================================================
87+
# Proxy Settings (Optional)
88+
# ================================================
89+
# Configure if behind a corporate proxy
90+
# Leave empty if not using a proxy
91+
92+
# HTTP proxy URL (e.g., http://proxy.company.com:8080)
93+
http_proxy=
94+
95+
# HTTPS proxy URL (e.g., http://proxy.company.com:8080)
96+
https_proxy=
97+
98+
# Comma-separated list of hosts to bypass proxy
99+
no_proxy=localhost,127.0.0.1
100+
101+
# ================================================
102+
# Quick Start Guide
103+
# ================================================
104+
#
105+
# 1. Copy this file:
106+
# cp .env.example .env
107+
#
108+
# 2. Edit .env and set your HF_TOKEN
109+
#
110+
# 3. Update host_ip if deploying to network
111+
# (use actual IP instead of localhost)
112+
#
113+
# 4. Start services:
114+
# docker compose up -d
115+
#
116+
# 5. Access UI at:
117+
# http://localhost:5173 (or http://<host_ip>:5173)
118+
#
119+
# ================================================

PolyLingua/.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Environment variables
2+
.env
3+
.env.local
4+
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# Virtual environments
28+
venv/
29+
env/
30+
ENV/
31+
.venv
32+
33+
# Model cache
34+
data/
35+
models/
36+
*.bin
37+
*.safetensors
38+
39+
# IDEs
40+
.vscode/
41+
.idea/
42+
*.swp
43+
*.swo
44+
*~
45+
46+
# OS
47+
.DS_Store
48+
Thumbs.db
49+
50+
# Logs
51+
*.log
52+
logs/
53+
54+
# Temporary files
55+
tmp/
56+
temp/
57+
*.tmp
58+
59+
# Node modules (for UI)
60+
ui/node_modules/
61+
ui/.next/
62+
ui/out/
63+
ui/build/
64+
65+
# Docker
66+
docker-compose.override.yml

PolyLingua/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ COPY requirements.txt .
1515
RUN pip install --no-cache-dir --upgrade pip && \
1616
pip install --no-cache-dir -r requirements.txt
1717

18-
# Copy translation service
19-
COPY translation.py .
18+
# Copy polylingua service
19+
COPY polylingua.py .
2020

2121
# Expose service port
2222
EXPOSE 8888
2323

24-
# Run the translation service
25-
ENTRYPOINT ["python", "translation.py"]
24+
# Run the polylingua service
25+
ENTRYPOINT ["python", "polylingua.py"]

PolyLingua/README.md

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,12 @@
1-
# PloyLingua
1+
# PolyLingua
22

33
A production-ready translation service built with **OPEA (Open Platform for Enterprise AI)** components, featuring a modern Next.js UI and microservices architecture.
44

5-
## 🏗️ Architecture
6-
7-
This service implements a **5-layer microservices architecture**:
8-
9-
```
10-
┌─────────────────────────────────────────────────────────────┐
11-
│ Nginx Reverse Proxy │
12-
│ (Port 80) │
13-
└────────────────┬────────────────────────────────────────────┘
14-
15-
┌────────┴─────────┐
16-
│ │
17-
┌───────▼────────┐ ┌──────▼──────────────────┐
18-
│ Next.js UI │ │ Translation Megaservice │
19-
│ (Port 5173) │ │ (Port 8888) │
20-
└────────────────┘ └──────┬──────────────────┘
21-
22-
┌────────▼────────────┐
23-
│ LLM Microservice │
24-
│ (Port 9000) │
25-
└────────┬────────────┘
26-
27-
┌────────▼────────────┐
28-
│ TGI Model Server │
29-
│ (Port 8008) │
30-
└─────────────────────┘
31-
```
32-
335
### Components
346

35-
1. **TGI Service** - HuggingFace Text Generation Inference for model serving
7+
1. **vLLM Service** - High-performance LLM inference engine for model serving
368
2. **LLM Microservice** - OPEA wrapper providing standardized API
37-
3. **Translation Megaservice** - Orchestrator that formats prompts and routes requests
9+
3. **PolyLingua Megaservice** - Orchestrator that formats prompts and routes requests
3810
4. **UI Service** - Next.js 14 frontend with React and TypeScript
3911
5. **Nginx** - Reverse proxy for unified access
4012

@@ -59,7 +31,7 @@ cd PolyLingua
5931

6032
You'll be prompted for:
6133
- **HuggingFace API Token** - Get from https://huggingface.co/settings/tokens
62-
- **Model ID** - Default: `haoranxu/ALMA-13B` (translation-optimized model)
34+
- **Model ID** - Default: `swiss-ai/Apertus-8B-Instruct-2509` (translation-optimized model)
6335
- **Host IP** - Your server's IP address
6436
- **Ports and proxy settings**
6537

@@ -113,7 +85,7 @@ Key variables in `.env`:
11385
| Variable | Description | Default |
11486
|----------|-------------|---------|
11587
| `HF_TOKEN` | HuggingFace API token | Required |
116-
| `LLM_MODEL_ID` | Model to use for translation | `haoranxu/ALMA-13B` |
88+
| `LLM_MODEL_ID` | Model to use for translation | `swiss-ai/Apertus-8B-Instruct-2509` |
11789
| `MODEL_CACHE` | Directory for model storage | `./data` |
11890
| `host_ip` | Server IP address | `localhost` |
11991
| `NGINX_PORT` | External port for web access | `80` |
@@ -133,24 +105,24 @@ The service works with any HuggingFace text generation model. Recommended models
133105
### Project Structure
134106

135107
```
136-
opea-translation/
137-
├── translation.py # Backend translation service
138-
├── requirements.txt # Python dependencies
139-
├── Dockerfile # Backend container definition
140-
├── docker-compose.yaml # Multi-service orchestration
141-
├── set_env.sh # Environment setup script
142-
├── .env.example # Environment template
143-
├── ui/ # Next.js frontend
144-
│ ├── app/ # Next.js app directory
145-
│ ├── components/ # React components
146-
│ ├── Dockerfile # UI container definition
147-
│ └── package.json # Node dependencies
148-
└── deploy/ # Deployment scripts
149-
├── nginx.conf # Nginx configuration
150-
├── build.sh # Image build script
151-
├── start.sh # Service startup script
152-
├── stop.sh # Service shutdown script
153-
└── test.sh # API testing script
108+
PolyLingua/
109+
├── polylingua.py # Backend polylingua service
110+
├── requirements.txt # Python dependencies
111+
├── Dockerfile # Backend container definition
112+
├── docker-compose.yaml # Multi-service orchestration
113+
├── set_env.sh # Environment setup script
114+
├── .env.example # Environment template
115+
├── ui/ # Next.js frontend
116+
│ ├── app/ # Next.js app directory
117+
│ ├── components/ # React components
118+
│ ├── Dockerfile # UI container definition
119+
│ └── package.json # Node dependencies
120+
└── deploy/ # Deployment scripts
121+
├── nginx.conf # Nginx configuration
122+
├── build.sh # Image build script
123+
├── start.sh # Service startup script
124+
├── stop.sh # Service shutdown script
125+
└── test.sh # API testing script
154126
```
155127

156128
### Running Locally (Development)
@@ -166,7 +138,7 @@ export LLM_SERVICE_PORT=9000
166138
export MEGA_SERVICE_PORT=8888
167139

168140
# Run service
169-
python translation.py
141+
python polylingua.py
170142
```
171143

172144
**Frontend:**
@@ -194,7 +166,7 @@ Translate text between languages.
194166
**Response:**
195167
```json
196168
{
197-
"model": "translation",
169+
"model": "polylingua",
198170
"choices": [{
199171
"index": 0,
200172
"message": {
@@ -216,8 +188,8 @@ Translate text between languages.
216188
docker compose logs -f
217189

218190
# Specific service
219-
docker compose logs -f translation-backend-server
220-
docker compose logs -f translation-ui-server
191+
docker compose logs -f polylingua-backend-server
192+
docker compose logs -f polylingua-ui-server
221193
```
222194

223195
### Stop Services
@@ -253,7 +225,7 @@ docker compose down -v
253225

254226
1. Check if ports are available:
255227
```bash
256-
sudo lsof -i :80,8888,9000,8008,5173
228+
sudo lsof -i :80,8888,9000,8028,5173
257229
```
258230

259231
2. Verify environment variables:
@@ -276,9 +248,9 @@ docker compose down -v
276248

277249
### Translation errors
278250

279-
- Wait for TGI service to fully initialize (check logs)
251+
- Wait for vLLM service to fully initialize (check logs)
280252
- Verify LLM service is healthy: `curl http://localhost:9000/v1/health`
281-
- Check TGI service: `curl http://localhost:8008/health`
253+
- Check vLLM service: `curl http://localhost:8028/health`
282254

283255
### UI can't connect to backend
284256

@@ -293,7 +265,7 @@ docker compose down -v
293265
- [OPEA Project](https://github.com/opea-project)
294266
- [GenAIComps](https://github.com/opea-project/GenAIComps)
295267
- [GenAIExamples](https://github.com/opea-project/GenAIExamples)
296-
- [HuggingFace Text Generation Inference](https://github.com/huggingface/text-generation-inference)
268+
- [vLLM](https://github.com/vllm-project/vllm)
297269

298270
## 📧 Support
299271

0 commit comments

Comments
 (0)