April 2026
Intermediate
395 pages
13h 22m
English
This technique is one of the simplest. The idea is to provide some examples to the model, so that it can learn by imitation.
Let’s consider an example simulating a customer service AI chat system. The chatbot will be supplied with two examples and thus answer a “real” customer request based on the style and type of response that it learned. You can find the complete example code in 04_PromptEngineering\10_few_shot.py.
First, load the required packages, as shown in Listing 4.9. We’re working with ChatGroq and therefore load the corresponding class. The API key is loaded via load_dotenv.
#%% packagesfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_groq import ChatGroqfrom dotenv import load_dotenv, ...
Read now
Unlock full access