Skip to content

Commit 9956eb9

Browse files
committed
Updated translator + app integration logic
1 parent 0e4d3d1 commit 9956eb9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def hardcoded_translate():
2020
text = data.get("text", "") if data else ""
2121
# For P4A, we return a dummy translation response
2222
return jsonify({
23-
"translatedText": "Hello world"
23+
"translated": "Hello, this is a hardcoded translation for P4A",
24+
"is_english": False
2425
}), 200
2526

2627
if __name__ == "__main__":

src/translator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
def translate_content(content: str) -> tuple[bool, str]:
24
if content == "这是一条中文消息":
35
return False, "This is a Chinese message"
@@ -32,3 +34,4 @@ def translate_content(content: str) -> tuple[bool, str]:
3234
if content == "This is an English message":
3335
return True, "This is an English message"
3436
return True, content
37+

test/unit/test_translator.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ def test_chinese():
77
assert translated_content == "This is a Chinese message"
88

99
def test_llm_normal_response():
10-
pass
10+
# A normal English sentence
11+
is_english, translated_content = translate_content("This is an English message")
12+
assert is_english == True
13+
assert translated_content == "This is an English message"
1114

1215
def test_llm_gibberish_response():
13-
pass
16+
# A gibberish or unrecognized message
17+
is_english, translated_content = translate_content("asldkjasldkj123!@#")
18+
# Since it's not a known foreign message, we assume it's English
19+
assert is_english == True
20+
assert translated_content == "asldkjasldkj123!@#"

0 commit comments

Comments
 (0)