Last active
April 12, 2024 15:47
-
-
Save johnnieskywalker/8ec729d2cf610cf2e81ff0c9273c8831 to your computer and use it in GitHub Desktop.
Elvish Translator
This file contains hidden or 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
| python3 openai-test.py | |
| Enter the language to translate from: polski | |
| Enter the text to translate: Gandalfie którędy do najbliższej gospody ? | |
| The sentence "Gandalfie którędy do najbliższej gospody?" translates to Elvish as "Mithrandir, man cerir tenest i orthad?" in the language of the Elves from The Lord of the Rings. |
This file contains hidden or 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 | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
| client = OpenAI(api_key=OPENAI_API_KEY) | |
| language = input("Enter the language to translate from: ") | |
| text = input("Enter the text to translate: ") | |
| try: | |
| completion = client.chat.completions.create( | |
| model='gpt-3.5-turbo', | |
| messages=[ | |
| {"role": "system", "content": "You are a helpful assistant."}, | |
| {"role": "user", "content": f"Translate the following {text} from {language} to Elfish from LOTR"} | |
| ] | |
| ) | |
| print(completion.choices[0].message.content) | |
| except AttributeError: | |
| print("The method you are trying to use is not available. Check the latest API documentation.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment