Advanced Prompt Engineering for Coding-Related Tasks
Some coding tasks extend beyond simple, single-task initiatives. For these more complex scenarios, advanced prompt engineering techniques such as chain of thought (CoT) and chaining can be highly effective when working with large language models (LLMs). This chapter will explore how to use these techniques when working with OpenAI API, ChatGPT, and GitHub Copilot on challenges that often require more than just the initial prompt to achieve the desired output.
We will walk through an example of implementing a geometric mean calculator for portfolio returns that handles negative net returns. By applying CoT prompting, we will guide the model with explicit reasoning steps and achieve desirable results, even with a lighter model such as GPT-4o mini. Then, using chaining, we will improve the initial implementation by enhancing its type hints and refining the docstring.
This chapter covers the following topics:
- Extending...