Skip to content

Instantly share code, notes, and snippets.

@itrobotics
Last active November 21, 2023 01:59
Show Gist options
  • Save itrobotics/4839a002eb514285a82453aa1815de57 to your computer and use it in GitHub Desktop.
Save itrobotics/4839a002eb514285a82453aa1815de57 to your computer and use it in GitHub Desktop.
import openai
# Replace 'YOUR_API_KEY' with your actual API key from OpenAI
api_key = 'YOUR_API_KEY'
# Initialize the OpenAI API client
openai.api_key = api_key
# Specify the prompt for text generation
prompt = "Once upon a time,"
# Generate text using the GPT-3 model
response = openai.Completion.create(
engine="text-davinci-002", # You can choose different engines based on your use case
prompt=prompt,
max_tokens=50, # Adjust the number of tokens in the generated text
)
# Extract the generated text from the response
generated_text = response.choices[0].text
# Print the generated text
print(generated_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment