chapter two

2 Harnessing the power of LLMs

 

This chapter covers

  • Understanding the basics of Large Language Models (LLMs)
  • Connecting to and consuming the OpenAI API
  • Exploring and using Open Source LLMs with LM Studio
  • Prompting LLMs with prompt engineering
  • Choosing the optimal LLM for your specific needs

The term Large Language Models (LLMs) has now become a ubiquitous descriptor of a form of artificial intelligence. These LLMs have been developed using generative pretrained transformers, or GPTs. While other architectures also power LLMs, the GPT form is currently the most successful.

LLMs and GPTs are generative models. That means they are trained to generate rather than predict or classify content. To illustrate this further, consider Figure 2.1, which shows the difference between generative and predictive/classification models. Generative models create something from the input, whereas predictive and classifying models assign it.

Figure 2.1 The difference between generative and predictive models

We can further define an LLM by its constituent parts, as shown in Figure 2.2. Data represents the content used to train the model. Architecture is an attribute of the model itself, such as the number of parameters or size of the model. Models are further trained specifically to the desired use case, including chat, completions, or instruction. Finally, fine-tuning is an added feature to models that refines the input data and model training to better match a particular use case or domain.

2.1 Mastering the OpenAI API

2.1.1 Connecting to the chat completions model

2.1.2 Understanding the request and response

2.2 Exploring open-source LLMs with LM Studio

2.2.1 Installing and running LM Studio

2.2.2 Serving an LLM locally with LM Studio

2.3 Prompting LLMs with prompt engineering

2.3.1 Detailed queries

2.3.2 Adopting personas

2.3.3 Using delimiters

2.3.4 Specifying steps

2.3.5 Providing examples

2.3.6 Specifying output length

2.4 Choosing the optimal LLM for your specific needs

2.5 Exercises

2.6 Summary