• AIPressRoom
  • Posts
  • Finest Practices to Use OpenAI GPT Mannequin

Finest Practices to Use OpenAI GPT Mannequin

For the reason that launch of the GPT mannequin, everybody has been utilizing them continually. From asking easy inquiries to creating complicated coding, the GPT mannequin will help the person swiftly. That’s why the mannequin would solely get greater over time.

To assist customers get one of the best output, OpenAI gives their best practice for utilizing the GPT mannequin. This comes from the expertise as many customers have experimented with this mannequin continually and have discovered what works greatest.

On this article, I’ll summarize one of the best practices you need to know for utilizing the OpenAI GPT mannequin. What are these practices? Let’s get into it.

GPT mannequin output is barely pretty much as good as your immediate. With particular directions for what you need, it might present the end result you anticipated. A number of suggestions to enhance your GPT output embrace:

  1. Have a element within the immediate to get related solutions. For instance, as a substitute of the immediate “Give me code to calculate regular distribution”, we will 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 means.

  1. Give a persona or instance, plus add the size of the output. We will carry a persona or instance to the mannequin for higher readability. For instance, we will move the system position parameter to clarify one thing in a means that the trainer would clarify issues to the scholars. By offering persona, the GPT mannequin would carry ends in a means 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 supply instance outcomes to direct how the GPT mannequin ought to reply your questions. For instance, on this code, I move 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",
        },
    ],
)
  1. Specify the steps to finish your duties. Present detailed steps on the way you need the output for one of the best 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?",
         },
        ])
  1. Present references, hyperlinks or citations. If we have already got numerous references for our questions, we will use them as the idea for the GPT mannequin to supply the output. Give the checklist of any references you suppose are related to your questions and move them into the system position. 

  1. Give GPT time to “suppose”. Present a question permitting GPT to course of the immediate intimately earlier than speeding to provide incorrect outcomes. That is very true if we move the assistant position a incorrect end result, and we wish the GPT to have the ability to suppose critically for themselves. For instance, the code under reveals how we ask the GPT mannequin to be extra crucial of the person 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",
         },
        ])
  1. Carry GPT to make use of Code Execution for exact outcomes. For extra prolonged and extra complicated calculations, GPT may not work as meant, because the mannequin would possibly present inaccurate outcomes. To alleviate this, we will ask the GPT mannequin to put in writing and run coding reasonably than immediately calculating them. This manner, GPT can depend on the code reasonably than its calculation. For instance, we will present enter like under.

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 without doubt one of the greatest fashions on the market, and listed below are some greatest practices to enhance the GPT mannequin output:

  1. Have a element within the immediate to get related solutions

  2. Give a persona or instance, plus add the size of the output

  3. Specify the steps to finish your duties

  4. Present references, hyperlinks or citations

  5. Give GPT time to “suppose”

  6. Carry GPT to make use of Code Execution for exact outcomes

  Cornellius Yudha Wijaya is an information science assistant supervisor and information author. Whereas working full-time at Allianz Indonesia, he likes to share Python and Knowledge suggestions through social media and writing media.