Get startedGet started for free

Controlling output structure

One way to control the output structure provided by a language model is to give it a sample question-answer in the prompt. The model will learn from it and follow it when generating responses for similar questions. This exercise aims to let you build a one-shot prompt that extracts odd numbers from a given set of numbers and displays them as a set of numbers between brackets, separated by commas as shown in the instructions.

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

This exercise is part of the course

Prompt Engineering with the OpenAI API

View Course

Exercise instructions

  • Create a one-shot prompt that provides an example showing how to extract the odd numbers from the set {1, 3, 7, 12, 19}, and seeks an answer for the set {3, 5, 11, 12, 16}.

Hands-on interactive exercise

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

client = OpenAI(api_key="")

# Create a one-shot prompt
prompt = """____"""

response = get_response(prompt)
print(response)
Edit and Run Code