Get startedGet started for free

Building specific and precise prompts

In the previous exercise, you generated text that completes a given story. Your team was happy with your achievement, however, they want you to follow specific guidelines when it comes to length and style. Your task now is to craft a more specific prompt that controls these aspects of the generated story.

The OpenAI package, the get_response() function, and the same story variable have been pre-loaded for you.

This exercise is part of the course

Prompt Engineering with the OpenAI API

View Course

Exercise instructions

  • Craft a prompt that completes the given story with only two paragraphs in the style of Shakespeare; use f-string, and delimit the story with triple backticks (```).

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

client = OpenAI(api_key="")

# Create a request to complete the story
prompt = ____

# Get the generated response
response = ____

print("\n Original story: \n", story)
print("\n Generated story: \n", response)
Edit and Run Code