Self-consistency prompts
Imagine you own a store that sells laptops and mobile phones. You start your day with 50 devices in the store, out of which 60% are mobile phones. Throughout the day, three clients visited the store, each of them bought one mobile phone, and one of them bought additionally a laptop. Also, you added to your collection 10 laptops and 5 mobile phones. How many laptops and mobile phones do you have by the end of the day? This problem is defined in the problem_to_solve string, and you will use a self-consistency prompt to solve it.
The OpenAI package and the get_response() function have been pre-loaded for you.
The get_response() function in this exercise employs the max_tokens parameter to help this exercise run faster.
Deze oefening maakt deel uit van de cursus
Prompt Engineering with the OpenAI API
Oefeninstructies
- Create the
self_consistency_instructionthat allows the model to solve the problem with three experts and combine the results with a majority vote. - Create the final
promptby combining theself_consistency_instructionand theproblem_to_solve.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
client = OpenAI(api_key="")
# Create the self_consistency instruction
self_consistency_instruction = ____
# Create the problem to solve
problem_to_solve = "If you own a store that sells laptops and mobile phones. You start your day with 50 devices in the store, out of which 60% are mobile phones. Throughout the day, three clients visited the store, each of them bought one mobile phone, and one of them bought additionally a laptop. Also, you added to your collection 10 laptops and 5 mobile phones. How many laptops and mobile phones do you have by the end of the day?"
# Create the final prompt
prompt = ____
response = get_response(prompt)
print(response)