Skip to content

Commit

Permalink
Merge branch 'feat/openai-translation-support' of github.com:vusallyv…
Browse files Browse the repository at this point in the history
…/django-rosetta into vusallyv-feat/openai-translation-support
  • Loading branch information
mbi committed Jun 23, 2024
2 parents 78a76a9 + 0456a7d commit cf56dd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rosetta/translate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,16 @@ def translate_by_openai(text: str, from_language: str, to_language: str, api_key
return: The translated text.
"""

import openai
from openai import OpenAI

openai.api_key = api_key
client = OpenAI(api_key=api_key)

prompt = f"Translate the following text from {from_language} to {to_language}:\n\n{text}"

try:
response = openai.Completion.create(
engine="gpt-3.5-turbo-instruct",
prompt=prompt,
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt=prompt
)
translation = response.choices[0].text.strip()
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions rosetta/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def get_context_data(self, **kwargs):
rosetta_settings.DEEPL_AUTH_KEY
or rosetta_settings.AZURE_CLIENT_SECRET
or rosetta_settings.GOOGLE_APPLICATION_CREDENTIALS_PATH
or rosetta_settings.OPENAI_API_KEY
),
}

Expand Down

0 comments on commit cf56dd3

Please sign in to comment.