Cover Image for Improve the Accuracy of Your Generated Text with ChatGPT and Template Prompts
Abdulrahman Muhialdeen
Abdulrahman Muhialdeen

Improve the Accuracy of Your Generated Text with ChatGPT and Template Prompts

As the demand for high-quality content continues to increase, content creators and writers are constantly looking for ways to save time and...

As the demand for high-quality content continues to increase, content creators and writers are constantly looking for ways to save time and increase productivity. OpenAI’s ChatGPT model has emerged as a powerful tool for generating natural language text, but the challenge lies in getting accurate and relevant results.

One way to improve the accuracy of generated text is by using template prompts. By providing a structured format for the input, template prompts can guide the ChatGPT model to generate more accurate and relevant responses.

Let’s take an example to illustrate the point. Suppose you want to ask ChatGPT to write a unit test for a C# method. Without a template prompt, the ChatGPT model might generate a response that is far away from the code pattern used in your current project. However, by using a template prompt, you can provide more context and instructions to the model to generate a more accurate response.

Here’s an example of a template prompt for generating a unit test for a C# method:

Prompt: Write a unit test for the following C# method:
public int Add(int a, int b) {
    return a + b;
}

Context: This method belongs to a class called Calculator.
Instructions: The unit test should verify that the Add method returns the correct result for different input values.
Prompt pattern: 
[TestMethod] public void TestAdd() 
{ 
int result = calculator.Add(2, 3);
 Assert.AreEqual(result, 5); 
}

Template: 
[TestMethod] 
public void TestAdd() 
{ 
    int result = calculator.Add({{input1}}, {{input2}}); 
    Assert.AreEqual(result, {{expectedResult}}); 
}

In this example, we provide the context of the method, the instructions for the unit test, and a prompt pattern that ChatGPT can learn from. We then create a template prompt that includes placeholders for the input values and expected results. By injecting the relevant inputs and expected results into the template, we can generate a highly accurate unit test that meets our requirements.

I made a Tool that can help to save time while working with prompt templating. check it out:

TechnoRahmon/TemplatingCodeGPT

How to Use the Project

The project has a page named /prompt that contains the settings of the template. On this page, you can set up the following:

  • Template Prompt: In this field, you can specify the text that you want to include in all of your prompt requests. The field should include the following placeholders:

  • {{input}}: This will be replaced by the prompt input from the home / page.

  • {{pattren}}: This will be replaced by the Pattern Prompt field.

  • {{context}}: This will be replaced by the Context Prompt field.

By setting up the text that will not change, you can focus solely on the prompt input in the home / page and save time.

Context Prompt: In this field, you can put your context text.

Pattern Prompt: This is the pattern that ChatGPT should learn from to generate the response.

The website uses local storage to save the chat list and the template settings.

We hope that you find this project useful and enjoy using it!