Example output
import openai
# Set up API key
openai.api_key = "YOUR_API_KEY"
# Define prompt
prompt = "Write a short adventure story"
# Generate story
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
# Print generated story
generated_story = response["choices"][0]["text"]
print(generated_story)
This script uses the OpenAI API to generate a single short adventure story based on the prompt "Write a short adventure story". The API response is stored in the response variable, and the generated story is extracted from the response and printed to the console.
Note: This script assumes that you have already obtained an API key for the OpenAI API and have entered it in the openai.api_key line.
Keep in mind that the quality of the generated stories will depend on the data that the API model was trained on and the parameters you provide in the request. You may need to experiment with different prompts, maximum token lengths, and temperature values to generate stories that meet your desired quality and style.