Spaces:
Runtime error
Runtime error
File size: 633 Bytes
82d9634 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import openai
def translate(text, target_lang):
"""Translate text to target language using OpenAI's GPT-3 API."""
client = openai.Client()
response = client.chat.completions.create(
messages=[{"role": "system", "content": f"You are AI-translator and you should translate text to {target_lang}"},
{'role': 'user', 'content': f'Please translate this text to {target_lang}: {text}. '
f'Answer with tranlsatrion and no additional information.'},
],
model="gpt-3.5-turbo",
)
return response.choices[0].message.content
|