Created
April 4, 2024 06:19
-
-
Save vinodjayachandran/454198f9cc21ef1c7b1d559250b36838 to your computer and use it in GitHub Desktop.
Language translations using OpenAI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openai import OpenAI | |
# Read OpenAI API Key from environment variable | |
api_key = os.environ.get("OPENAI_API_KEY") | |
client = OpenAI(api_key=api_key) | |
def translate_text(text): | |
model = "gpt-4-turbo-preview", | |
response = client.chat.completions.create( | |
model="gpt-3.5-turbo-0125", | |
messages=[ | |
{"role": "user", "content": f"Translate the following text to English: {text}"} | |
] | |
) | |
return response.choices[0].message.content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment