Skip to content

Commit 41edfbf

Browse files
Set MAX_CODE_LENGTH to 4000
1 parent 90a42b4 commit 41edfbf

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

sample_solutions/CodeTranslation/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ LLM_MAX_TOKENS=4096
2121
# Code Translation Settings
2222
# MAX_CODE_LENGTH: Maximum input code length in characters
2323
# 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
24+
# Set to 4000 characters to stay safely under the token limit with prompt overhead
25+
MAX_CODE_LENGTH=4000
2626
MAX_FILE_SIZE=10485760
2727

2828
# CORS Configuration

sample_solutions/CodeTranslation/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ LLM_MAX_TOKENS=4096
210210
# Code Translation Settings
211211
# MAX_CODE_LENGTH: Maximum input code length in characters
212212
# 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
213+
# Set to 4000 characters to stay safely under the token limit with prompt overhead
214+
MAX_CODE_LENGTH=4000
215215
MAX_FILE_SIZE=10485760
216216
217217
# CORS Configuration
@@ -250,8 +250,8 @@ LLM_MAX_TOKENS=4096
250250
# Code Translation Settings
251251
# MAX_CODE_LENGTH: Maximum input code length in characters
252252
# 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
253+
# Set to 4000 characters to stay safely under the token limit with prompt overhead
254+
MAX_CODE_LENGTH=4000
255255
MAX_FILE_SIZE=10485760
256256

257257
# CORS Configuration

sample_solutions/CodeTranslation/TROUBLESHOOTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +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 8000 characters"
25+
#### "Code too long. Maximum length is 4000 characters"
2626

2727
**Solution**:
2828

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

3636
#### "Source language not supported"
3737

sample_solutions/CodeTranslation/api/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
# Code Translation Settings
2626
SUPPORTED_LANGUAGES = ["java", "c", "cpp", "python", "rust", "go"]
2727
# 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
28+
# Set to 4000 characters to stay safely under the token limit with prompt overhead
29+
MAX_CODE_LENGTH = int(os.getenv("MAX_CODE_LENGTH", "4000")) # characters
3030
LLM_TEMPERATURE = float(os.getenv("LLM_TEMPERATURE", "0.2")) # Lower temperature for more deterministic code generation
3131
LLM_MAX_TOKENS = int(os.getenv("LLM_MAX_TOKENS", "4096"))
3232

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

Lines changed: 7 additions & 7 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 > 8000 ? 'text-red-600 font-semibold' : 'text-gray-500'}`}>
131-
{sourceCode.length.toLocaleString()} / 8,000 characters
130+
<span className={`text-xs ${sourceCode.length > 4000 ? 'text-red-600 font-semibold' : 'text-gray-500'}`}>
131+
{sourceCode.length.toLocaleString()} / 4,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 > 8000 ? 'border-red-500' : 'border-gray-300'
139+
sourceCode.length > 4000 ? 'border-red-500' : 'border-gray-300'
140140
}`}
141141
/>
142-
{sourceCode.length > 8000 && (
142+
{sourceCode.length > 4000 && (
143143
<p className="text-xs text-red-600 mt-1">
144-
Code exceeds maximum length. Please reduce to 8,000 characters or less.
144+
Code exceeds maximum length. Please reduce to 4,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 > 8000}
186+
disabled={isTranslating || !sourceCode.trim() || sourceCode.length > 4000}
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,7 +202,7 @@ 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 8,000 character limit is due to CodeLlama-34b's
205+
<span className="font-semibold">Note:</span> The 4,000 character limit is due to CodeLlama-34b's
206206
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>

0 commit comments

Comments
 (0)