Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenAI API Cookbook

You're reading from   OpenAI API Cookbook Build intelligent applications including chatbots, virtual assistants, and content generators

Arrow left icon
Product type Paperback
Published in Mar 2024
Publisher Packt
ISBN-13 9781805121350
Length 192 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Henry Habib Henry Habib
Author Profile Icon Henry Habib
Henry Habib
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Chapter 1: Unlocking OpenAI and Setting Up Your API Playground Environment FREE CHAPTER 2. Chapter 2: OpenAI API Endpoints Explained 3. Chapter 3: Understanding Key Parameters and Their Impact on Generated Responses 4. Chapter 4: Incorporating Additional Features from the OpenAI API 5. Chapter 5: Staging the OpenAI API for Application Development 6. Chapter 6: Building Intelligent Applications with the OpenAI API 7. Chapter 7: Building Assistants with the OpenAI API 8. Index 9. Other Books You May Enjoy

Using the System Message in the OpenAI Playground

In this recipe, we will observe how modifying the System Message affects the completion response that we receive from the model. This is important because as you begin to use the OpenAI API, you will likely adjust and refine the System Message to your specific needs, and the Playground is a great way to try that.

How to do it…

  1. Navigate to the OpenAI Playground.
  2. In the SYSTEM field, type in the following: You are an assistant that creates engaging and professional company names based on descriptions of companies.
  3. In the Chat Log, populate the USER message with the following: A company that helps you with your taxes.
  4. Select the Submit button on the bottom of the page.
  5. You should now see a completion response from OpenAI. In my case in Figure 1.3, the response is as follows:
    TaxGuardian.
Figure 1.3 – The OpenAI Playground with prompt and completion

Figure 1.3 – The OpenAI Playground with prompt and completion

  1. Hover over the ASSISTANT response and select the minus icon on the right-hand side to delete the model’s response from the Chat Log. This needs to be done because we want OpenAI to not only generate a response but generate one as the ASSISTANT.
  2. Modify the System Message to You are an assistant that creates potential customer segments and marketing strategies based on descriptions of companies.
  3. Select the Submit button on the bottom of the page.
  4. You should now see a much longer completion response from OpenAI. In my case, as shown in Figure 1.4, the response details potential customer segments:
Figure 1.4 – The OpenAI Playground response after modifying the System Message

Figure 1.4 – The OpenAI Playground response after modifying the System Message

How it works…

The model generates a completely different type of response after modifying the System Message, even though the prompt in the Chat Log is exactly the same. The response changed from a one-word answer to a multi-paragraph response because of the instructions from the System Message. We also had to remove the default Assistant response because we want OpenAI to generate its own response instead of feeding it a response.

The System Message, being the first message in the conversation, heavily influences the thinking of the model by providing a frame of reference or context. This context is crucial because, without it, the model would lack necessary guidance to respond appropriately to subsequent user inputs. It is the cornerstone of defining your interaction with the model, allowing you to provide important context and high-level directives that steer the conversation or task at hand.

As a result, when we begin to use the OpenAI API to create business applications, careful considerations must be made to the instructions that we put into the System Message.

There’s more…

The beauty of the System Message is that that you can be as simple or as intricate with your instructions as you want. For example, here are common system messages that can be used for various purposes:

  • You are an assistant that helps young students learn important concepts in science by explaining concepts in easy-to-understand language
  • You are an assistant that creates marketing slogans based on descriptions of companies that are provided to you
  • I am planning a birthday party 2 weeks from now for my 5 year old niece and you are my party planner that tells me what I should be doing
You have been reading a chapter from
OpenAI API Cookbook
Published in: Mar 2024
Publisher: Packt
ISBN-13: 9781805121350
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image