Skip to content

Commit 6d0e436

Browse files
committed
Revert "Adding query_llm_robust"
This reverts commit 0f7d899.
1 parent 0f7d899 commit 6d0e436

File tree

3 files changed

+13
-45
lines changed

3 files changed

+13
-45
lines changed

app.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
from flask import Flask
44
from flask import request, jsonify
55
from src.translator import translate_content
6-
from src.llm_utils import query_llm_robust
76

87
app = Flask(__name__)
98

109
@app.route("/")
1110
def translator():
1211
content = request.args.get("content", default = "", type = str)
13-
is_english, translated_content = query_llm_robust(content)
12+
is_english, translated_content = translate_content(content)
1413
return jsonify({
1514
"is_english": is_english,
1615
"translated_content": translated_content,
16+
})
17+
@app.route("/translate", methods=["POST"])
18+
def hardcoded_translate():
19+
data = request.get_json()
20+
text = data.get("text", "") if data else ""
21+
# For P4A, we return a dummy translation response
22+
return jsonify({
23+
"translated": "Hello, this is a hardcoded translation for P4A",
24+
"is_english": False
1725
}), 200
1826

19-
2027
if __name__ == "__main__":
2128
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))

requirements.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
Flask==3.0.0
22
pytest==7.4.0
33
ollama
4-
torch==2.9.0
5-
sentence_transformers
6-
pytest
7-
ipytest
8-
pytest-mock
9-
mock

src/llm_utils.py

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,7 @@
11
import ollama
2-
3-
MODEL_NAME = "gemma3:270m"
4-
5-
CLASSIFICATION_CONTEXT = """\
6-
You are a language identifier.
7-
Your task is to detect the primary language of the given text input and respond only with the English name of that language.
8-
9-
Rules:
10-
- Do not translate or explain.
11-
- Do not guess based on previous examples--decide only from the current input.
12-
- If the text appears to be random characters, symbols, or nonsense, respond with "English".
13-
14-
Output format: a single word--the English name of the detected language.
15-
16-
Examples:
17-
INPUT: Bonjour, je m'appelle Sarah
18-
OUTPUT: French
19-
20-
INPUT: Können Sie mir bitte helfen?
21-
OUTPUT: German
22-
23-
INPUT: %#$%#%#%#%#%@#!#!@#
24-
OUTPUT: English"""
25-
26-
TRANSLATION_CONTEXT = """\
27-
You are a translation model. Your only task is to translate any non-English input into natural, fluent English.
28-
Do not interpret, paraphrase, or answer the text- -only translate it exactly as written.
29-
Respond only with the English translation, and nothing else.
30-
31-
Example:
32-
INPUT: Bonjour, je m'appelle Sarah
33-
OUTPUT: Hello, my name is Sarah
34-
35-
INPUT: Il fait très chaud aujourd'hui, n'est-ce pas ?
36-
OUTPUT: It is very hot today, isn't it?
37-
"""
2+
MODEL_NAME = "test-model"
3+
CLASSIFICATION_CONTEXT = "Classify language"
4+
TRANSLATION_CONTEXT = "Translate to English"
385

396
def get_translation(post: str) -> str:
407
try:

0 commit comments

Comments
 (0)