Picture by rawpixel.com on Freepik
For the reason that launch of the GPT mannequin, everybody has been utilizing them consistently. From asking easy inquiries to growing complicated coding, the GPT mannequin may also help the consumer swiftly. That’s why the mannequin would solely get greater over time.
To assist customers get the perfect output, OpenAI offers their greatest follow for utilizing the GPT mannequin. This comes from the expertise as many customers have experimented with this mannequin consistently and have discovered what works greatest.
On this article, I’ll summarize the perfect practices you need to know for utilizing the OpenAI GPT mannequin. What are these practices? Let’s get into it.
GPT mannequin output is simply pretty much as good as your immediate. With particular directions for what you need, it could present the end result you anticipated. A number of suggestions to enhance your GPT output embody:
- Have a element within the immediate to get related solutions. For instance, as an alternative of the immediate “Give me code to calculate regular distribution”, we are able to write “Present me with the usual distribution calculation with the code instance in Python. Place a remark in every part and clarify why each code is executed that approach.
- Give a persona or instance, plus add the size of the output. We are able to carry a persona or instance to the mannequin for higher readability. For instance, we are able to go the system position parameter to clarify one thing in a approach that the trainer would clarify issues to the scholars. By offering persona, the GPT mannequin would carry leads to a approach that we require. Here’s a pattern code if you wish to change the persona.
import openai
openai.api_key = ""
res = openai.ChatCompletion.create(
mannequin="gpt-3.5-turbo",
max_tokens=100,
temperature=0.7,
messages=[
{
"role": "system",
"content": """
When I ask to explain something, bring it in a way that teacher
would explain it to students in every paragraph.
""",
},
{
"role": "user",
"content": """
What is golden globe award and what is the criteria for this award? Summarize them in 2 paragraphs.
""",
},
],
)
It’s additionally nice to offer instance outcomes to direct how the GPT mannequin ought to reply your questions. For instance, on this code, I go how I might clarify emotion, and the GPT mannequin ought to mimic my fashion.
res = openai.ChatCompletion.create(
mannequin="gpt-3.5-turbo",
max_tokens=100,
temperature=0.7,
messages=[
{
"role": "system",
"content": "Answer in a consistent style.",
},
{
"role": "user",
"content": "Teach me about Love",
},
{
"role": "assistant",
"content": "Love can be sweet, can be sour, can be grand, can be low, and can be anything you want to be",
},
{
"role": "user",
"content": "Teach me about Fear",
},
],
)
- Specify the steps to finish your duties. Present detailed steps on the way you need the output for the perfect output. Give an in depth breakdown of the instruction on how the GPT mannequin ought to act. For instance, we put 2-step directions with prefixes and translations on this code.
res = openai.ChatCompletion.create(
mannequin="gpt-3.5-turbo",
max_tokens=100,
temperature=0.7,
messages= [
{
"role": "system",
"content": """
Use the following step-by-step instructions to respond to user inputs.
step 1 - Explain the question input by the user in 2 paragraphs or less with the prefix "Explanation: ".
Step 2 - Translate the Step 1 into Indonesian, with a prefix that says "Translation: ".
""",
},
{
"role": "user",
"content":"What is heaven?",
},
])
- Present references, hyperlinks or citations. If we have already got varied references for our questions, we are able to use them as the premise for the GPT mannequin to offer the output. Give the record of any references you assume are related to your questions and go them into the system position.
- Give GPT time to “assume”. Present a question permitting GPT to course of the immediate intimately earlier than dashing to present incorrect outcomes. That is very true if we go the assistant position a mistaken end result, and we would like the GPT to have the ability to assume critically for themselves. For instance, the code beneath exhibits how we ask the GPT mannequin to be extra important of the consumer enter.
res = openai.ChatCompletion.create(
mannequin="gpt-3.5-turbo",
max_tokens=100,
temperature=0.7,
messages= [
{
"role": "system",
"content": """
Work on your solution to the problem, then compare your solution to the user and evaluate
if the solution is correct or not. Only decide if the solution is correct once you have done the problem yourself.
""",
},
{
"role": "user",
"content":"1 + 1 = 3",
},
])
- Carry GPT to make use of Code Execution for exact outcomes. For extra prolonged and extra complicated calculations, GPT won’t work as supposed, because the mannequin would possibly present inaccurate outcomes. To alleviate this, we are able to ask the GPT mannequin to write down and run coding somewhat than immediately calculating them. This fashion, GPT can depend on the code somewhat than its calculation. For instance, we are able to present enter like beneath.
res = openai.ChatCompletion.create(
mannequin="gpt-3.5-turbo",
max_tokens=100,
temperature=0.7,
messages= [
{
"role": "system",
"content": """
Write and execute Python code by enclosing it in triple backticks,
e.g. ```code goes here```. Use this to perform calculations.
""",
},
{
"role": "user",
"content":"""
Find all real-valued roots of the following polynomial equation: 2*x**5 - 3*x**8- 2*x**3 - 9*x + 11.
""",
},
])
The GPT mannequin is likely one of the greatest fashions on the market, and listed below are some greatest practices to enhance the GPT mannequin output:
- Have a element within the immediate to get related solutions
- Give a persona or instance, plus add the size of the output
- Specify the steps to finish your duties
- Present references, hyperlinks or citations
- Give GPT time to “assume”
- Carry GPT to make use of Code Execution for exact outcomes
Cornellius Yudha Wijaya is an information science assistant supervisor and knowledge author. Whereas working full-time at Allianz Indonesia, he likes to share Python and Knowledge suggestions by way of social media and writing media.