Skip to content

Commit e6e5e7d

Browse files
committed
Addressed PR comments
1 parent 6c2a6ac commit e6e5e7d

6 files changed

Lines changed: 61 additions & 34 deletions

File tree

sample_solutions/CodeTranslation/.env.example

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ BACKEND_PORT=5001
44
# Inference API Configuration
55
# INFERENCE_API_ENDPOINT: URL to your inference service (without /v1 suffix)
66
# - For GenAI Gateway: https://genai-gateway.example.com
7-
# - For APISIX Gateway: https://apisix-gateway.example.com/inference
7+
# - For APISIX Gateway: https://apisix-gateway.example.com/CodeLlama-34b-Instruct-hf
8+
# Note: APISIX Gateway requires the model name in the URL path
89
#
910
# INFERENCE_API_TOKEN: Authentication token/API key for the inference service
1011
# - For GenAI Gateway: Your GenAI Gateway API key
@@ -18,13 +19,16 @@ LLM_TEMPERATURE=0.2
1819
LLM_MAX_TOKENS=4096
1920

2021
# Code Translation Settings
21-
MAX_CODE_LENGTH=10000
22+
# MAX_CODE_LENGTH: Maximum input code length in characters
23+
# Note: For Enterprise Inference with CodeLlama-34b (max tokens: 5196)
24+
# Recommended value is 8000-12000 characters (~4000-5000 tokens with prompt overhead)
25+
MAX_CODE_LENGTH=8000
2226
MAX_FILE_SIZE=10485760
2327

2428
# CORS Configuration
2529
CORS_ALLOW_ORIGINS=["http://localhost:5173", "http://localhost:3000"]
2630

2731
# Local URL Endpoint (only needed for non-public domains)
28-
# If using a local domain like inference.example.com mapped to localhost, set to the domain without https://
32+
# If using a local domain like api.example.com mapped to localhost, set to the domain without https://
2933
# Otherwise, set to: not-needed
3034
LOCAL_URL_ENDPOINT=not-needed

sample_solutions/CodeTranslation/README.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ The system integrates a FastAPI backend, alongside a modern React + Vite + Tailw
55

66
## Table of Contents
77

8+
- [Code Translation](#code-translation)
9+
- [Table of Contents](#table-of-contents)
810
- [Project Overview](#project-overview)
911
- [Features](#features)
1012
- [Architecture](#architecture)
1113
- [Prerequisites](#prerequisites)
14+
- [System Requirements](#system-requirements)
15+
- [Required API Configuration](#required-api-configuration)
16+
- [Local Development Configuration](#local-development-configuration)
17+
- [Verify Docker Installation](#verify-docker-installation)
1218
- [Quick Start Deployment](#quick-start-deployment)
19+
- [Clone the Repository](#clone-the-repository)
20+
- [Set up the Environment](#set-up-the-environment)
21+
- [Running the Application](#running-the-application)
1322
- [User Interface](#user-interface)
23+
- [Stopping the Application](#stopping-the-application)
1424
- [Troubleshooting](#troubleshooting)
1525
- [Additional Info](#additional-info)
1626

@@ -124,21 +134,22 @@ Before you begin, ensure you have the following installed:
124134
This application supports multiple inference deployment patterns:
125135

126136
- **GenAI Gateway**: Provide your GenAI Gateway URL and API key
137+
- To generate the GenAI Gateway API key, use the [generate-vault-secrets.sh](https://github.com/opea-project/Enterprise-Inference/blob/main/core/scripts/generate-vault-secrets.sh) script
138+
- The API key is the `litellm_master_key` value from the generated `vault.yml` file
139+
127140
- **APISIX Gateway**: Provide your APISIX Gateway URL and authentication token
128-
129-
Configuration requirements:
130-
- INFERENCE_API_ENDPOINT: URL to your inference service (GenAI Gateway, APISIX Gateway, etc.)
131-
- INFERENCE_API_TOKEN: Authentication token/API key for your chosen service
141+
- To generate the APISIX authentication token, use the [generate-token.sh](https://github.com/opea-project/Enterprise-Inference/blob/main/core/scripts/generate-token.sh) script
142+
- The token is generated using Keycloak client credentials
132143

133144
### Local Development Configuration
134145

135146
**For Local Testing Only (Optional)**
136147

137-
If you're testing with a local inference endpoint using a custom domain (e.g., `inference.example.com` mapped to localhost in your hosts file):
148+
If you're testing with a local inference endpoint using a custom domain (e.g., `api.example.com` mapped to localhost in your hosts file):
138149

139150
1. Edit `.env` and set:
140151
```bash
141-
LOCAL_URL_ENDPOINT=inference.example.com
152+
LOCAL_URL_ENDPOINT=api.example.com
142153
```
143154
(Use the domain name from your INFERENCE_API_ENDPOINT without `https://`)
144155

@@ -165,8 +176,8 @@ docker ps
165176
### Clone the Repository
166177

167178
```bash
168-
git clone https://github.com/opea-project/Enterprise-Inference.git
169-
cd Enterprise-Inference/sample_solutions/CodeTranslation
179+
git clone https://github.com/cld2labs/GenAISamples.git
180+
cd GenAISamples/code-translation
170181
```
171182

172183
### Set up the Environment
@@ -182,7 +193,8 @@ BACKEND_PORT=5001
182193
# Inference API Configuration
183194
# INFERENCE_API_ENDPOINT: URL to your inference service (without /v1 suffix)
184195
# - For GenAI Gateway: https://genai-gateway.example.com
185-
# - For APISIX Gateway: https://apisix-gateway.example.com/inference
196+
# - For APISIX Gateway: https://apisix-gateway.example.com/CodeLlama-34b-Instruct-hf
197+
# Note: APISIX Gateway requires the model name in the URL path
186198
#
187199
# INFERENCE_API_TOKEN: Authentication token/API key for the inference service
188200
# - For GenAI Gateway: Your GenAI Gateway API key
@@ -196,14 +208,17 @@ LLM_TEMPERATURE=0.2
196208
LLM_MAX_TOKENS=4096
197209
198210
# Code Translation Settings
199-
MAX_CODE_LENGTH=10000
211+
# MAX_CODE_LENGTH: Maximum input code length in characters
212+
# Note: For Enterprise Inference with CodeLlama-34b (max tokens: 5196)
213+
# Recommended value is 8000-12000 characters (~4000-5000 tokens with prompt overhead)
214+
MAX_CODE_LENGTH=8000
200215
MAX_FILE_SIZE=10485760
201216
202217
# CORS Configuration
203218
CORS_ALLOW_ORIGINS=["http://localhost:5173", "http://localhost:3000"]
204219
205220
# Local URL Endpoint (only needed for non-public domains)
206-
# If using a local domain like inference.example.com mapped to localhost, set to the domain without https://
221+
# If using a local domain like api.example.com mapped to localhost, set to the domain without https://
207222
# Otherwise, set to: not-needed
208223
LOCAL_URL_ENDPOINT=not-needed
209224
EOF
@@ -218,7 +233,8 @@ BACKEND_PORT=5001
218233
# Inference API Configuration
219234
# INFERENCE_API_ENDPOINT: URL to your inference service (without /v1 suffix)
220235
# - For GenAI Gateway: https://genai-gateway.example.com
221-
# - For APISIX Gateway: https://apisix-gateway.example.com/inference
236+
# - For APISIX Gateway: https://apisix-gateway.example.com/CodeLlama-34b-Instruct-hf
237+
# Note: APISIX Gateway requires the model name in the URL path
222238
#
223239
# INFERENCE_API_TOKEN: Authentication token/API key for the inference service
224240
# - For GenAI Gateway: Your GenAI Gateway API key
@@ -232,14 +248,17 @@ LLM_TEMPERATURE=0.2
232248
LLM_MAX_TOKENS=4096
233249

234250
# Code Translation Settings
235-
MAX_CODE_LENGTH=10000
251+
# MAX_CODE_LENGTH: Maximum input code length in characters
252+
# Note: For Enterprise Inference with CodeLlama-34b (max tokens: 5196)
253+
# Recommended value is 8000-12000 characters (~4000-5000 tokens with prompt overhead)
254+
MAX_CODE_LENGTH=8000
236255
MAX_FILE_SIZE=10485760
237256

238257
# CORS Configuration
239258
CORS_ALLOW_ORIGINS=["http://localhost:5173", "http://localhost:3000"]
240259

241260
# Local URL Endpoint (only needed for non-public domains)
242-
# If using a local domain like inference.example.com mapped to localhost, set to the domain without https://
261+
# If using a local domain like api.example.com mapped to localhost, set to the domain without https://
243262
# Otherwise, set to: not-needed
244263
LOCAL_URL_ENDPOINT=not-needed
245264
```
@@ -255,7 +274,7 @@ LOCAL_URL_ENDPOINT=not-needed
255274
Start both API and UI services together with Docker Compose:
256275

257276
```bash
258-
# From the CodeTranslation directory
277+
# From the code-translation directory
259278
docker compose up --build
260279

261280
# Or run in detached mode (background)
@@ -343,7 +362,7 @@ For comprehensive troubleshooting guidance, common issues, and solutions, refer
343362

344363
## Additional Info
345364

346-
The following models have been validated with CodeTranslation:
365+
The following models have been validated with code-translation:
347366

348367
| Model | Hardware |
349368
|-------|----------|

sample_solutions/CodeTranslation/TROUBLESHOOTING.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ This document contains all common issues encountered during development and thei
2222
```
2323
3. Restart the server
2424

25-
#### "Code too long. Maximum length is 10000 characters"
25+
#### "Code too long. Maximum length is 8000 characters"
2626

2727
**Solution**:
2828

2929
- The limit exists due to model context window constraints
30+
- CodeLlama-34b on Enterprise Inference has a max token limit of 5196
31+
- 8000 characters ≈ 4000-5000 tokens including prompt overhead
3032
- Break your code into smaller modules
3133
- Translate one class or function at a time
32-
- Or adjust `MAX_CODE_LENGTH` in `.env` if needed
34+
- Or adjust `MAX_CODE_LENGTH` in `.env` if your deployment supports higher limits (up to ~12000 characters max)
3335

3436
#### "Source language not supported"
3537

@@ -120,7 +122,7 @@ npm run dev
120122

121123
### Character Counter Not Updating
122124

123-
**Problem**: Character counter shows 0 / 10,000 even with code
125+
**Problem**: Character counter shows 0 / 8,000 even with code
124126

125127
**Solution**:
126128

sample_solutions/CodeTranslation/api/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424

2525
# Code Translation Settings
2626
SUPPORTED_LANGUAGES = ["java", "c", "cpp", "python", "rust", "go"]
27-
MAX_CODE_LENGTH = 10000 # characters
28-
LLM_TEMPERATURE = 0.2 # Lower temperature for more deterministic code generation
29-
LLM_MAX_TOKENS = 4096
27+
# MAX_CODE_LENGTH: For Enterprise Inference with CodeLlama-34b (max tokens: 5196)
28+
# Recommended: 8000-12000 characters (~4000-5000 tokens with prompt overhead)
29+
MAX_CODE_LENGTH = int(os.getenv("MAX_CODE_LENGTH", "8000")) # characters
30+
LLM_TEMPERATURE = float(os.getenv("LLM_TEMPERATURE", "0.2")) # Lower temperature for more deterministic code generation
31+
LLM_MAX_TOKENS = int(os.getenv("LLM_MAX_TOKENS", "4096"))
3032

3133
# CORS Settings
3234
CORS_ALLOW_ORIGINS = ["*"] # Update with specific origins in production

sample_solutions/CodeTranslation/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- INFERENCE_MODEL_NAME=${INFERENCE_MODEL_NAME}
1515
- LLM_TEMPERATURE=${LLM_TEMPERATURE:-0.2}
1616
- LLM_MAX_TOKENS=${LLM_MAX_TOKENS:-4096}
17-
- MAX_CODE_LENGTH=${MAX_CODE_LENGTH:-10000}
17+
- MAX_CODE_LENGTH=${MAX_CODE_LENGTH:-8000}
1818
- MAX_FILE_SIZE=${MAX_FILE_SIZE:-10485760}
1919
networks:
2020
- code-trans-network

sample_solutions/CodeTranslation/ui/src/components/CodeTranslator.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ export default function CodeTranslator({
127127
<label className="block text-sm font-medium text-gray-700">
128128
Source Code ({LANGUAGE_LABELS[sourceLanguage]})
129129
</label>
130-
<span className={`text-xs ${sourceCode.length > 10000 ? 'text-red-600 font-semibold' : 'text-gray-500'}`}>
131-
{sourceCode.length.toLocaleString()} / 10,000 characters
130+
<span className={`text-xs ${sourceCode.length > 8000 ? 'text-red-600 font-semibold' : 'text-gray-500'}`}>
131+
{sourceCode.length.toLocaleString()} / 8,000 characters
132132
</span>
133133
</div>
134134
<textarea
135135
value={sourceCode}
136136
onChange={(e) => setSourceCode(e.target.value)}
137137
placeholder={`Enter your ${sourceLanguage} code here...`}
138138
className={`w-full h-96 px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent font-mono text-sm resize-none ${
139-
sourceCode.length > 10000 ? 'border-red-500' : 'border-gray-300'
139+
sourceCode.length > 8000 ? 'border-red-500' : 'border-gray-300'
140140
}`}
141141
/>
142-
{sourceCode.length > 10000 && (
142+
{sourceCode.length > 8000 && (
143143
<p className="text-xs text-red-600 mt-1">
144-
Code exceeds maximum length. Please reduce to 10,000 characters or less.
144+
Code exceeds maximum length. Please reduce to 8,000 characters or less.
145145
</p>
146146
)}
147147
</div>
@@ -183,7 +183,7 @@ export default function CodeTranslator({
183183
{/* Translate Button */}
184184
<button
185185
onClick={handleTranslate}
186-
disabled={isTranslating || !sourceCode.trim() || sourceCode.length > 10000}
186+
disabled={isTranslating || !sourceCode.trim() || sourceCode.length > 8000}
187187
className="w-full bg-gradient-to-r from-blue-500 to-purple-600 text-white py-3 rounded-lg font-medium hover:from-blue-600 hover:to-purple-700 transition-all disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center space-x-2"
188188
>
189189
{isTranslating ? (
@@ -202,8 +202,8 @@ export default function CodeTranslator({
202202
{/* Info Note */}
203203
<div className="mt-4 p-3 bg-blue-50 border border-blue-200 rounded-lg">
204204
<p className="text-xs text-gray-600">
205-
<span className="font-semibold">Note:</span> The 10,000 character limit is due to CodeLlama-34b's
206-
context window (16K tokens). This ensures optimal translation quality and prevents timeouts.
205+
<span className="font-semibold">Note:</span> The 8,000 character limit is due to CodeLlama-34b's
206+
max token limit (5196 tokens) on Enterprise Inference. This ensures optimal translation quality and prevents errors.
207207
For larger files, consider breaking them into smaller modules.
208208
</p>
209209
</div>

0 commit comments

Comments
 (0)