MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Prompt Engineering with the OpenAI API

Lihat Kursus

Petunjuk latihan

  • 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}.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

client = OpenAI(api_key="")

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

response = get_response(prompt)
print(response)
Edit dan Jalankan Kode