inv dev logo

A guide to effective prompt engineering in Gen AI Tools like Chat GPT

jonnie russell

Jonnie Russell - Invdev CTO

In this guide, we delve into the world of “Prompt Engineering” and its application in Gen AI tools, with a special focus on Chat GPT. Discover how to harness the power of Gen AI by crafting more effective prompts.

3 strategies to improve your Gen AI prompts

Strategy 1 - Use Iterative Questioning

So what happens if you don’t get the answer you expect? Well perhaps you need to adapt and tweak your questioning in order to get to a better or more relevant result.

For example the following iterative questions build upon the initial question, allowing for a more detailed and comprehensive explanation – in this case of Node.js – and subsequently deeper understanding of any topic.

Initial Question:
“Explain what Node.js is and its role in web development.”

Iterative Question 1:

“Could you elaborate on the key features of Node.js that make it well-suited for building server-side applications?”

Iterative Question 2:

“What are some popular use cases for Node.js, and can you provide examples of real-world applications that have been developed using Node.js?”

Iterative Question 3:

“How does Node.js handle asynchronous programming, and what are some best practices for writing non-blocking code in Node.js applications?”

Strategy 2 - Break Down Large Projects

Gen AI tools like Chat GPT can be incredibly useful in breaking down complex projects into manageable chunks. Using Gen AI to build a project iteratively, focusing on logical components or smaller more manageable tasks.

For example, let’s say that as part of a new Drupal website development I want to be sure that I’m following best practices when it comes to security updates and quality assurance testing. I might use Chat GPT to start breaking out these component parts using the following prompts:

“How can I secure the Drupal website against common vulnerabilities, and what is the best way to stay up-to-date with Drupal core and module updates?”

“What are the best practices for testing a Drupal website to ensure its functionality, compatibility, and performance meet industry standards?”

Strategy 3 - Contextual Understanding

Enhance your prompt engineering by providing context. The more context you provide, the more relevant and accurate the responses will be.

For example, let’s say you want to ask about the advantages of electric cars. Instead of a vague prompt like “Tell me about electric cars,” you can provide more context like this:

“Can you please explain the environmental and economic advantages of electric cars compared to traditional gasoline-powered vehicles? I’m particularly interested in understanding how electric cars contribute to reducing greenhouse gas emissions and the long-term cost savings they offer to consumers.”

In this example, the prompt specifies the topic (electric cars), the specific aspects you’re interested in (environmental and economic advantages), and the context (reducing greenhouse gas emissions and cost savings). This helps the model provide a more focused and informative response, demonstrating contextual understanding.

3 ways Gen AI tools can be used in technical development

Code Generation

Tools like GitHub Copilot and Amazon’s CodeWhisperer, which leverage Gen AI make it easier for developers to write and maintain high-quality code.

GitHub Copilot vs Amazon's CodeWhisperer

GitHub Copilot:

GitHub Copilot is an AI tool that assists developers in writing code more efficiently. It integrates with popular code editors and offers suggestions, autocompletions, and even generates code snippets based on your coding context. It can save you time and help you write code more accurately by providing context-aware recommendations as you work on your projects.

Amazon’s CodeWhisperer: 

Amazon’s CodeWhisperer is an all-encompassing code generator powered by machine learning. It offers real-time code recommendations as you write. CodeWhisperer intelligently suggests code snippets based on your existing code and comments. These personalised recommendations can range from small one-line comments to complete, fully-formed functions.

Debugging

Gen AI can assist in debugging by providing insights and suggestions for resolving coding errors to create more reliable and efficient code.

Examples include:

  • Error Identification and suggested fixes
  • Carry out deep code analysis to identify potential bottlenecks, redundant code, or areas where optimization is needed
  • Provide real-time feedback
    Generate documentation and comments to make your code more understandable to others
  • Recognise common coding patterns and flag potential issues or make suggestions based on best practices.

Learning through documentation

Using Gen AI tools like Chat GPT as a conversational tool to interact with documentation, can help developers gain a better understanding of complex concepts and find solutions to coding challenges. Here are 3 use cases:

Querying for Information: how about using Chat GPT to ask about a specific topic or problem they want to understand better? For example, “How do I use loops in Python?” or “Explain the key features of ReactJS.”

Clarifying Concepts: How about using Chat GPT to clarify or simplify complex or technical jargon? For example, “Can you explain [jargon] in simpler terms?” or “Give me an example of how [concept] works.”

Staying Updated: How about using Chat GPT to stay up-to-date with the latest updates and best practices in software development? For example, “What are the best practices for web security in 2023?”

3 Gen AI Pitfalls to overcome

Whilst Gen AI is clearly revolutionising the way we answer questions and become more efficient, it is also important to be aware of potential pitfalls.

Pitfall 1 - Don’t become over reliant on it

Avoid becoming overly reliant on Gen AI. Remember that it’s a tool, not a replacement for human expertise.

Pitfall 2 - Beware of misleading answers

Always verify solutions generated by Gen AI, as they are based on existing knowledge and may not be foolproof.

Pitfall 3 - Be careful of AI-generated code

Exercise caution when using AI-generated code. Remember that this code will have come from somewhere in the first place so it’s important to ensure it’s checked for plagiarism and that it is safe to use in the context of your project.

It all starts with the prompt

This guide offers valuable insights into how to maximise the value and power of Gen AI tools like Ghat GPT. We’ve covered a range of strategies to improving your prompt engineering and some use examples to enhance technical projects.

If you’ve got some great examples of prompt engineering you’d like to share with us, then get in touch with Invdev.