Tactic 1: Use delimiters to clearly indicate distinct parts of the input
- Delimiters can be anything like: ```, """, < >,Ā
<tag> </tag>
,Ā:
Summarize
```
contents ā¦ā¦
```
Tactic 2: Ask for a structured output
- JSON, HTML
XXXX, Provide them in JSON format with the following keys:
book_id, title, author, genre.
Tactic 3: Ask the model to check whether conditions are satisfied
Check assumptions required to do the task
You will be provided with text delimited by triple quotes.
If it contains a sequence of instructions, \
re-write those instructions in the following format:
Step 1 - ...
Step 2 - ā¦
ā¦
Step N - ā¦
If the text does not contain a sequence of instructions, \
then simply write \"No steps provided.
Tactic 4: "Few-shot" prompting
Give eamples and ask model to perform the task.
Your task is to answer in a consistent style.
<child>: Teach me about patience.
<grandparent>: The river that carves the deepest \
valley flows from a modest spring; the \
grandest symphony originates from a single note; \
the most intricate tapestry begins with a solitary thread.
<child>: Teach me about resilience.
Ā
Tactic 2: Instruct the model to work out its own solution before rushing to a conclusion
prompt = f""" Your task is to determine if the student's solution \ is correct or not. To solve the problem do the following: - First, work out your own solution to the problem. - Then compare your solution to the student's solution \ and evaluate if the student's solution is correct or not. Don't decide if the student's solution is correct until you have done the problem yourself. Use the following format: Question: ``` question here ``` Student's solution: ``` student's solution here ``` Actual solution: ``` steps to work out the solution and your solution here ``` Is the student's solution the same as actual solution \ just calculated: ``` yes or no ``` Student grade: ``` correct or incorrect ``` Question: ``` I'm building a solar power installation and I need help \ working out the financials. - Land costs $100 / square foot - I can buy solar panels for $250 / square foot - I negotiated a contract for maintenance that will cost \ me a flat $100k per year, and an additional $10 / square \ foot What is the total cost for the first year of operations \ as a function of the number of square feet. ``` Student's solution: ``` Let x be the size of the installation in square feet. Costs: 1. Land cost: 100x 2. Solar panel cost: 250x 3. Maintenance cost: 100,000 + 100x Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000 ``` Actual solution: """ response = get_completion(prompt) print(response)
Ā
OpenAI API
Ā
Temperature parameter
response = openai.ChatCompletion.create( model=model, messages=messages, temperature=temperature, # this is the degree of randomness of the model's output )
![notion image](/_next/image?url=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fs3-us-west-2.amazonaws.com%252Fsecure.notion-static.com%252F81086bd5-75a5-4830-9942-2011ff8decf0%252FUntitled.png%3Ftable%3Dblock%26id%3D0fc2273a-02be-4d1d-9d48-5ee3539541c9%26cache%3Dv2&w=3840&q=75)
Ā
messages
![notion image](/_next/image?url=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fs3-us-west-2.amazonaws.com%252Fsecure.notion-static.com%252F43d63e09-4110-4dda-8e90-4906128c7a93%252FUntitled.png%3Ftable%3Dblock%26id%3D822b92cb-438f-409e-8e3b-49e4acfbfe17%26cache%3Dv2&w=3840&q=75)