Skip to content

Commit

Permalink
Merge pull request #11 from RongYYYY/revert-6-ckpt-final
Browse files Browse the repository at this point in the history
Revert "fixing bugs"
  • Loading branch information
ogometz authored Nov 16, 2024
2 parents 92223c8 + 22ed3da commit 2b53606
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 25 additions & 9 deletions src/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
azure_endpoint="https://apirecitation.openai.azure.com" # Replace with your Azure endpoint
)

# Make a request to your Azure OpenAI model
response = client.chat.completions.create(
model="gpt-4o-mini", # This should match your deployment name in Azure
messages=[
{
"role": "user",
"content": "What is the future of artificial intelligence?"
}
]
)


def get_language(post: str) -> str:
context = f"I'm trying to translate some text, only return the language it is written in and nothing else. If you can't determine it, then only return the word 'unknown' What is the language of this text: {post}"
context = f"I'm trying to translate some text, only return the language it is written in and nothing else. What is the language this text: {post} is written in."

try:
# Make request for language detection
Expand Down Expand Up @@ -68,19 +79,24 @@ def get_translation(post: str) -> str:
def translate_content(content: str) -> tuple[bool, str]:
try:
is_eng = get_language(content)
if is_eng.lower() == "unknown":
return False, "Unknown language"
is_translated = get_translation(content)
if (is_translated is None or
not isinstance(is_translated, str) or
is_translated == "N/A" or
len(is_translated) <= 0 or
is_translated == "I don't understand your request"):
return False, "There was an error translating the text"

if is_eng == "English":
return True, content
else:
translated = get_translation(content)
# if (translated is None or
# not isinstance(translated, str) or
# translated == "N/A" or
# len(translated) <= 0 or
# translated == "I don't understand your request"):
# return False, "There was an error translating the text"
if (translated is None or
not isinstance(translated, str) or
translated == "N/A" or
len(translated) <= 0 or
translated == "I don't understand your request"):
return False, "There was an error translating the text"

original_full_stop_exist = content.endswith(".")
translated_post_full_stop_exist = translated.endswith(".")
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def test_llm_gibberish_response():
is_english, translated_content = translate_content("asdfghjkl12345")
print(f"Post: 'asdfghjkl12345', Is English: {is_english}, Translation: {translated_content}")
assert is_english == False
assert translated_content == "Unknown language"
assert translated_content == "There was an error translating the text"

0 comments on commit 2b53606

Please sign in to comment.