Conversation and Instructions

Tom Chant
InstructorTom Chant
Share this video with your friends

Social Share Links

Send Tweet
Published a year ago
Updated a year ago

Learn how to set up a conversation array and an instruction object as the foundation for building a chatbot. The conversation array stores all the interactions with the chatbot, ensuring a single source of truth. The instruction object specifies how the chatbot should behave and respond.

Each object in the array includes a role (like "system" or "user") and content (the instruction or inputted text). Explore the key-value pairs and their significance, and get insights on how to influence the AI's behavior. Start building your chatbot with this essential setup.

[00:00] Okay, so we need a place to store our conversation. This is going to be the single source of truth as it were, the place where everything we ask of OpenAI and everything it replies to us is stored. So I'm going to come in here and I'm going to set up a const called ConversationArray.

[00:16] In fact, I'll abbreviate array to just R. Remember, this is going to store an array because the API needs to have this conversation as an array of objects. So let's look at the first object that we need. It's the object that holds the instruction.

[00:33] This is where we tell the chatbot how we want it to behave. Now, this instruction object consists of two key value pairs, and that will be the same for all of the objects in this array. They're going to follow a similar pattern. The first key will be role, and this should correspond to the value system.

[00:52] This is just telling OpenAI that what comes next is the instruction and not part of the conversation. The second key will be content, and this should correspond to a string with an instruction. And this is your chance to influence how the AI behaves and responds.

[01:08] So I'm going to come in here and I'll set up the first object in this array. So the first key will be role, and we'll set that to the string system. And the second key will be content, and this will hold our instruction. And for now, I'm going to put something fairly mainstream.

[01:27] I've gone for, you are a highly knowledgeable assistant that is always happy to help. Now, later on in the project, when the chatbot is up and running, we will actually revisit this instruction and have some fun with it. But for now, let's keep things simple. Okay, so we've got the conversation array and the instruction object set up.

[01:45] Now, let's deal with the user's inputted text, which we'll also be adding to this conversation array. So let's come on to that next.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today