Examining the Code Output
00:00
So now it’s time to have some fun and to test your bot. So let’s see if it has access to the Code of Conduct and let’s see how it interprets those rules in that secret document. So if you have installed uv, you can use uv commands directly without having to activate your virtual environment, or you can activate your virtual environment in the usual way.
00:24
It’s up to you. I chose the latter, so I am in my virtual environment, and the command to get started is python policy_bot.py.
00:34 If you hit that, then you get a prompt to ask a question about our company policy. And I’ve just prepared a rather long prompt that I’ll just paste in for now. So I work for Steven’s Pythonistas Limited.
00:47
"Can I show off my new baseball cap in the office on Monday?" Let’s see what it comes back with. "No, you cannot wear your new baseball cap in the office on Monday." So that is interesting because the rules, as you might remember, don’t talk about baseball caps.
01:01 They talk about hats. So it does interpret the rules, and it assumes that a baseball cap is some sort of hat. Now I would like it to be a bit more specific in terms of why it’s telling you you cannot do that. So I’m going to run it again and add something to the prompt.
01:24
So the prompt as it is, but then in the end I’m going to say, "Please explain why." And then the answer should be a bit more specific. It said "No, you cannot show off your new baseball cap in the office on Monday because the company policy explicitly states that staff are not allowed to wear a hat in the office." So that, I think, is success.
01:43 And just because I’m enjoying it, I actually might try two more prompts to just try the other rules. One has to do with swearing. So I’m going to run the bot again and then paste in this other prompt about swearing.
01:57
So I work for this company. "I fear I cursed three times last week." So I’m using the word cursing here, not swearing. "Did I break any rules?" And again, let me ask why.
02:09
Hit Enter. Okay, what does it say? "Yes, you broke a rule. According to the company policy, swearing is not allowed and will result in a fine of $1 for each instance of swearing." That’s indeed what is in the policy.
02:21 Since you mentioned that you cursed three times last week, you have violated the rule against swearing as outlined in the company policy. So I think that adding please explain why does give you quite a bit more context as to what it is that you have done wrong.
02:37 Let’s try one more example. This has to do with working the weekend. So there’s a rule that says you cannot work weekends. Let’s run this again. And then I have another prompt here.
02:51
I need to finish something urgently. "Can I come into the office on Saturday? Please explain why."
02:57
"No, you are not allowed to work in the office on Saturdays according to the company policy. It works. It’s great. That’s mission accomplished.
03:05 That was the objective of the course, wasn’t it? So I could say, well, thank you. That’s it. Thank you for your attention and see you next time. But no, fear not. I am going to cram as much content as possible into this course.
03:19 And so the next logical step for you would be to introduce persisting. So that’s something that we haven’t done yet. But before you do that, it’s actually best to refactor the existing code first, which is what you will be doing in the next lesson.
Become a Member to join the conversation.
