Self-consistency Prompts
Stell dir vor, du hast einen Laden, der Laptops und Handys verkauft. Du startest deinen Tag mit 50 Geräten im Laden, von denen 60 % Handys sind. Im Laufe des Tages kamen drei Kunden in den Laden, jeder kaufte ein Handy und einer kaufte zusätzlich einen Laptop. Außerdem hast du deiner Sammlung zehn Laptops und fünf Handys hinzugefügt. Wie viele Laptops und Handys hast du am Ende des Tages? Dieses Problem ist in der Zeichenfolge problem_to_solve definiert, und du wirst es mit einem self-consistency Prompt lösen.
Das Paket OpenAI und die Funktion get_response() sind bereits für dich vorinstalliert.
Die Funktion get_response() nutzt in dieser Übung den Parameter max_tokens, damit die Übung schneller läuft.
Diese Übung ist Teil des Kurses
Prompt-Engineering mit der OpenAI-API
Anleitung zur Übung
- Erstelle
self_consistency_instruction, damit das Modell das Problem mit drei Experten lösen und die Ergebnisse mit einer Mehrheitsentscheidung zusammenfassen kann. - Erstelle den endgültigen
prompt, indem duself_consistency_instructionundproblem_to_solvezusammenfügst.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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)