Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Running Role-Based Messages

00:00 So to test your new and improved chatbot, please go to your terminal and enter python function_assistant.py. And when you hit enter now, you now get a prompt.

00:11 That’s the prompt you created for your user input. So describe the Python function you want help with. Now to save some time again, I’ve just copied a prompt.

00:22 And the prompt is “Please write a simple Python function to add two numbers.” And when you hit enter, it’ll go away and think, and it’ll come up with probably a very similar answer to before.

00:37 And as you can see, it now has the def add(a, b). It returns the sum of two numbers and it returns a + b. And it then gives you an example. So that’s pretty cool.

00:49 But what I’d like to do is I’d like to test to see if this introduction of the developer role is actually helping, because a developer told the chatbot to only provide Python output.

01:02 Just to show you what I mean, on lines fifteen and sixteen, there’s “You are a Python coding assistant. Only accept Python-related questions.” So of course, what I’m going to do, I’m going to ask a JavaScript question and see if I get an answer.

01:18 So back to our terminal, run the program again, we’ll get the prompt. Again, I’m going to copy and paste the prompt. So “Please write a JavaScript function to add two numbers” and see what we get now.

01:32 So the bot goes away, thinks about it, and let’s see what it comes up with.

01:39 It says “I can only help with Python-related questions.” So I’m not getting my JavaScript answer that I was hoping for, because the developer told the bot to only give Python-related answers.

01:54 So that is the power, I guess, of introducing the roles. In the next lesson, I’m going to try and be clever and see if I can break the rules that are built into your bot.

Become a Member to join the conversation.