AI Agents in Action cover
welcome to this free extract from
an online version of the Manning book.
to read more
or

2 Harnessing the power of large language models

 

This chapter covers

  • Understanding the basics of 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 AI. These LLMs have been developed using generative pretrained transformers (GPTs). While other architectures also power LLMs, the GPT form is currently the most successful.

LLMs and GPTs are generative models, which 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 classify it.

Figure 2.1 The difference between generative and predictive models
figure

We can further define an LLM by its constituent parts, as shown in figure 2.2. In this diagram, data represents the content used to train the model, and 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 a feature added 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 Creating detailed queries

2.3.2 Adopting personas

2.3.3 Using delimiters

2.3.4 Specifying steps

2.3.5 Providing examples