import openai
# Set your OpenAI API key
api_key = 'YOUR_API_KEY'
# Initialize the OpenAI API client
openai.api_key = api_key
# Prompt for the model
prompt = "Translate the following English text to French: 'Hello, how are you?'"
# Make a request to the API
response = openai.Completion.create(
engine="text-davinci-002", # GPT-3.5 engine
prompt=prompt,
max_tokens=50, # You can adjust this to control the response length
n=1 # Number of responses to generate
)
# Extract and display the generated text
generated_text = response.choices[0].text
print(generated_text)