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

In the last chapter, we reviewed the need for various agents and assistants, their components, and the tools used to build them. This chapter starts with the basics of connecting to LLMs, using open-source LLMs, and choosing the right LLMs for your needs. In the next section, we look at the fundamentals of LLMs.

2.1 Understanding the fundamentals of Large Language Models (LLMs)

The term Large Language Models (LLMs) has now become a ubiquitous descriptor of a form of artificial intelligence. These LLMs have been developed using a system called 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

2.2 Mastering the OpenAI API

2.2.1 Connecting to the chat completions model

2.2.2 Understanding the Request and Response

2.3 Exploring open-source LLMs with LM Studio

2.3.1 Installing and running LM Studio

2.3.2 Serving an LLM locally with LM Studio

2.4 Prompting LLMs with prompt engineering

2.4.1 Detailed queries

2.4.2 Adopting personas

2.4.3 Using delimiters

2.4.4 Specifying steps

2.4.5 Providing examples

2.4.6 Specifying output length

2.5 Choosing the optimal LLM for your specific needs

2.6 Exercises

2.7 Summary

sitemap