Practical Prompt Engineering for Dummies using NexusGenAI

Austin Starks
AI Advances
Published in
8 min readFeb 21, 2024

--

Prompt Engineering is hard. At first glance, it appears simple - just persuade the Large Language Model (LLM) to reply precisely as you desire. However, this is unexpectedly very challenging. There’s so much that goes into tuning these models that, unless you’re a highly experienced software engineer actively working in the space, it’s challenging to grasp the full extent of the intricacies involved.

Thus, I decided to write this walkthrough guide on simplifying these complex prompt engineering techniques and integrating complex workflows into your LLM applications. I hope to show two things.

  1. That advanced prompt engineering doesn’t have to be hard.
  2. To demonstrate the effects of integrating advanced prompting on the output of an LLM

While I’ll be using NexusGenAI, a next-generation LLM prompt management platform, you can follow along most of the article using open-source models or the OpenAI API.

Let’s get right to it!

Brief Overview

To demonstrate the power of advanced prompt engineering, I’m going to show how a particular prompt in NexusTrade improves by adding these techniques.

NexusTrade is an AI-Powered automated investing platform that lets users create, test, optimize, and deploy fully automated trading strategies. It’s flagship feature is an AI-Powered chat that translates plain English into different actions within the app.

The NexusTrade AI-Powered Investing Platform

As you can imagine, NexusTrade utilizes NexusGenAI for prompt management. This article will walk through the process of how I improved the “Intelligent Stock Screener” prompt using advanced prompt engineering techniques.

The Base Case – Zero-Shot Learning

Zero-shot learning is when you tell an LLM to do something and expect it to do it well on its first try. You provide explicit instructions, but no examples for the model to follow, thus testing how well the model does solely based on its original training data.

The response from the model

After outlining the steps, the model then generates a JSON that can be used to query a MongoDB database. Here are the results:

Successfully connected to cloud database server!
[] // the result of console.log(results)
austinstarks@Austins-MacBook-Pro NexusTrade %

This is not correct! Even though the model showed some basic reasoning skills, the end result was wrong.

What would make the model more accurate is if we had some examples of input/output pairs. That way, the model has an idea of how to structure the query.

Simple Prompt Engineering — Few-Shot Learning

Few Shot Learning is the ability of LLMs to learn by example.

By supplying examples, the model better understands the intricacies of how the response ought to look like. This drastically improves the output of the model for real-world problems.

The benefits of this is that it’s simple and it works well for a vast majority of problems. For example, with our new static examples, we generated a JSON that gives us this data:

Successfully connected to cloud database server!
[
{
"description": "NVIDIA Corporation provides graphics...",
"symbol": "NVDA",
"revenue": 18120000000,
"fiscalYear": 2023,
"fiscalPeriod": "Q3"
},
{
"description": "Intel Corporation designs, develops...",
"symbol": "INTC",
"revenue": 14158000000,
"fiscalYear": 2023,
"fiscalPeriod": "Q3"
},
{
"description": "Broadcom Inc. designs, develops...",
"symbol": "AVGO",
"revenue": 8876000000,
"fiscalYear": 2023,
"fiscalPeriod": "Q3"
},
{
"description": "QUALCOMM Incorporated engages in the...",
"symbol": "QCOM",
"revenue": 8451000000,
"fiscalYear": 2023,
"fiscalPeriod": "Q3"
},
// more stocks, omitted for brevity
}

While this works very well for simple examples, when it comes to prompts that are more sophisticated, the static hard-coded examples sometimes fall short. They’re also wasteful because we end up supplying a bunch of irrelevant examples that the model doesn’t need.

What if, instead of these static examples, we retrieved examples in real-time? This makes them dynamic and capable of changing depending on the user input. How can we accomplish this?

Advanced Prompt Engineering — RAG Pipeline

Retrieval Augmented Generation (RAG) is an advanced prompt engineering technique that fetches contextually relevant examples during each request to the LLM. It involves two simple steps.

1) We first must upload examples of input/output pairs to a database. We augment these examples so that it is possible to measure the similarity of between it and the examples in the database.

Uploading Examples and processing them to make it easier to query

This process is called “chunking”, and it involves splitting the documents into smaller documents and converting the text as a large list of numbers. With this new format, the document can be easily queried from a database to measure the similarity between other documents. If you want to fully understand the intricacies of this process, check out the following article.

2) Then, when we use the model, we retrieve the most relevant examples and feed it into the system prompt for each request.

This has very many concrete benefits. The responses from the model become much better because we don’t waste any tokens supplying irrelevant examples.

Additionally, this process scales well. The more high quality examples we upload to the LLM, the better the model becomes at generating responses. In other words, if we find an example that the model can’t do, we can just upload it, and the model should be able to handle similar examples in the future!

We also don’t have to worry about fine-tuning, which can be expensive and require hundreds or thousands of training examples.

Finally, with platforms like NexusGenAI, the underlying implementation can be abstracted away from the user, so that they can focus on building advanced workflows, not implementing LLM techniques.

An exercise for the reader: what are the downsides of this approach? 🤔 Comment and let me know what you think!

Combining GPT-4, Few-Shot Prompting, and RAG

Finally, by combining GPT-4, few-shot prompting, and retrieval augmented generation, we get a model that is truly capable of reasoning for highly complex user workflows.

User:
Query for semiconductor stocks that made over $2 billion in revenue in Q3 2023
and increased their profit margin every year for past the two years in a row
AI Assistant:
Given the complexity of the request, let's break down the MongoDB
aggregation pipeline into detailed steps to query for semiconductor
stocks that made over $2 billion in revenue in Q3 2023, with an increasing
profit margin for two consecutive years prior. This pipeline will also
include all relevant data for verification.
1. **Filter for Semiconductor Stocks**: Start by filtering...
// More steps

// The output of the model after executing the query against the DB.
// Some parts omitted for brevity.
[
{
"_id": "AVGO",
"description": "Broadcom Inc. designs, develops, and supplies...",
"financials": [
{
"fiscalYear": 2021,
"fiscalPeriod": "Q1",
"revenue": 6655000000,
"grossProfitMargin": 0.59384
},
{
"fiscalYear": 2021,
"fiscalPeriod": "Q2",
"revenue": 6610000000,
"grossProfitMargin": 0.61377
},
// more years for Broadcom
],
"symbol": "AVGO",
"Q3_2023_Revenue": 8876000000
},
// many more stocks, omitted for brevity
]

Basic prompt engineering will only get you so far. If you’re goal is to tackle complex problems, then you either need to learn advanced prompt engineering, or use a platform like NexusGenAI that simplifies the entire process.

Summary and Conclusion

In this article, I hoped to demystify advanced prompt engineering, and show you that it doesn’t have to be difficult. I’ve also demonstrated the concrete benefits of utilizing these techniques for a complex user workflow. NexusGenAI made the process simple by abstracting some of the more technical things away so I could focus more on the big picture.

Whether you choose to utilize NexusGenAI or not, advanced prompt engineering is very important. If you’re building a simple app that only needs to respond to a narrow range of inputs, then you can get away with using zero-shot prompting and few-shot prompting. However, as soon as you need to accomplish a complex task that requires reasoning and step-by-step thinking, you’re going to want a way to integrate your prompts with your external data sources in an easy, intuitive way.

I hope to have shown the value that NexusGenAI brings to the AI community! I’m eager to get feedback from small business owners and AI enthusiasts. As always, thank you for reading!

If you enjoyed this article, please give me some claps and share this article with a friend (or social media)! I have several newsletters you could follow. Aurora’s Insights is the perfect blog if you’re interested in artificial intelligence, machine learning, finance, investing, trading, and the intersection between these disciplines. You can also create a free account on NexusTrade to get access to a next-generation algorithmic trading platform.

🤝 Connect with me on LinkedIn

🐦 Follow me on Twitter

👨‍💻 Explore my projects on GitHub

📸 Catch me on Instagram

🎵 Dive into my TikTok

--

--

https://nexustrade.io/ Highly technical and ambitious. Building a no-code algotrading platform and an ecosystem of AI applications. https://nexusgenai.io