Build

A Developers Guide to Prompt Engineering and LLMs

5 min read Sergio Munoz on Mar 14, 2024

With the rise of large language models (LLMs) and artificial intelligence like ChatGPT, developers now have incredibly powerful AI assistants that can help them code faster and be more productive. However, simply prompting an LLM to write code often results in unusable or buggy outputs. Whether you are developing a chat application, or an enterprise solution at the network edge, o speed up your development time with the help of AI you need a thoughtful strategy. Lets dive deeper into prompt engineering techniques in the next sections of this blog.

Plan Ahead

Don't just jump right into prompting for code. Take time to plan out the overall architecture, schemas, integrations, etc. This gives your AI assistant the full context it needs. Visualize the end state so your generative AI model understands the big picture.

Role play with Experts 

Set up scenarios where your AI model can act as an assistant and role play as a team of experts discussing solutions. Give them personalities and have them break down problems. This encourages creative thinking from different perspectives.

Ask GPT for Insights

If you get stuck, don't be afraid to pause and ask your LLM for specific advice or code examples relevant to your problem. Its knowledge that can spark new ideas.

Prompt Engineering 

Take it step-by-step and refine your prompts over multiple iterations and fine-tuning to provide the optimal context and steering for your AI assistant. Effective prompts lead to great results.

Manual Code Generation

Have your AI generate code manually at first, then inspect the outputs and correct mistakes before copying usable parts back into your prompt. This gives the AI a concrete example of what you are looking for and the repetitive nature of doing this will eventually generate accurate code. For more examples check out the concept chain-of-thought prompting and zero-shot-prompting.

Automatic Code Generation 

Once you're happy with the LLM model output and it’s producing consistently good code, set up pipelines to automatically generate assets based on schemas, tests based on code, etc. This removes bottlenecks.

Handle Failures Gracefully

Yes, occasional failures are expected. Improve your prompts to prevent similar failures in the future. Learn over time what types of tasks your AI handles well.

By blending planning, roleplaying, prompting, iterative training, and automation, you can achieve huge productivity gains from AI assistants like GPT. With the right strategy around designing prompts, improving your development speed is possible!

Generating Code With Prompts

As we stand on the cusp of the AI revolution, we find ourselves in a position to rethink how software development is approached and executed. This tutorial will dive into how we can navigate this transition from a traditional process to one that is supercharged by natural language processing.

Planning Ahead: The Foundation of Success

The first step in this journey is embracing the ability to plan ahead. AI, particularly models like GPT-3, may not be adept at mapping out the future. Their expertise lies in real-time problem-solving within a tight context token window. This is where human developers need to step in.

By painting a detailed picture of the final code – including model schemas, technology stack, and deployment processes – we can set the stage for AI to solve complex tasks. This planning stage might be the most challenging part of the process, but it morphs the role of developers from coders to orchestrators, setting the stage for a harmonious blend of human intelligence and AI prowess.

Assembling a Panel of Experts

Enter the "Panel of Experts". This group can comprise a diverse array of stakeholders, from C-suite executives to AI agents, all contributing to the understanding and planning of a specific task. Using a thoughtfully crafted prompt, you can create a virtual playground where the panel can discuss and resolve complex issues, with AI bots providing assistance and notes.

And if you find yourself grappling with a question, remember you have a powerful tool at your disposal designed for question answering: GPT. Whether you need a summary, a rephrase, or a more in-depth exploration of a subject, GPT can help. Being intentionally vague with your prompts can often yield surprising and innovative solutions.

Example for Code Debugging Prompt:

GPT-4 Response:

Manual Code Generation & AI

The next step is to harness GPT-4 for manual code generation, a process that promises to exponentially increase productivity. By guiding GPT, you are optimizing a variety of tasks from deploying a web application in a foreign stack to creating an algorithm in a low-level language.

Use commands on your Agents example:

GPT-4 Response:

However, the process isn't perfect. Human limitations such as copy-pasting and prompt/result generation times can create bottlenecks. Also, GPT isn't consistently accurate, sometimes changing the format or offering only partial results. But with practice and the right strategies, you can guide GPT to generate useful and accurate code.

Avoid Hallucinations and Gain Useful Results

Hallucinations, or instances where GPT generates irrelevant, bias or incorrect information, can be frustrating. However, the more you work with GPT, the better you become at steering it towards desired outputs. One way to minimize these hallucinations is to provide context to GPT by copying and pasting relevant documentation and code samples.

Build a custom Langchain agent with tests example:

Build Langchain agent tests:

GPT-4 Response:

Automated Code Generation

The real power of LLMs, however, lies in automated code generation. By using tools such as PubNub, Python, LangChain, and Streamlit, you can automate most of your workflow, leaving you to focus on more important tasks.

With a few more abstractions we can hook our simple LangChain runner into our workflow:

The Road to Developing 100X Faster

Envision a developer with a laser-focused ambition to amplify their coding skills, aspiring to attain a 2X, 3X, or even a staggering 50X productivity level. The secret to this ambition lies in the strategic application of LLMs. This toolset acts as a lever to productivity, enabling our developers to innovate new platforms and drive automated workflows like never before. From something as simple as text summarization to generating production code.

As we venture further into the sphere of AI and its role in software development, it's important to remember that the true strength lies in the fusion of human creativity with AI abilities. Thoughtful planning, the smart application of AI, and the appropriate digital tools can enable us to transform into a more productive company. This transition is about amplifying human developers' potential with AI, not replacing them. The concept of becoming a 100X company, using AI, isn't just a far-off dream but a reachable future we can shape collectively.