Transcription
So, as you know, AI is affecting the world quite a bit. Uh, especially the tech industry and especially cyber security. We're just able to do much more with much less these days. And the result of that, it's kind of raising the bar and then increasing the barrier to entry to get into cyber security, especially for future jobs. You're not only going to have to know those security things and like personal network and all that, but you're going to have to know how to like leverage AI on top of that to be effective at your job and get hired and like maintain your position for future roles. And it's my mission to try to help everybody stay ahead of the curve as much as possible and introduce things that will be useful for your future interviews and future jobs and all that stuff.
So this course, we're basically going to build a cyber security agentic AI, like an AI sock analyst that does like threat hunting and can like take action and stuff like this. But in order to do that, we need to build up our foundation. Uh, so this course is going to be in three parts. The first part being the basics of Python. So you can do this like even if you have zero programming experience, like anyone can start doing this. And then the second part of the course is going to be using Python to uh interact with the OpenAI API, cuz this is going to be heavily leveraged when we actually build the agent in the third part of the course.
So after completing the course, um, not only going to be able to build an agentic AI, like an AI sock analyst, you're going to have a really good understanding of how LLM APIs function and how to interact with them. And this will open up a literal world of possibilities for you. Like once you know how to program and you understand how APIs work and you understand how to interact with uh the API for like Chat GPT, for instance, you can do like a lot of stuff. And the future of cyber security is very likely going to include some kind of orchestration of agentic AI's, like orchestration of like AI sock analysts. Another way you can think about it, and going through this course and doing everything will give you a really good understanding of how an AI agent might think and make decisions and how it interacts with a model and everything like that. Like the purpose of this course is not to like, you know, be able to like build an agentic AI and like go and like sell the product or something, cuz what we're making is like relatively simple. Rather, it's to help you understand how everything works and give you a good mental foundation and expand your mind, basically.
And this course was originally created for the Cyber Range, my community. It's a long series of like many different videos, and we just stitched them together and put it on YouTube. And eventually, you'll get to a point where you need to have access to the organic uh log database from the Cyber Range, cuz a lot of organic and attack traffic gets put in there. And then we're going to use that uh log repository to do threat hunting and that type of stuff. But you'll be able to get through like seven hours of the course and like learn how to use the OpenAI API and like all the stuff before we even get to there. But when we get to that point, um, you just need access to the Cyber Range in order to use the logs. But if you want, I can provide um some like sample, like real logs, but I'll provide them in samples for you that you can use with your code. But I recommend joining the Cyber Range anyway. Uh, the community support is basically unparalleled, and it's a really, really high-quality environment with enterprise tools and a nice production platform. It's just really, really good.
And all the links and everything you need and like bookmarks and stuff are down below. Like when we start getting to the actual like interacting with the OpenAI API, you're going to have to be using like different code, and I'm just going to provide all those down below in some links. And a quick note before we actually get into the course, I'm going to give you a quick demo of the agent in action, like the cyber security agentic AI agent, and it might look like a bit intimidating because there's a lot of code and stuff, but eventually, when we get through the course and like learn all this stuff, it will look a lot less intimidating and it will make a lot more sense. But when you're watching the demo, just try to make sense of it and just try to understand it at a superficial level and like understand what I'm saying. And of course, if you have questions, just ask in the comments. I'll do my best to answer them. But again, uh, I spend most of my time in the community, and I dedicate like a few hours a day just to answering community posts in there. So if you, if you join the Cyber Range, like instead of leaving YouTube comments, just like leave a comment in the Cyber Range and tag me, and I'll, I'll like definitely respond to it, or one of the staff will respond. Don't stress. Just do your best to absorb things and work through it slowly, and you'll get to the end. Just be consistent. Yeah. Best of luck. Ask any questions if you get stuck, and we will see you in the next video.
Hey everybody, welcome to the Agentic Cyber Security AI and Python course. Um, if you didn't already know, Agentic AI is just like an AI agent that can do something and then take some kind of action on its own with minimal or no uh input from humans. And if you mix cyber security into that, you get an agentic cyber security AI. And then you can imagine things like um automatically remediating something that it found, like maybe isolating a virtual machine based on logs that it analyzed, or like remediating some vulnerability, or like turning off a VM, notifying somebody. Like the AI can actually like do something beyond just some kind of analysis. So in this course, we're going to build an agent that can do that stuff.
And the reality is, with all the advent of the crazy AI and GPT and like all this stuff that's coming out these days, it's getting really, really good. And you know, like businesses want to min-max and like save as much money as possible and like make money and all this stuff. So of course, they're going to try to automate away as much as they can. And what this means for cyber security is, for sure, a lot of those like low-end, like what you know now as those like tier one sock analyst jobs, that that's definitely going to get automated away eventually. It's not going to be like today or maybe even this year, but um, as people adopt AI more, those like entry-level jobs are going to kind of go away. And um, it's going to create new other positions that heavily leverage AI, um, AI agents to do those kind of cyber security operations things. It's kind of raising the bar in cyber security. You can think about it that way. Like the lower-end jobs are going to kind of go away, and then there's going to be other jobs that are like engineering the agents, like orchestrating the sock, orchestrating the agents, like fine-tuning them and stuff like this. So, we kind of have to like build on top of the foundation we already have and like learn these new uh AI-related skills.
And the whole reason for making this course is I just want people to get ahead of it. Like I don't want the jobs to like start going away in like, you know, 2027 or whatever, and then people are like, "Oh, I have to like learn how to deal with cyber security agents at that time." It's better to just like do it now. So we're going to build one from scratch, and then we're going to learn the inner workings of it and everything. So by the time, like even now, like when you start interviewing, it's going to be really, really strong. Um, when it comes to like your resume and like during the interview, you're what you're going to be able to talk about is going to look really, really good. But by the time we have to start actually like using these like fully developed SAS applications that use AI agents, um, you'll have like a really good idea and a good intuition for how those work. So you should be like, you know, much better off than the average person who's like not doing anything about it yet.
In the next video, I'm going to show you a demo of the thing that we're actually going to build. Um, I'll probably update that video, you know, as we build out the agent, but basically, um, it's an AI sock analyst agent. It will take a prompt from a user, decide where to search for the data, collect and analyze the logs, hunt for potential threats, generate a report, and then take some kind of action based on its findings. And you'll see like what I mean by like the level one sock analyst positions are eventually going to go away because the agent, um, if it's built correctly, it functions at like 3 to 500 times the speed as a human does.
And the way this course is structured, um, there's going to be kind of maybe three main sections. The first section is just uh Python fundamentals. It's not really related to AI or anything, but we we're going to be using Python quite a bit. And I'm not going to teach it in the sense that I just like cover all the theory. I'm going to cover it um in a way to kind of help you understand the specific components of Python that we need when we actually go to build the agent. And the second portion of the course, uh, Python plus AI basics, um, we talk about how to combine Python with AI tools and different APIs, like how to use Python and interact with the Chat GPT API, and how to use Python to interact with like our log analytics workspace and and this type of stuff, the next level building blocks to build the AI agent. And then the third part of the course, um, we're going to actually put everything together and then build our own intelligent um AI sock analyst that can actually do the threat hunting and like do those autonomous actions.
And then the requirements for this course, um, as of right now, uh, everybody needs to have their own OpenAI account. Uh, it's not really expensive. Um, we'll kind of cover that later, but we need to use the Chat GPT API. So we have to like register that account. It's relatively cheap and um, it's kind of like pay as you go. The second thing is, um, you need to, or rather, I highly recommend you have completed the Security Operations course inside the Cyber Range, because it kind of provides you that foundation, that threat hunting security operations foundation, where we go over the logs and like learn how to use KQL and like all that stuff, cuz we're going to build on top of that. And then the third thing you need is access to the Cyber Range. Um, the reason for this is there's like a ton of organic traffic and logs inside of there that we're going to use to actually build our agent with. So, it's important to have these three things. Yeah, welcome to the course. We'll see you in the next video.
Welcome back and welcome to the introduction to Chat GPT. And I just wanted to make this video real quick in case people like didn't know what Chat GPT was or someone who has like heard about it or maybe you haven't used it yet. Basically, you can use it for free. Um, I think you might have to sign up for it in order to like send more than X number of messages to it, but you can sign up to it for free and just kind of like use it with this demo if you want. Just go to chat.openai.com. But the best way to think about this is like a super hyper intelligent alien that you're having a conversation with that happens to know all about humanity. Basically, don't use it like it's Google. You can say like full-on sentences to it. For example, like, um, "Give me a, you know, carrot cake recipe for my son's only parents' birthday. They are allergic to gluten. I'm I'm spelling stuff wrong, but it doesn't matter cuz it's really smart. Gluten flour, and they are a hyper militant vegan. They like the color white when it comes to food." You you can say like crazy stuff like this, like all kinds of things. Um, and it will it will give you a decent recipe, and this probably, especially with the latest versions of GPT, this will probably end up being pretty good if you were to cook it. Say this is like too long for example, you can you can say something like, "Okay, that's too many ingredients, whatever." And then it will it will simplify it a bit for you. You can pretty much change the way it communicates with you. Like you can say, "Even if you're like learning English for the, you know, it's not your first language, you can say, [snorts] like, uh, I'm ESL, I'm an English second language learner, whatever. Can you use a bit easier English for?" Okay. And then it will it will do it, right? And you can say like, you know, "Please put this in table format and make it easier to understand still," and it will do it.
This is called like prompt engineering, uh, where you you craft, oh, by the way, okay, the the thing that you send to Chat GPT, this message, this is called a prompt. And then prompt engineering is when you craft this message you send to GPT in a certain way where it, you know, in I don't I don't want to say entices, but it gets GPT to respond to you in like a certain format. Like, for example, um, our prompts resulted in like easier English, like a shorter recipe with less ingredients, and then in table format, basically. So you can say things like, you know, "Explain photosynthesis in simple terms," or like, "Explain something in an easy-to-understand way." "Explain like I'm five," like, "Explain how an uh atom bomb works as if I'm three years old." It's going to say something ridiculous. I don't know if a three-year-old can understand this, but you kind of like get the idea, right?
And if you want to do something like really, really specific, like you have a question about the law, you can say something like, "Okay, now you are a lawyer, whatever, who specializes. I'm spelling stuff wrong, but whatever. Specializes in uh, whatever. I don't know if this is a thing. Housing law in Washington State. My landlord is not fixing the mold, the mold for and weeks. Which RFCs are they violating?" Can you do something like this, right? And it has like a big, big model, big brain model with like it's been trained on like pretty much everything on the internet, basically. So it it pretty much like knows everything, right? And then you can ask it stuff. You can give it context for like how you want it to think and how you want it to respond, and you can ask it like all kinds of like arbitrary stuff like this. You can even say something like, cuz it knows about the internet and it knows about like people on the internet, and it can also search the internet. I think the free one can do this. I'm not really sure, but you can say like, um, "Okay, like I just bought a service from Josh Mator. What are the chances that I'm left feeling disappointed? Please give me a straightforward answer based in reality." I don't know what this is going to say. I assume it's going to say something like good, because uh, I try not to make bad stuff. Well, if you don't know, then go out and search. Well, it did say something. Let me see. "I don't have specific personal knowledge of reviews." It's telling me to like check reviews. Shut up. You do it. It It can go out and do it for you. And it did. It checked like Reddit, and apparently what else? Course Report. Reddit, YouTube, Course Report. Uh, and it said, "Based on the available information." Um, I'm not going to read this. I'm just going to include it in the dictionary in the video. I don't like reading like too many texts, but you kind of like can get the idea. Order the YouTube. Okay. Out of all the YouTubers, which are most likely to scam you? And sometimes, um, okay, I'll say, "Order them 1 through 10." Sometimes it will answer stuff like this, but sometimes if it's like too unethical or like it's like, "I don't want to smear anyone," it it like won't answer, right? So, you can some kind of like you can sometimes bait it into answering stuff. Um, if you're trying to like, you frame it in a certain way, like, "I'm trying to like figure out the best thing for my son to watch," or something like this, you can bait it into doing stuff.
But basically, um, I just want to like introduce Chat GPT as a hyper smart, you know, super intelligent alien that will do all kinds of stuff. And you can, the more context you give it for what you want it to do, like the better an answer it's going to formulate for you. So, we're actually going to use this to help us with threat hunting, but we're not going to like paste stuff in here like this. We're going to use it programmatically on the back end. So, for example, what this look like, what this might look like is we're going to eventually say something like, you know, "You are a cyber threat hunter. You are really smart and know everything, whatever." And then we can, we're going to say something like, "Uh, I suspect X Y Z might have happened, but I'm really not sure." And then we're going to say, "Like, here are the logs." And then we're going to send like, uh, you know, a bunch of logs in here, like a ton of logs after this. And then GPT is going to read this to get the context of like what we want to do. And then it's going to look at all the logs and it's going to take like, you know, a minute or 30 seconds or whatever to like analyze them and threat hunt. And it's going to come up with like a bunch of, you know, recommendations and stuff that it found. Basically, is the idea of how we're going to use it. It's not exactly like that. It's a bit more like fine-tuned and nuanced, but that's the general idea. We're using this like magical black box hyper intelligent alien as GPT, and then we're just like prompt engineering and crafting it and giving it perfect, not perfect, but really good context for what we want to do, and then we're going to take the output and then do some kind of like actionable uh remediations with it, like isolating VMs, etc.
So yeah, let's Chat GPT. There's like there's like a lot that goes into this, and there's a lot of videos on YouTube on like how to use it and stuff. But I just wanted to give this like brief introduction about it in case there was people who like didn't know what it is or didn't really know how to use it. But yeah, we will see you in the next video.
Welcome to the AI Sock Analyst Agent Demo. I'm just going to kind of show you what it is right now and then give you a sense for what we're actually going to be building. Likely by the time you get to this, this thing is going to be built out even more. But I'm just going to show you the functionality as it is uh right now today. And again, this course is actually designed for people who are already inside the Cyber Range. Um, so I'm going to reference stuff that they should know about already, but I'll kind of explain about it um as we go.
But before we actually launch this, I just want to show you something really quick just so you have like context or some idea. Basically, inside the Cyber Range, um, there's like a lot of traffic and a lot of like organic logs and stuff being created, and there's a lot of different tables where the different logs are being stored. So, for example, like audit logs is like if you update an account in Azure Active Directory, like you assign permissions to it, delete it, or something. Azure activities when you like create virtual machines, or create or remove or delete any kind of resource in the portal. Um, sign-in logs is when you like actually go to sign into Azure. All those kind of related activities get put in there. Syslog is like um Linux servers and stuff like this, like Linux virtual machines, Ubuntu virtual machines, and there's just a ton of different tables in here, and they're all like filled with organic, like actual traffic from users. There's about a thousand users on here, and then a lot of the virtual machines and servers are intentionally exposed to the internet. So they they get like a lot of organic uh attack traffic from malicious bots and bad actors. So I just want to like give you a sense for what uh is on the back end. And Cyber Range members, of course, you have like access to all this, and this is what we're going to actually use to uh build our agent. So we need some kind of like logs to do analysis on.
So, uh, getting right into the demonstration. Um, I'm not going to like explain all this code right now. All of this is something that's going to be covered eventually, but I'm just going to do a quick demo for you. So, I'm going to run this. I'll just say start debugging. And you get like a message down here for what you want to do. And by the way, this can be made into a web UI, but I'm just using on the command line for now for sake of simplicity. So, the agent that we're building, it's asking like, um, "Sock analyst at your service, what would you like to do?" And you can say something like, uh, "I saw on the news yesterday there was a there was a new utility for uh enumerating enumerating and gathering whatever, gathering information from Azure tenants. Azure tenants, this is just our cloud environment. Uh, we are a bit worried that our environment might be compromised. Anything in the last day or so that you can find, please help ASAP." You can The idea is you give it some kind of like human sentence like this.
And then I'm just going to pause the code and then just run through it. Um, I'm not going to let it just go. I'm just going to I'm just going to step through the code so we can kind of slowly see what the AI agent is doing. So it's right now it's looking at our English sentence and then it's using uh GPT endpoint to decide the log search parameters uh based on the user request. So it's it's trying to figure out which tables we need to look in. So, for example, do we need to look in audit logs or like operation logs or Syslog or like where do we need to look, uh, where do we need to start our search? And it finished. It decided it needs to look in the sign-in logs and it gave a time range of the last 36 hours, and it's going to look at these fields specifically. It decided all this based on our user input and the rationale for it. You can kind of read this, the rationale for its decision: "Hunting for potential Azure tenant enumeration via cloud sign-ins and app uses." And it says, "This table, the sign-in logs, shows XYZ blah blah blah." So that's why we're going to look there.
So we can keep stepping through this. It built this KQL query. If you've gone through like the Security Operations course, um, this will make a lot of sense to you. But I'll copy this for example. Now, if I go to Log Analytics, this is the query it made. So, if I search this, this should be like last 36 hours, but that's okay. It it's going to find a bunch of logs. It looks something like this. And then it's going to use these logs to do its threat hunting and analysis. It returned 1167 records from the query. It's going to build threat hunting prompt instructions based on the logs it found. It's going to select an adequate and appropriate model. It's going to count up the number of tokens. You'll learn what this means when we actually get into the course. Um, because not every model can handle like, you know, they handle different number of tokens and data. Like if it's too much, we have to use like a different model potentially. Uh, agent determined that the token amount was safe. It's within the budget for GPT-5. And then it's going to start the threat hunt. I'll just press continue. And this is the part that is like 3 to 500 times faster than like a human sock analyst. So I'll let this go. I'll run this threat one more time or this threat hunt one more time, but for like some other different scenario. But this time I'll just like let it go all the way through so you can like get a good sense for the speed of it.
And while this while this is going, uh, by the way, like the Python courses, like the fundamentals, the building blocks, etc. All of those courses are designed to like help us make sense of all the stuff that's inside of here. And the whole goal of this is to give everyone a really good intuition how this works. And then my hope is that you'll be able to build on top of it and extend it, like extend functionality, and then be able to kind of do your own thing. Cuz if you really understand how this works and you're able to talk about it in interviews and articulate it like in your profile and stuff, you're going to be like way ahead of way ahead of the average person who just like went through Google Cyber Security or got Security Plus or something, or like even the bachelor's degree, right? Like a traditional one. You're going to be able to like apply this kind of thing to the real world and like talk about it, and it's going to it's going to look really, really good.
So, the threat hunt is happening right now. Usually, this takes like 1 to 2 minutes. So, it finished. I'll let this continue. It found, uh, it took about a minute and a about a minute and a half, and it found three potential threats. So, we'll press enter. I don't know what these are going to, and then I paused the code at the very last end, or the very last line. So we can kind of take a look at what these threats are. So, first one: "Likely account compromise, sustained successful login from Kazakhstan with 10 account reconnaissance confidence level high." And it kind of explains what it found in the actual, this is a Cyra user account, like an actual one, actual IP from Kazakhstan, and it kind of explains what it found. Uh, it includes confidence level, MITRE ATT&CK information, um, which is tactics, techniques, and procedures. The very specific log lines that it thought the compromise, that that it counted, that it considered indicators of compromise. Um, it has indicators of compromise here. This is probably a better word, a better name for this is probably like malicious entities or something, and then tags and recommendations: "Create incident, pivot, monitor," and then some more information.
Then threat number two: "External Gmail account sign-ins to Azure portal from Japan, verify guest access." This is interesting. Um, it categorized it as a medium. And this is actually me because I'm in Japan right now. I'm not in Fukuoka, but the ISP like probably is. But it just noticed something like interesting because it knows like the the tenant is a Login Pacific tenant. Um, but it recognized me logging in from like outside of the US with a non-Login Pacific account. So, it flagged it as medium. You can kind of read the through these uh description in the IOCs and stuff if you want.
Then the last one: "Idle sign-in from hosting VPN IP with multiple MFA challenges then success." So, you can kind of read about this. It just was probably something that it considered unusual of what happened. It's probably not malicious. I'd have to look into this more. Um, but yeah, it was able to like browse through all of those, create this report, um, and figure all this stuff out in like 2 and 1/2 minutes. And that's like significantly faster than a human, right? So, I'll let this program finish. Uh, I'm going to run this again without debugging this time. I'll just like let it run all the way through. And then for my new prompt, maybe I'll say something like, uh, um, "I think um some maybe malicious traffic has gotten past the firewall today. At least, you know, the last 8 hours or so. I'm not really sure. I'm thinking this because uh an intern disabled some of the firewall rules. I don't know. I'm just like literally making this up." So, if I say enter, it will take the prompt. Will decide which logs to look for, like which table to look at, and which logs to pull. Usually takes a few seconds. It decided to look in the Azure Networks Analytics CL table. The rationale: it created a query. It returned a lot of records, and then actually, um, the er, it had an error. Uh, this is built into the program, so this is like pretty good. So basically, like the agent saw that like, "Oh, the tokens, the amount of logs that got returned is too much to feed into the Chat GPT agent all at once because the estimated tokens is, you know, 345k, where GPT-5 can only handle 72,000 for example." And then normally I would like build into this application or into the agent like, "Oh, if you exceed too many tokens, exceed what this model can handle, maybe use a different model." Right? We can build that functionality in. But instead, I'm just going to like manually set the default model to GPT-4.1 um, because I didn't build that into it yet. So we'll just like run this. We'll debug it again. Actually, I'm going to take, uh, I'm going to take the same prompt. So, and then I'll just like simply run this without debugging again. Same thing, but I switched the model to use GPT-4.1. And you see how fast like GPT-4.1 is compared to GPT-5. It's GPT-4.1 is like way faster, and it can take more tokens, but I think its analysis is a bit slower because it takes time to like, you know, quote, make sure of its findings. So that's that's what's happening right now.
So basically, it chose this table to look based on my prompt of like, you know, the firewall rules being disabled. Chose this table, created this, this is the KQL it query, it this is the KQL query it created. So if we copy this for example, we go to Azure, we can search this, and these are the logs that it's going to actually look at. Like these are like the firewall logs, most flow, destination IP, source port, the VM, allowed inflows, etc. And it's going to analyze, take all these, and then see, uh, what I can figure out. The GPT-4.1 selected, calculating the tokens, 300K out of a possible million, so it's about like, you know, a third of the max. And then it took 40, only 40 seconds, and it found three potential threats. So we can say enter, and we can look at the threats it found. That was like, it's really fast, right? So, the first threat: "Mass lateral movement and potential command and control exfiltration activity across multiple VMs." This is pro, this is probably legit happening inside the Cyra range because it's designed to allow this kind of activity for exactly these scenarios where we can do threat hunts with it. It talks about the MITRE ATT&CK info, tactics, techniques, actual logs, or some of the logs. There's like a lot. It says like hundreds of similar lines. Um, how it discovered like how it came to the conclusion that this was a malicious activity. Um, some of the entities involved in it. Um, some tags. C2 means command and control, um, recommendations, etc.
Uh, threat number two: "Unusual denied flows to public IPs, potential external communication attempts." So it found like a lot of probably a lot of blocked outbound flows. I'm not sure. I'm not going to read all of this. You can you can read it if you want.
And then third one: "Confidence level high, high volume of repeated SSH, RDP, and legacy protocol traffic." Um, this is probably legit. It's probably either people trying to attack inbound or stuff that got breached inside of the Cyber Range trying to attack outbound. Um, I can spend more time to look at this if I want. This one's likely legit.
And then eventually, uh, this is relatively trivial to do, um, compared to the rest of it. But we can do things like we can put logic in our agent where like, uh, if the user query is about a specific virtual machine and there was findings and the confidence is high, then we can like create a firewall rule, uh, isolate the virtual machine, shut it down, create a report, like all this kind of stuff. That's where like the agentic part of agentic AI comes from. Like it can actually take action based on the stuff that it found. And that's what we're going to build out and get into. And then again, my hope is people will get a sense for how this works and they'll be able to build out their own custom actions, uh, that their AI agent can do. But yeah, we'll see you in the next video.
Welcome back. In this lesson, I just want to talk about the objective of the Python course. So basically, um, the purpose of this course is I just wanted to help you to build your skill up enough to be able to recognize what some code does and then potentially like augment it and like edit it to get it to do uh what you want to do. I'm not trying to turn everybody into a bunch of like Google software engineers or anything like this. Um, I just want you to like get your coding skill up enough to where you can recognize things and then you can understand the output that Chat GPT gives you when you when you ask it stuff, and then you can make the necessary changes to your code. Um, no doubt we're going to deep dive into all the code, and I'm going to explain literally what everything does. But basically, these are these are the levels of coding, uh, in my opinion, that people can be at. Um, like level zero up to three is kind of what I hope for for you guys watching this. So like level zero just means like no coding school, like literally zero knowledge. Like imagine like your great-grandmother or something like this has like literally no idea. And then level one is code literacy. Like you can kind of read and understand what basic code does. You can figure it out, like maybe just by by looking at it. Um, level two is code modification. Like you can modify an existing script to fit your needs. Like, for example, maybe you want to use like, you know, GPT model like 5.0 instead of 4.1, or GPT-5, I guess it's called, instead of 4.1. You can be like, "Okay, like I found it. I'm going to like adjust it and then make it work." And then level three is basic coding, where you can write relatively like simple code, um, from scratch, and you can automate everyday tasks, and you don't have to rely on like GPT for those basic things like loops and conditionals and flow control and stuff like this. If you can get to level three, um, from the following lessons, that's like more than enough to be to do like, you know, pretty decent and produce something of value, right? Especially when it comes to like doing interviews and like creating a nice portfolio and stuff.
And the higher level your coding is, the more you're going to be able to leverage GPT. So, this makes sense, right? Somebody who has like level zero coding, they can type something into GPT like, "Make a web page for me," and it it will make it, right? But the person doesn't know, like they don't know how to like extend it or edit it or like literally do anything. And like the higher you go down this like skills list toward level seven, like the more useful GPT is going to be for you in terms of like generating code and like being being able to edit it and um, identify when GPT like messes up. So your goal is to get to level three. Um, don't, as we're going through the tutorials and stuff, don't feel bad if you're like, "There's no way I could produce this on my own." Like, you're that's not the goal. Um, right? The goal is to like at least get to level three. You have like a basic understanding. You can write basic stuff on your own. And then when GPT produces something, at least you have enough like knowledge to be able to like kind of identify it and ask the right questions.
And coding is just basically like moving around data. It's just like creating, reading, updating, and like deleting or getting rid of stuff. You don't have to think about it like in too much depth. It's just moving around data to to do what you want to do from like a business standpoint or like, you know, whatever it is you're trying to do. And I don't want you to like uh get stressed out and try to memorize syntax and like memorize stuff. That's a good way to like stress yourself out. And cuz I I don't memorize anything, but you you will accidentally memorize stuff if you do it enough. But the goal is to try to understand what's going on and understand the logic behind the code, and I'll try to do a really good job of explaining it and like stepping through the code and everything. So don't worry about it too much. Just work on understanding and just try to understand what we're talking about. And yeah, nobody nobody knows everything, right? I don't I don't know like hardly anything, to be honest. I'm like comfortable enough to know that I can figure stuff out. So I I just kind of hope other people can get to that level.
And you'll likely feel overwhelmed at some point. Um, because it's like it is a lot. But it's not like the more you practice, the dumber you're going to get. This doesn't make sense, right? Like the more you expose yourself to it with intent, and the more you focus, and just the more time and effort you spend on it, you it's just going to make you that much better over time. And everyone struggles with coding. Like everyone does. Like even me, I quit comp sci the first time I was in it. But just I didn't have like the tools and mindset I have today. So just don't give up and leverage the forum, like the community section a lot. Uh, leverage Chat GPT, and just keep trying, and you you'll come out better. You'll come out uh better for it.
And yeah, finally, I just want to say like leverage the community heav he heavily. Like if you're in the Cyber Range or Cyber community, um, go to like the community section and make posts, and then if you want me to see it, just like tag me. Um, don't DM me directly about code. I I literally like know if not to be like mean or anything, but I won't answer it if you DM me about code because it's not scalable, and a lot of people are going to be like asking questions. So please use the community, cuz when you do that, it will give you like reputation points, and it will give other people like a chance to understand what's going on and like answer questions, um, because there's that internship component, right? If you provide technical help or a technical solution, you can get points for it if you're doing the internship. So, um, use the community a lot. Don't DM me about code. Um, just you can DM me still, like DM me. Um, but just make sure it's about stuff that's like, you know, it can't be answered in the community. It's like something specific to me. Um, yeah, I hope to get to the point eventually where I can just go to the community and just like spend a long like block of time answering questions. Um, but if it's not me, like somebody else will will get to it eventually. But yeah, um, don't stress out. Remember, we're just like shooting for level three, and just do your best and keep going. And we'll see you in the next lesson.
Welcome to the first video where we're actually going to be doing stuff. Uh, we're going to be setting up our environment uh where we're going to be doing all of our Python development and stuff in. And I'm going to be doing this uh in a Windows PC cuz I I think most people have Windows. I'm not sure. But um, everything we're doing in here um, you can do it uh in Mac as well. It's a pretty similar process. For stuff where you get stuck, you know, just use Google, Chat GPT, or of course um use the Cyber Range or Cyber community forum to ask questions. But I'm just going to get right into it.
So, first thing we're going to do, uh, is install Python. This is like a brand new computer, so it's going to like probably ask me a bunch of questions. So, okay. So, we just go to Google and we can not what I wanted, but we'll just go download Python and editor. Uh, who who'ever editing this, just cut this out. We'll go to download Python, and you can just uh, there should be a button here that says like, whatever the latest one is. Um, just go ahead and get the latest one. Probably won't have any much problems in the future if the version changes. And we'll just open this and then just wait before you like click through everything and install it. So, we're going to check this like, "Add to the path," and then go ahead and like check this as well. And then just say install. And we'll just let it Huh? And we'll close this.
And then next, we're going to install VS Code. So go to Google again, or you can use Bing if you want. VS Code, and then I'm going to get it for Windows. If you're using Mac, you know, if you have like an M1 Mac, um, well, just do your best to figure it out. I'm not going to get into that, but if you're running Windows, just download Windows, and it should download automatically. I'm going just open it when it's done. I'm going to say okay. And then I'm going to mute my system volume. We don't hear that again. Accept. And then just install this with the defaults is fine. And then create a desktop icon. And then add these things as well. It's not the end of the world if you don't do it, but but we will let it install. This is our development environment. So like the thing, uh, the program that we're going to actually write the Python code in, that's what VS Code is. And we can say launch VS Code. Sure. Then we can close the internet, whatever, Edge at this point. And then VS Code opens.
And then before we do anything, let's just create a folder on our desktop. We'll call it code, a new folder, and we will rename this to code. So I'll just name my code. And then inside VS Code here, and maximize this, and we can say, we can either say file and then open folder, or you can click these two pages here, and you can say open folder here, and then we'll browse to our desktop, and then we'll open the code folder, and then say select folder. And then we can see on the left our folder is over. Uh, just I trust this if you get this popup. And then we see our code folder here, but there's nothing in it yet.
So first thing we're going to do, we're going to install some plugins. Um, we're going to install the Python plugin first, or extension, I guess it's called, um, which will allow us to easily run Python code inside of VS Code. So click extensions, and then just search Python, and then install. You should see it should have like 178 million installs. So, just click install. We'll just wait a bit for it to finish. I'm going to close this thing, if you have it open. Cool. So, that thing installed. And then the next extension, um, just open extensions if you closed it, and search for the word black, and then there should be like a black formatter, uh, by Microsoft. This it should have this badge, and then go ahead and install this. This thing is going to like let us um, be
able to format you. This won't make sense yet, but it will let us format JSON code in a way that's like easily readable. And um it's really, really useful to have. So just go ahead and install this black formatter. And we can close this. And um I'm just going to close VS Code and then open it again just so we can like see. So close it and then open VS Code. And then you see that our code folder is like already open here. Um if it's not there for some reason, I'm just going to close mine. So I can say close folder. And then if you want to open that folder again, you just, you know, again, you can go to file and then open folder or or use those two pages and then browse to desktop and then browse to the code folder and say select. And then we have our code folder here. But it's it's empty. Um but we're ready to uh do stuff.
So, inside of the code folder, we're going to create um a project file. It we'll just call it main.py. Python files end with py just fy. So, we're going to write uh our first line of code. It's going to be that like iconic, you know, print hello world. So, we'll just type uh print and then just copy what I have on the screen like parenthesis. Okay. Whatever. Allow this. I don't know if you're going to see that, but just type what I have on the screen. And then you can go to run and then uh run without debugging or you can press the play button and then choose Python debugger. And then it will open this terminal down here and the code will run. And then you see it says hello world down here. And that's all there is for this one. Um I just wanted to get the environment up and running. If you're able to do everything and follow along and you're able to print hello world and everything looks good, great. We can move on to the next one. Um, if you get stuck, go ahead and ask in the community, like the forum, either the cyber range or the cyber community, I guess, depending on like where you're watching this. And then feel free to tag me in there. Um, don't DM me about code individually. It's not scalable, but tag me and then someone will probably get to it before me, but if they don't, like someone will like tell me and I'll get to it. Yeah, that's the end of this lesson and we'll see you in the next one.
Welcome back. In this video, we're going to cover debugging and the general basic flow of code um in Python or I guess in any language. So, um I'll just get right into it. Um I'm going to make a few more um messages here just so we have like some code on the screen that can do something. Uh, and by the way, like all the stuff I'm doing in here, it's it's just like really basic and I'm just showing you um like the fundamental tools of how stuff works in Python and it will all make sense and we're going to like tie it to real world context um like when we get to actually building like the components and and building out the AI sock agent and when I can I'll try to give like real world examples of how stuff is useful um and how it's like used in in real life or whatever. But um sometimes I I won't be able to. I'm just like showing some feature or something like this. So, um like I said in this video, we're going to cover just like basic flow of code and then uh ability to debug. So, oh, and also before we like really get started, um my intent is for you to copy the stuff I'm doing and if I need you to get like a certain file to do something like there's like too much code to write or you know you need some file, I'll like let you know. Um but otherwise, feel free to just like type along and then just like you know type out the code yourself. But okay, this is our file. Um, we have our file main. py. If you don't have the file anymore, you know, you can always like reopen the folder on your desktop, the code folder, and then you can like create a new file like like so, like, you know, main py something like this. Um, I'm going to delete this though.
Okay, so here's our here's our file main.py. And if we just run this as is, you'll notice it just immediately like prints everything out on the screen, right? But Python um it will execute um sequentially like it will print this one and then this one and then this one and then this one and then like the program ends essentially. So if we don't want it to just like immediately just like zip through the whole program when we want to like inspect things, um it gets really useful later. We can set what's called a break point. Like if you put your mouse to the left side of these, this is like really, really important by the way. Um, so you can break it anywhere. So it's called breaking it. So I'll go ahead and break it on line one. And then you'll notice if you if you just click play, it just plays out. It just runs anyway. And if you click run and you say run without debugging, it will just like run as usual anyway. But if you want the code to stop here, you can say run and then start debugging and then Python file. And then you'll notice this like yellow thing highlighting the first line where we put our break point. This is like where the it's called the interpreter. I guess you can think about it like that. Um where it will like stop execution and then you have the ability to like um step over and step into. I'll talk about what all these things mean later, but for now let's just use step over. So if you click the interpreter's here, right? It's about to execute this line of code. That's what that yellow like thing means. So if you step over, you'll notice hello world one prints and then it moves to the next line and and so forth like so. And then and then it finishes, right? That's pretty much all there is. Um that's pretty much all I wanted to show. And it's really surprising because when your when your code starts getting more complex, you really need to be able to like debug it and observe what's happening to get an understanding and intuition for it. And I've seen people get like halfway through like computer science bachelor's degree curriculum and then not know that you can debug your code, which is really insane to me. So just get used to debugging stuff all the time so we can like closely observe and inspect what the code is doing.
And I'll show you something like uh really quick here. Um we're going to talk about this more in depth later, but so there's like decisions that Python can make. So for example um if you know 10 is greater than uh nine print cat and I'll do like another one if you know one or is if uh zero is greater than one print dog. So like intuitively speaking uh oh and I'll put a one at the end print. So intuitively speaking you can think in your head if 10 is greater than 9 maybe it's going to print cat. If zero is greater than one maybe it's going to print dog. Um so instead of just like you know running this all the way through we can like break it and then we can observe the code like as it runs through and makes decisions about stuff. So I'll break this here on line one. And then I will run this and start debugging. And then we can observe things slowly. So we can see like so. And we can see it printing stuff down below. And then it gets to this point. If 10 is greater than 9, print cat. So is 10 greater than 9. In your head, you might think yes. So it looks like cat is printing. And then it goes to the next statement. And then if 0 is greater than one, print dog. Is zero greater than one? It's not. So we can like observe the interpreter like skip over this because this condition was not met and then it goes to the last line and then we can step over that and then it gets finished. Um yeah, that's debugging and flow of code in Python. Um of course it's going to get way more complex but I just wanted to like introduce debugging to you and drill it into your brain that you always need to be using this and we'll see you in the next video.
Cool. Welcome back. Uh in this one we're going to cover variables and I don't know if you've taken like algebra or something before where you where you deal with stuff like you know x is like equal to something like this but it's kind of similar in that sense where um you will have like a variable name something and then you can assign it a value like this. So like if you see something like this it doesn't mean that like it doesn't mean x is equal to 7 exactly. If you see like a single equal sign, it means like whatever is on this side of the equal sign is going to get put into whatever is on this side of the equal sign. So for example, we say print and then just say x. I'm going to break this here. So break your code here and we'll say run and start debugging. And this is like important. So when the code is debugging, like when you have this like yellow thing highlighting and it's like in debug mode, you can um go to this like bug thing with a play thing uh a play button. And then for example, if I step over this, you'll see that like x now is equal to 7 or rather x has the value seven in it. So if we print x, you might expect seven to get printed out and it does for example. So that's pretty much all that's pretty much all there is. It's just that I just want to say you can like have variables and then you can assign them values. And best practices in programming in general um is to make variable names that like really make sense even if it's like long. So um for example I might have a variable like you know this is like really contrived but you know my full family name and then um this is called a string which we'll talk about in a bit. It's just like a a collection of any random characters. So my full family name Namdi Joshua Mator and then I can do something like print my full fam name. By the way, you can type like um you know as long as the the letters are in sequence. So for example, I can type my MF fn like something like this and press tab and then it will like autocomplete the variable. So I can do this and then if I run this so I can break it here and then I can continue or step over and then it will print like my full family name. And you can put numbers in variables too of course. So I can say like my real age like something like this. I can do like so. Oh, whoops. My real age. And then I'll just run this without debugging. You get the idea about like debugging. Oh, whoops. I I debugged it anyway. My bad. Just continue. And you'll see it prints NAMD Joshua Mator and then it prints 40 out. And then we'll get into this like um oh uh let me show you something else actually too. You can do like for example um my a for example my my age I can make a variable called my age and set it to 40. Then I can say your age I can set it to 30. And then I can do something like our combined age equals my age plus your age like so. And then I can do this our combine age. Oops. Our combine age like so. And then I'm going to break this here. And then I'll say like run and then start debugging. And then basically like what happens um remember that thing I said earlier if there's a single equal sign like the stuff on the right side will get assigned to the stuff on the left. So whatever is here will get evaluated and then get it will get put into here essentially. So we see on the left we're on the debug screen right our code's debugging. You can see this thing is highlighted. My age is 40 your age is 30. If we step over this like this computation will happen. And then now we have a new variable like our age is 70 which is here or our combined age. And then if we continue this program, you see it gets printed to the screen like so. And of course, this will get like more complicated over time. Um, but I just want to show you like what a variable is and like maybe some general use cases for it. when we get to like um creating the actual AI model and stuff like this, we might have something that looks like um this I don't want to like make this like too complicated for you, but we'll have like a lot of stuff that's fixed in place that doesn't change that makes more sense to be in a variable. So for example like we might have like a you know default for example chat GPT model and then maybe for our default model we want to use like GPT5 which is like brand new you know or technically or you know GPD 4.1 or some something like this and then later when we when we do something with our our model we can just like reference this um this variable instead of like typing out a string or something like default tangent model. If we print this, of course, it's going to print GPD5. Yeah, that's variables. Um, it's just something that can store the value of something else. And you can do computations. We'll just do like one last thing. You can do stuff like this. They store value. You can compute stuff, etc. see that this got printed out and then you can use them in other places in your code. And this this of course it will make a lot more intuitive sense when we start actually doing stuff with it and then doing more examples. But yep, that is variables. And we'll see you in the next lesson.
Welcome back. Uh in this lesson, I'm going to talk about types or data types, what's more commonly known as data types. And basically um it's just the different uh I don't know how to say the different format or like what something is considered. So for example the I think these are actually all different data types. This is technically a string even though it's 20. Uh this is an integer and then this is a float I believe because it happens to have a period even though they're they're all 20. Right? So if I if I try to do something like um combined age equals age1 no I'll do age2 + age3 and then try to print combined age. We can see what happens. I'll set a breakpoint here. I'll run this debug and then we can step over this and we can see our three variables. H1 is 20.0 is 20 and then this is also 20. And we're trying to combine 20 + 20. H2 is 20. H3 is also 20. And then these should it's supposed to add these together and then assign it to combine age, which you know intuitively should be 40. And then it should print. But if we try to step over this, it says like it it can't do that because we're trying to add um what's a considered a string and then a number. Like to us this looking at this makes intuitive sense but to the computer it's literally the same thing as saying like okay let's what's like cat plus 20 or what's uh India + 5 or some something like this it doesn't make sense right to add what's considered a string and uh an integer or a number and by the way a string is just like any arbitrary characters that are enclosed by quotes could be like a double quote or a single quote but Uh you can force for example you can force this into becoming a number. Um if you do something like this int science or coding or whatever this is called casting. So I'm going to cast this into an int. So we should have two integers and then we should be able to add those. So I'll just like run this you know without debugging. It should just print 40 because 20 plus 20 gets assigned to this and then this will print 40 out like so. And I'll I'll step this. I'll I'll debug it so you can see it. live and we can see it stopped here. We can see our three variables. We step over this. We see combined age is now 40. And then if we print it, it prints out 40. And you can also see um what type something is. So for example, you can see if it's like a float or in int or whatever. Example, if you print out the type and you put the thing inside that you want to see what see the type of it. So for example, H1, H2, H3, like so. I'll break this maybe here. And we will debug. It stops here. So H1, we'll print this. It prints out a float cuz it's like a number with a decimal. Even though it's zero still, uh, it's still a float because of the decimal. The next thing is a string because it has quotes around it. The next thing is an int. like so because it's a a flat number. I don't know how to say this, a non decimal number. And we can do something like this. We can we didn't learn about this yet, but this thing is called a list where you can have like um it's like a grouping of items. They don't have to be similar. They can be like any type of item. So for for example, this is like a group of numbers that are 1 through 7. This is a group of um, let me print the type of this is what I want to do. We'll learn about list later, so don't don't worry about it like too much, but I just want to show you. So, I'll put a list in here, and then I'll put another list in this one, and I'll put like age one, age two, and age three. So we'll print these out and then we can end the lesson start debugging and just try to think about what this is going to print like what is type of age one looks like a float and it prints float. What is type of age two? This is a string. What is type of age three and this [snorts] should be an int. And then what is this type? This this is a list a list of integers. This is a list of random stuff. Remember this is like a float, this is a string, this is an int. But in overall it's still a list and the last two things are lists. And this seems like really arbitrary and I promise there's a use case for it. Um cuz type matters. Um it matters a lot more when you start doing complex stuff. And I just want to show it to you. So you know I can kind of prime your brain for when we start looking at more complicated stuff. um it it seems like a bit ambiguous right now, but it it will make sense later and it will be like much easier to interpret and understand when we start actually doing and building things. But yeah, that's data types. I just wanted to go over that real quick and we'll see you in the next lesson.
Welcome back. In this lesson, we're going to cover input and output. Um, we kind of already covered one version of output which is just printing stuff to the screen but in this one we're going to cover actually like taking in input um from the user like from the command line. So for example, we can say something like um I'll just print like a welcome message. Welcome to our program and then we can say uh first name. Then we can say like this is how you get input from the user. It will make sense in just a moment. I can say uh please enter your first name and then just you can follow along with me. So, and then back slashn means uh it just means new line in Python. You'll see like what this means in a second. And then we can say, you know, last name. This is this is a variable. And then this is like a function to get input from the user. But we'll see what this looks like in a second. So, we'll do this. You can might guess what we're going to put in here. Please enter your last name. So, and then I'm going to say print hello and then do a comma and a space and then after this quote do a space plus and then we'll say first name space or do a plus and then just copy what I'm doing comma space and then another plus and last name like so and then we will all break this. Uh, I won't break it. I'm just going to run it first. So, I'll just run this as is. And you can see down below it printed welcome to our program. Please enter your first name. And then you see this thing went to the next line. And then we can click down here and then put your name in. Say enter. Please enter your last name Mator. I'll say enter. And then printed hello Josh, oh that was not necessary this comma. But you can see it says hello, Josh, Mator. So actually I can remove this comma from here and I'll resave this. And then I'll go ahead and like break this and I'll run and say debug. And then you see it breaks here and then I'll step over this. Welcome to our program. And then it will pause here. And then basically this this input thing um puts the thing to the command line that it will say this and then whatever we type and press enter it will get stored in this variable. So if we step over this, you see it says please enter your first name. I'll just put Josh and say enter. And you can see the next line uh got broke but on or it it's paused executing on the next line. But we see over here like the value the string value Josh got assigned to first name. Same thing will happen here. Enter your last name Mator with a capital A on accident. Now we see last name is over here in debugging by the way. That's what this is. And then we can just uh continue executing the program and I will show you uh I'll just uh I'll change these uh no I'll just I'll leave it as is and I'll I'll show you something interesting. So um I'll debug the skin and break it here. Welcome to our program. Please enter your first name. I'll step over. I'll put uh Bob. say enter and then last name I'll step over this I'll put I'll just put like Mator and then you see over here on the left in the debug window this thing you can see the variables here actually and then you can actually edit the variables live um if you there's some reason you want to do it like you're testing something so even I typed Bob I can like edit this I can change it to you know Josh enter and it changed now when I step over the last line of code, it prints hello Josh Matachor instead of Bob Mator. But yeah, that's getting input in um from the command line. And the way this is used in our like aentic AI like the AI sock analyst that we're going to make um there's going to be like something in there that it says something like, you know, uh what are your security you know what are your security concerns with the environment or like or just like what do you want to do for example and then the user prompt. And this is not exactly but this is what gets sent to chat GPT kind of um as well part of the prompt. So for example like in the real like AI sock analyst thing we're building for example welcome to our program what are your security concerns? What do you want to do? And then notice how I didn't put back slashn here and now the cursor is like up here instead of down below. But I can say like um I think someone breached one of the computers VM named Windows target one. Oh, I I made a mistake. Target one like so. And then th this is an oversimplification, but this prompt would then like get sent to GPT and then some analysis would be done on it and then a threat hunt would ensue essentially. Um, but that's that's how this is used. It's just used to take input in from the user when we're trying to do something. Um, but yeah, hope that makes sense. Uh, that's inputs. Uh, as always, you can always ask questions in like the Cyber Cyber community, like the community section. Don't DM me directly, but ask questions there and feel free to tag me. And we'll see you in the next lesson.
Welcome back. This lesson is super simple. We're going to cover comments. Um, comment is just basically something inside of the code that the interpreter will ignore and it's just for humans to look at and read just so they know what's going on. And there's two ways to do comments. You can do like a single hash mark like this and then type whatever you want. So I can say like a welcome the user to the program upon launch. And then for this one I would say like you know gather uh information about what the user wants to do. And then this would be like you know tell user that uh tell user what will be sent to chat GPD some something like this. Um it's just to describe what's happening in the code. And of course, if something is like too easy, like maybe you don't need to comment it, right? So, for example, like something like this, you know, you wouldn't you wouldn't do like prints out the word cat like cuz this this is already like this is already too self-explanatory and this is actually like more characters than the actual code. So, like this is not something that you need to comment and a lot of the times the the code will be like more complicated. there will be like a big chunk or a big like block of something that you know maybe needs some kind of explanation or maybe maybe you're using like some kind of API where you would put like um you put like more info at you know whatever um you know whatever openai.com API reference how to you know xyz so you know a future developer can like see this in the future and then be like oh okay and like go to it But it's basically just comments, you know, to let other humans know what's going on. And there's two type of comments. There's just like single hashtag one and then there's like the other type which is like for example like this. You can do three like single quotes and then whatever you like put inside of here um is ends up being comments. This is a string technically, but you can use it as a comment inside of um Python like so. Oops. like so. And I believe you can break these type of comments, but you you can't break these or you can't like uh if you for example if you put a break point and I say like start debugging the the program will just run all the way through. Um it just breaks up here. Even I didn't put a break point there. It I clicked here. Sorry. It won't run all the way through. It'll just try to like break somewhere else. like it it won't break on the comment where I put like the the red dot if that makes sense. So, for example, if I just like erase all of this and I I do something like something like this and I I try to like break it um it it doesn't break the program. The program just like runs all the way through like so. But if I do like the triple quote comment, it will you can break on this. This is not like super important. Um but I believe these these will break. So if I run this and debug um yeah see it will break like so. Yeah, that's comments. Um it's just a way to um let other humans know what's happening in your code and just try to get in the habit um using them not only for like other developers but for yourself too. Especially when you're new and you people tend to write like code that's a bit ambiguous and you might need to be reminded of it in the future especially when you like figured out how to do something really complicated. I'll put like yeah I'll put URLs in my comments sometimes. But yeah, that's comments. [snorts] Um pretty straightforward. Uh, we'll see you in the next video.
Welcome back. Uh in this video we're going to cover uh if statements. Um it's going to bit it's going to get a bit more difficult in here. Um it's how you control the flow of your code based on like if something has like a certain value or or something like this. Um it will make a lot more sense when we start doing the code. But basically um I'll just do something like really really basic. I'll say like my age equals you know 17 or something. Your age equals uh 40 or 55. Then we'll say something like um if uh we'll ignore actually we'll ignore this for now. I'll say if my age is greater than 18 we're going to print welcome to the club. And then I'll just go way down here and I'll say like print finish just to show our program is finished. So I'll set a break point here and then I'll debug this. See it breaks here. We'll step over this. We see my age is 17. Has the value of 17. Now some like decision is going to be made here. If my age is greater than 18, we're going to like do [clears throat] something. Um otherwise we're not going to do anything. So step over this. See what's going to happen. This whole thing was skipped. Nothing got printed because my age is not greater than 18. And then the code finishes like so. So if you want to like um if you want to do something if this is not true you can say something like uh else um back later something something like this. Come back later. So if we run this, I'm just trying to like let you get an intuition for this minus 17. If this if this is true, then this will print. Otherwise, this will print. So if we step, this doesn't print cuz this is not true. And then this one, this thing will always get printed. Whatever is inside of else, it'll come back later. And then prints finished. But we can add more statements into here. We can say like um l if l if my age equals 17 we can say come back next year. So we'll save this. We'll run debug it. Code breaks here. We can step over. We see that this doesn't execute because my age is not greater than 18 and then it will skip. It will go ahead to the next evaluation and it will say is my age equal to 17. And in Python when you're comparing two things like this is an assignment. This will assign 17 to my age. But if there's two equal signs, this will compare two things. So we're saying else if my age is equal to 17, then we're going to do something. So if we step over this because my age is equal to 17, it will go ahead and then execute this thing like so come back next year and then you'll notice it completely skipped over this thing and just went to the end of the code. That's because um this is like I forget what it's called an else if block or an if block. um only only like once one of these conditions is met all the code under that condition will execute and then once it does the thing is like it's done um the interpreter will just go outside of the block and then start executing the next code. So for example I'll show you what that means. So if we just copy like a bunch of these and by the way um that's why like stuff is indented in Python. It just groups it with the thing that's above it. So for example, I'll show you what that means. So if we restart this, the code breaks here or the code stops. We step my age is equal to 17. This is not true. So none of these will execute. We step over. Is my age equal to 17? It is true. So now the interpreter went inside of this code block under this statement and it's going to execute all of these things. So it'll it'll print three times. And then because one of the if statements was satisfied, the whole rest of the thing like totally gets skipped. So I'll add another thing to here. Um maybe you can get like uh an intuition or rather let me let me do this. Let me do this. So I'll rerun this. Code breaks here. It stops. We see that my age is equal to 18. So think about it like is my age greater than 18? It's not greater because it's equal to 18. So you'll notice this total this thing totally got skipped. The next thing is going to evaluate is my age equal to 17. It's not. So this whole thing got skipped and then this thing will print. This block of code will print like so. And then finish. And you can have a lot of I think you can have pretty much like unlimited uh else if statements. So if I add another one here, l if my age um is you know I can say I can say greater than or equal to 18. We can say print wow you just made it. Oh no doesn't make sense. Wow. Welcome to the club. I don't mean like an actual club. I mean like you know a kids club whatever. So um and I'll I'll copy this a few more times just to so you can get like the intuition that like once one of these conditions is met everything underneath of it or everything underneath will execute. For example, we run this still broken up here. The break point my age is 18. Is my age greater than 18? It's not. So that thing gets skipped. Is my age equal to 17? It's not. So that gets skipped. Is my age greater than or equal to 18? That's how you say this. And it is greater than or equal to because it's equal to 18. So now this code got block gets executed. And then this gets skipped because um something one of the conditions was satisfied and then the it just goes to the next line which is um going to finish the code and it does. So, how this relates to the real world or like rather what we're going to be doing. Um, I'll just give you like a really basic example. This is used like literally everywhere by the way, but um in chat GPT like you you can't send an infinite number of uh characters to the GPT model. It has a limit, right? So for example um I can say like you know my prompt equals you know please find the threat for me I think someone logged into my PC something like this and we can get like the we can get the length of this in terms of characters like how many characters long it is so we can say um just any random variable name I'll just call it length And then to do that we we do we use a length function called len and then we put the thing inside that we want to measure like so. And then if the prompt is like too big we don't want to send it to GPT cuz it's going to like have an error, right? So we can say like uh and then here's another example of a variable. We can say like this is really just random by the way. Like of course you know the prompt max size is bigger than this but I'll say like max prompt size and I can set this to like 10. So if anything's larger than like 10 characters we can't send it to GPT just for example for a sake of simplicity. So we can say like uh if uh call this prompt length. So if prompt length is greater than max prompt size, we're going to tell the user your prompt is too big. Have to shorten it. else you know uh send this is a comment send prompt to chat GPT and then in Python if you just you don't want to do anything um you just type pass this is just for example right I just want to like show an example so if we run this oops so if we run this I'm going to set a break point here now we'll run So max prompt size, this is just a just a variable. Let's get set to 10. And then my prompt, please find the threats for me. I think someone logged into my PC. You can see it here. My prompt. And then this length function calculates how long this prompt is. So if we step over it, we see the prompt length is 65. It means there's 65 characters like inside of here supposedly. And then now we're saying if prompt length is greater than max prompt size, we have to print your prompt is too big, you have to shorten it. Otherwise, we're going to process it like send the prompt to chat dbt. So if we step over this, our prompt length is too big. It's more than 10 characters. So it's going to print something to the screen. Your prompt is too big. You have to shorten it and then the code ends. And we use we use something really similar to this inside of the the AI sock agent that we're going to build it. It's just a way to control the flow of the code. Um to measure something and like control the flow of the code. So hopefully that makes sense. Um at least by the time you see them um in the wild when we start getting into the actual coding and building stuff, hopefully it will make more sense. Um they get really complex. Um they can get really complex, but um if you understand this much, you are good to go and we'll see you in the next video.
Welcome back. Uh this is a lesson on lists. Uh, a list is basically just a collection of things. It could be collection of strings or like any kind of other random stuff. Like it could be anything. It doesn't have to be strings necessarily, but I'll just kind of like uh show you, you know, what it looks like. Us. Usually it's like a collection of stuff that's similar like similar items. Um, there strings are more useful or rather lists are more useful when the items are like similar and it's usually similar stuff. But I'll I'll just like kind of show you what it looks like and like how to use it and stuff. So if I if I print this and I say like type and I type the name of the variable, we can see like and I break this. I can break it. Yeah, I'll just run this just to show you. So it breaks here and then if we step over it, we see like the list over here, the random members list. We can see it 0 through four. And if we print this type random members, it will print out that it's a it's a list. We're printing the type. But if I just print out the list itself, like so. Break it. Let it run. You can see it just prints out Josh, Leia, Miho, Ken, all see. It just prints it out um all of them together. But if we want to um print like a particular one of these for some reason or we want to access it for some reason, we can say like um this is like the first member, second member, third member. So if we want like third member in the list for example, we can say like we do it like this. So this is the notation and actually this is the zeroith place like zero index one index second index third index fourth index. So if we want this one we would actually get the second index. So this is 0 1 2 3 4 like so. And then it it should take out the second index and store in here. And then we'll print that. Oh, damn. So, we'll actually print this out like so. Okay. Okay. Like, whoever's editing this, can you like remove that URL because actually I don't know what it is, you know, and I I don't want them going to it. But anyway, so we'll paste this and then we'll break the code here with our break point. We'll start debugging and we step over. We see our list is here and then we can actually see zero place, first place, second place, third, fourth. But the third member in English are, you know, for our English brain, we'd say like 1 2 3. So we're going to step over this and we see that uh miho got assigned to third member in the list which is here and then it will print out. So and we can do other stuff with this. For example, uh we can say number of members. We can make a new variable and then we can say we can use a length function and then pass this thing in here the random members uh list. Then we could say if number of members is greater than three we can say there's not enough food. Sorry. And then we can say else or we can say else if or l if number of members is less than or equal to or yeah we can say if less than three we can say print welcome in there's enough for everyone like so and then we can say finish just so we know the code is are program is done. So if we run this, we can start debugging. This is broken break point here. We get our random members. We see them over here. And then we step one and then number of members. It's it takes the length of the random members. So we see number of members is equal to five. And then we can just look at this um number of members is five. So is five greater than three? Five is greater than three. So then then the line under this should execute and it does. And then when this executes it means one of these conditions was met in this like if statement. So after this executes the code's just going to go out. So like so there's not enough food. Sorry. And then it finishes like so. But if we remove like you know maybe me and I don't know can and also we run this again we get a sense step over there's only two members again or there's only two members we step over this the length of random members is only two so if if Number of members is greater than three. It's not. So that won't execute. Is number of members less than three? It is. So this executes. Welcome in. There's enough for everyone. And then the program finishes. So yeah, that's lists. Um they can get more complicated. Um for example, you can have like all kinds of random stuff in them. So for example like we can say something like you know maybe we have a string. Let me like maybe we have like a number maybe we have like you know whatever this is and then maybe we have like another list actually you know another list. This is actually another list right? Um so you can do something like this and then you can say like um you know oops let me let me rename this to something else. I'll just name it my list. This is a bit interesting. So we can say like print my list and then I'll just like run this without debugging. Um just it's it's going to print it out. And you see that it prints this. prints like this is the list Josh 10 class string and then it prints another list right so this is item zero item one item two and this this is the third item so we can say like for example if we say my list and then index 3 0 1 2 3 it will access this list so if we print this I'll just run this you notice it prints 1 2 3 4 because it prints only this list. But what if we want to print like only three for example? So this is a list itself. So we have to get if we want to print three, we have to print index 0 1 and then this is the second index. So this
returns a list. So if we want to print the second index of this list, we would do something. Oh, I mean to do that. We do something like this. It's like a bit confusing, but that's just like how it is. So let me do this just so we have something else. So I will start debugging this. It breaks. Then we, if we look at our list here, we see index number three is 0, 1, 2, 3, 4, 5, like so. 0, 1, 2, 3. This is our index three. And then if we get, we're getting index three from my list, which is this, uh, another list actually. And then we're getting index two from within this list. So that's index 0, 1, 2. So this should print three out. Should. And it does. And then finishes. So that's those are lists. Of course, you can do like a lot more with them. Um, we're going to, anyway, we're going to use these like quite a bit in the future, but I just wanted to introduce them and give you like a leg to stand on, I guess, when you start seeing like production versions of this. But yeah, that's lists and we'll see you in the next video.
So, getting into the next lesson, uh, this is where we're going to cover what's known as JSON, which stands for JavaScript Object Notation. It's just a way to represent, um, something in a nice structured way that the computer is, it's easy for the computer to parse out and understand. Um, it can be like a representation of like a real-world object, or it can be like, it can be literally anything, really. So, I, I went to GPT and I was like, "My name is Josh. I'm 40. I'm a cyber professional. I live in the US. I like these things. Uh, please represent me as a JSON object." And it built an object that looks like this. So, this is like a property. And then the value. The name, we'd say like the age property has a value of 40. The profession property has a value of cyber security professional. And then the locations, um, because I said I live in these three locations, it grouped them in a in a list or or an array. You can call this like an array or a list of like objects. So if you see, um, if there's like a group of like objects in in JSON, it will be formatted like like this. You'll see like a square bracket around it. And so locations because there's like three, like, you know, they're all locations, so it formatted them like this. And then the things that I liked, same thing. It's likes. So it formatted them all together in like a list like this. So pretty, pretty straightforward. Um, you can have like, well, you can get like really elaborate with this, which we will cover in the next lesson. And then I told GBT like, okay, create three more humans with the same schema. And schema just means like the way the data is formatted, or the format of the data. So, has me, Aiko, Marcus, and then Sophia, and they're all, they're all like the same format, you know, their loca, or their locations, their likes, etc. It's just a, well, it's just a way to format data. And we're going to get into this, uh, a bit more in the next lesson. By the way, I copied all this and then I created a variable called people and I just, um, assigned people this JSON object, and you can do that. So, for example, if I just simply print people like this, it will print that whole object out. The whole object with like everybody in it. You can see like Josh, Aiko, like Sophia, and everybody else. And this thing, this is actually a list, like it returned it in a list format. You can see like the outer thing is like a square bracket like so, because it's a list. So if I, for example, I collapse this, this is like one item in the list. This whole thing is like one item. So I can collapse it. This is another whole item. So, right, I can collapse this, etc. And if you remember, um, you can access lists by, so basically lists are ordered like from zero. So this is like the zeroth item, the first item, the second item, and the third item, and, or, or like the item at position zero. So if I say like people, uh, give me the one, the person at position zero, which is me, it should just return this whole thing. So if I run this, it will just print out Josh's stuff only. So, Josh, and then cakes, pizza, and sushi, like this. And this is person zero, right? So this is Josh. And if I want to get only like the name property, I can pick the per, the people at position zero, and then I, I can get like their name property, and it will, it should only print Josh, for example, like so. And we'll dive into this a bit more in the next lesson, um, where we talk about dictionaries, and I give some real-world examples of where you might see JSON like this. And dictionary, like, this won't make sense yet, cuz you didn't get to the dictionary lesson, but dictionaries are, are basically in JSON format. This is, this is basically like a dictionary. So, for example, this is the last thing I'm going to do. So, people zero. I'll print this again, just to like give you a sense. And you see it prints out this JSON object essentially, that is a representation of Josh. If we want to see the type for this, like what is it, we can do this. We can put it inside of this type function, equals zero, and then we run it, run without debugging, and then it tells us that it's a type of a dictionary. And the next lesson is on dictionaries. So we're going to like really dive into more depth on that. So we will see you there. That was, this was JSON objects or JSON.
Welcome back, and we're going to get into dictionaries in this lesson. And this is like getting like really real-world. After I do this, uh, simple example, I'll show you what like, you know, a real, like production dictionary looks like and how we're going to use it like in the, um, our project that we're going to do. But basically, um, just like a real dictionary, um, basically there's like what's called a key and then a corresponding value. So in a real dictionary, you'd have like a word and then a definition. Um, but in Python, this is called key, and this is called value, and then these things together is called a KVP, or like a key-value pair. So, for example, this is how you define a dictionary. Well, one of the ways that you can define a dictionary, it's called fruits, and then these are all the keys on the left side, and then these are all the values. So if I want to get access to like, if I want to access or change, um, this definition, or if I want to access or read the definition, this is how you would do it. Um, but I, I'll just like step through it and then explain it as we go. So I'll put a breakpoint here, and, um, by the way, I'll put a link to like this file. Um, there should be a link to that, or a couple files for this lesson. So you can just like either copy the contents or paste them in here, or you can put them inside of your code folder, like download the file into your code folder if you want, but I'll break this, um, start debugging, stops here, and then do this, and then I'll step over this, and then you see on the left, we can see our fruits dictionary, apple, like a word, and then definition, word, definition, etc. And then this is how to access the definition for apple, or yeah, the definition for apple, or the value of this key, like so. This is just the notation to do it. That's just how it is. Um, so you can kind of get used to it. I, I do recommend you like type this out to like get your muscle memory and stuff. Um, it help, it really does help a lot. But we'll, uh, step over this, and then we see it printed the definition for apple, sweet, crisp fruit that comes in red, green, and yellow, just like this. Like so. And then we're going, this is how you add a new fruit and its description. So this is like, uh, this is our fruit dictionary. And then this is the, this is the new key that's being added, and then the new value for the key, or like the new word in English, and then the definition of the word. So if we step over this, we see that grape gets added to the dictionary, like so. And then this is one way to remove a key, or a key-value pair from the dictionary. So if we run this, like delete space fruits mango, it should delete the whole key-value pair of mango and then this juicy tropical fruit. So we step over this. Oh. Oh. Oh, I accidentally, uh, changed the description of banana. So, let me just like, uh, rerun this. I skipped banana on accident. So, I'll break this here, and I'll just rerun it again. So, here we are at banana. This is how you change the value of something. So, if I expand this, uh, it's going to change the value of banana to a soft, sweet tropical fruit. So, right now, banana is a soft, sweet fruit with a yellow peel. So, if we step over this, we see that the value changes, like so. And then this is how you delete mango. I don't know how I managed to skip that, but, um, we will step over this, and then mango should disappear, and it does. And then, um, we didn't actually learn this notation yet. We'll learn about this later. Um, it's called string interpolation, or f-strings. But anyway, it's going to print each, for every fruit, it's going to print the fruit title and then the description out. So we can just like, we didn't learn about this like loop yet. We'll learn about loops later. So just like ignore this. I just got this example from GPT because it was like easy and made sense. And then we can see all the new values getting printed out like so. And then the program ends. So I'll do like a really simple custom dictionary, um, with like people's names and ages. So, um, we can say like, for example, uh, which I do, I'll say like person, I'll do person one, and then so say name, I'll just say no, I'll say people, sorry, people name, then Josh, no, okay, people ages, we'll do this, people ages. So I'll say Josh 40, Aiko 31, comma, and then Leia, I don't know, I forgot, 26 maybe, just two, and Jimmy, no, there's no Jimmy, I'll see, is I think 30. So if we, if we, if we want to see how old Josh is, we'd say like people ages, like so. And then we do, we'd access the person who we want to see. And we see Python's like autocompleting this for us. So if we want to do this, it will just simply, we run it, it will simply print Josh's age. It should say 40. Like so. So that's, um, that's dictionaries. It, it can get way more complex, though, um, which I'm about to show you in a second. So, go ahead and download this, uh, file called Big Dict. That stands for big dictionary. And what you're looking at here, this is basically like, um, an entire, uh, I guess it's called an entire threat. Yeah, it's a, this is a threat that was discovered by the AI sock analyst, and it will, it will output it in this like crazy, this like crazy format here. And this is, this is basically like one big dictionary, but there's like dictionaries inside of other dictionaries, etc. So, for example, just so you can believe me, I'll print type and then what did I call this thing? This should actually be called threat, threat instance. It doesn't matter, but that's, that's what it is. So if I print the type for this, I'll just run this without debugging. Oh, Python debugger. And then you can see it's class dictionary, cuz this, this thing is technically a dictionary. So you remember, dictionary is full of key-value pairs, essentially, like the, the word and the definition, or the key and the value. So what this is from, this is like a real, real-world thing. Basically, we're going to do this and learn about it a lot in the future, but we dump a lot of logs into chat GPT and basically tell it, or the GPT API, and we tell it, find the threats, and then it goes through the logs and then it will like correlate stuff and find something, and this is just one of the threats it found. It's like a, it's a dictionary object. But key, this is a key. And then the value, this is the key. This is the value. This is a key. And then this is a value. And you notice this value is actually just another dictionary. And then you'll notice this is a key. And then this is the value. But this value is just a list, or an array. It's a, it's a list. This is pretty standard. A key and a value. This is a key. This is a value. But this value happens to be a list, and it goes on and on. So if, for example, we're going to deal with like maybe a dictionary inside of a dictionary. So if we say like print, uh, oops, I didn't mean to do that. So let's look at this MITRE key. This is a, a key, right? And then this is a value. So if we, if we print, uh, threat instance, uh, MITRE, like so, I'm going to break this, save it, and then I'll run and then start debugging, and you notice like the threat instance variable over here, it's a dictionary, and you can see like all this stuff, and then this is the MITRE key, and then the value. So if we print this, like it is, it's going to print the MITRE, uh, value. So it, it should print this stuff, right? Just to get a sense for it. So if we step over it, we see that it prints tactic, initial access, technique, blah, blah, blah, sub-technique, which is this stuff right here. It just prints out another dictionary essentially. But for example, if we want to get access to like, what was the, um, you know, what was the description, the description inside of MITRE, like doing this just gets access to all of this, this whole thing, which is a dictionary. But if we want access to this, we have to use the actual description key inside of the secondary dictionary, like so, description. So if we run this, it should print the description for this, like so. And it does. And then I'll do one more thing, really, really quick. Um, so we, this is like accessing a dictionary inside of a dictionary. It's a bit like complicated. I, I know. Um, but that's just like how it is. So this time we're going to access a list inside of the dictionary. So this is actually a diction, this is whole thing is a key-value pair. This is a key. This is the value. Right? So we access, for example, recommendations. So if we just print this as is, or we run it, we'll stop here. Step over. It prints out monitor, [snorts], and pivot. And this is just a list, right? We learned about these a few episodes ago, a few videos ago. But say that we want to like access, you know, pivot, for example, we can do that. Um, but this is like the zeroth item, and this is the first item, or the first index, zero index, first index. So if you want to access pivot, we have to access the first index. So, so if we run this, print it, it prints out pivot. It reaches into, um, recommendations, and then we got the, uh, first index inside of recommendations, which is pivot. And it's a bit complicated, but I, re, I recommend you to like do some activities with this, like look at different values, I guess, and like try to print them out, like so, for example, like try to print this line out. This is a list, right, inside of the log lines key-value pair. So try to print out the first index of this, or try to print out this description, for example, and, or try to print out my email address. This is like a real log, by the way. Try to print out this email address because, um, when, if you're dealing with like APIs, or doing like really, like literally any kind of development that involves the web, or almost anything, you will be dealing with data in in this structure. So, it's like really good to learn how to parse it and like deal with it and stuff. And we're going to like be dealing with this a lot when we're actually building the, um, like the actual AI sock analyst, or however you want to call that. So it's really good to understand it, and yeah, that's dictionaries. Um, you can always like, you know, if you get stuck or have questions, definitely ask in the, the community area, or you can go to chat GPT. You can like literally dump anything into GPT and be like, explain this to me, like I don't get what dictionary is, or like, you know, you can talk to it and then get it to explain things to you in an easier way. But yeah, that's dictionaries. Uh, just try to acknowledge it and be aware of how to use it, and as long as it's not like completely foreign to you when you look at it, you're in good shape. But yeah, we'll see you in the next lesson.
Welcome back. Uh, in this lesson, we're going to cover what's called string concatenation. And concatenation just means like connecting together, like connecting something together. So, connecting strings together. And I'll try to, I'll give you like an example, um, um, of how to, how to do this. I guess that makes sense that we can like make use of some of the other stuff that we learned. So, we'll, we'll do a program. We'll say like, uh, not Josh. Oh my god. First name equals, and we're going to get input from the user. What is your first name? And we will, I'm going to copy this. This one will be last name. What is your last name? And then age, we'll say, how old are you? And then we're going to, uh, concatenate all of these. So we're going to say, we're going to print, and then we'll say, hello. So this is one string, and then if we want to concatenate, [clears throat] it, we can use a plus sign, and then we can say first name, and then we will concatenate more, like a comma. Oh, we'll say first name, and then sorry, we'll do a space. This is, sorry, this is like really troublesome, but it will make sense. Hello, first name, last name, and then we're going to concatenate. That's how you like connect strings together with like the plus sign. Then concatenate again. Oh, wait. You are base. We'll say age base years old, right? I know this seems like really arbitrary, but we'll take a gander at this. So, say this, and we'll break it here. Or maybe I'll break it here, and I'll, I'll just like let this run. So, we'll, we'll debug this, and the code's running. We say, what is your first name? Josh. Your last name, Matakor. How old are you? Six. And then the code, because we put a breakpoint here, we can see here, our first name is Josh, last name Matakor. Our age is six. And then if we run this, it should just like put all these things together. We run it, it says, hello Josh Mator. You are 6 years old. Right? That, that's just string concatenation, basically. Um, it's just putting strings together. And then in the real world, um, when we go to like build the, you know, the AI sock analyst, we're going, we're going to use this quite a bit. But one like really, like, um, main use case for it is, um, creating our prompt to send to the OpenAI, uh, API endpoint. Like when we're trying to do threat hunting, we'll, we'll have something that looks like this. Um, it will be like, uh, user, user desire, whatever, user desire, and then we'll have like a system prompt, and then we'll have, uh, like some logs, for example. So, for instance, instance, let me try to like do a real-world thing of this, one second. So, for example, um, I just, I'm getting some like actual live logs from the side range, a bunch of log on failures against one of our virtual machines. I like copied these. So, for example, we'll have something like this. Try to make this make as much sense as possible. So, this is like a way to do a block of string. So, I paste this like giant thing in here. This is like ton of logs, right? I just, this is a variable with like a ton of logs in it. So the user desire will be something like, um, um, we sus, you know, suspect a computer was exposed to the internet. We are worried, uh, it could have been breached, something like this, you know, a basic thing that we're going to ask the agentic AI, right? We, something's like wrong, can you like look into it and do a threat hunt, please hunt. And then this is where we would, we would provide like the system prompt, um, you know, that that would be like, you are an expert, you know, whatever, [snorts] expert, expert threat hunter, and an Azure and KQL god. Uh, please, you know, examine the logs and let us know if anything is wrong. Please cover MITRE, whatever attack TTPs, etc. Something like this. So basically, we're going to end up with like three strings, um, just the way the, uh, model context and protocol and like the whole agent works, and then we're going to have to like create like one, uh, basically large prompt, um, that we send to the, um, OpenAI, it's like the ChatGPT's API endpoint essentially. So, for example, my god, let me, so, for example, it, it will end up being something like this, um, you know, whatever message to send to GPT, not, not exactly like this, but pretty much, it, it's going to be a concatenation of these things. So we'll, we'll concatenate user desire with, uh, system prompt, and then with the logs at the end. Oh, yeah, this at the end of this, it will say something like, you know, please examine, oops, the logs below, something like this, and then this is the thing that will end up getting sent to GPT essentially, and then it will perform a threat hunt and then etc. So I'll, I'll just like run this, you know, just, just for fun. So, message to send to GPT. This is like the full concatenation of, we concatenated those three strings into this, and then this is what goes to GPT. And for fun, if you want, we can just copy this whole thing and we can go to GPT, and then this is like what will get sent on the back end to the API, like some, it looks like this. It's like some crazy, like big thing of text. It's not exactly like this, but it's like pretty close. And then it's like smart enough to like, you know, look through it and produce some kind of results. This is like really kind of like unstructured data and like a bit crazy, but I just wanted to show you like, um, string concatenation and how it's, and how it's used essentially. And there's like easier ways to do this, but yeah, I just wanted to show you that, and we will look at a more efficient way to do it in the next lesson when we cover what's called string interpolation or f-strings. So, we will see you there.
Welcome back. Uh, in this lesson, we're going to cover string interpolation. It's really similar to, um, string concatenation, but it's just like an easier way to, or more human-readable way to do it, I guess. So, uh, let's see if I run this. I'm just going to run this again, uh, without debugging, just so you can see the output of it. So, what is your name? Uh, Josh. Last name, Matakor. How old are you? Six. And then it prints out this thing like, hello Josh Mator, you're six years old, right? And if we want to do this with string interpolation, um, aka an f-string, it's much easier. And the notation is like a bit arbitrary, but it's just like this. You basically like just type it out. For example, hello. And then first name will go here. Last name will go here. You are age years old, right? Oops. Read. I don't know why I typed that. And then you just put the variables in here. So, first name, last name, and then age. Oops. Age. This is string interpolation. It, it's just like more intuitive to look at. Like this is quite hard to read, right? And you'll like mess it up with like spaces. It's just hard to deal with. But this one, it's easy to read. So, if we run this, um, I'll just run it without debugging. Or, yeah, and I'll use like a different name. Uh, I don't know. Uh, Sandy Wandy Wang. Okay. 90. It's the same. You see it prints the exact same thing, but this one's easier to read. This is like string interpolation. And the way, let me see, for example, um, if you remember that like long thing with like the prompt or whatever, um, where we have like, uh, you know, the user message, um, I want to do X, and then system, system prompt, or system message, you are a master threat hunter, blah, blah. Uh, use the logs below, and then the logs. No, uh, whatever random login data. It's a bit easier to like, um, do string interpolation with these, because you, you can just do something like this. Uh, master message, whatever, or combined message is a better way to say it. Combined message. You can do something like this equals, and you can do f-string, and then you can do like a triple quotes, or like this. You can do something like, um, it's like really like straightforward, say like user message thing, system message, and you would put like the logs here, like so. And then it's just, it's just easier to like look at and deal with, um, to be honest. And you can also do something like this. These are almost the same thing. So, for example, for example, do something like this. You put all these like even on the same line. And you can go back to single quotes. And then you just put like a, a line break between them, or a new line, something like this, like this. And then this is your system message. It's just like really easy to, to put it together. And if you print these, it should probably print the same thing. My message one, I believe, print one. Print two. And I'll just, uh, run this without debugging. It should print like, you know, it prints the same thing. So it just makes it easy to like put strings together without like using the plus sign and like all that like crazy stuff, if that makes sense. So string interpolation, aka f-strings, it's just like, you know, you have a string. I'll do something easy. Cat, dog, name, Jane. You just have a string, right? You can have an empty string, put an F in front of it, put the curly braces, and then you just put the variable in that you want to like combine together. So, and then I, I'll break this and then I'll, I'll end the lesson. So, cat name, Jim, dog name, Jane, combined names, it's just cat name, base, dog name, and then prints the combined names, and Jim, Jane. But yeah, that's, uh, f-strings, string interpolation, and we'll see you in the next video. And this is used like a lot in the real world, and for sure you're going to see it when we get there, and you're going to be like, okay, yeah, I, I learned what this was. That's the whole point of this. Again, I just want to remind you, I'm not like, we're not trying to become like fang engineers or something like this. I'm just trying to get people to like the level, or get you to the level where you can like recognize and interpret code, and then change it. You know, you can change it, um, if you want to change something. Like someone who doesn't know how to code anything, like they've never seen Python before, and if they look at this, they, they won't know like what they're looking at. But you, at least now you have like some idea, like you know what this is, and like if you want to change what gets printed out, you have some kind of idea, like maybe you want to change one of the animals' names, or you want to have like more spaces, or like a line, you know, a line between them, um, or something like that. So don't get like discouraged or anything. Um, I'm just trying to, we're just trying to build like a general intuition and be able to recognize patterns and stuff. But yeah, we'll see you in the next lesson.
We'll come back in this lesson, and we're going to cover what's called for loops. Um, a for loop is basically just a way that when you have a collection of things, for example, like a list, it's a way that gives you a chance to do something or interact with each item in the collection, if that makes sense. It will make more intuitive sense once we actually run the code, but, um, here's a list of things. We learned about lists, uh, recently, and it gets assigned to this variable, and then this is the actual for loop, um, how it's structured, and then, you know, the code ends here. So we'll just run it, and I'll just kind of explain things, um, as we go. So I also, I also made the screen a bit bigger, but it made my run thing inside of here. So I have to like, you know, go in there, but we see the code breaks here, and then if we step, our fruits has these inside of it, and then this variable, this is like a placeholder variable. It can be anything. Um, but the way it's like the grammar syntax is like, for x in whatever your, uh, collection or your list is, and then it will give you a chance to like print out every single thing. So, for example, if we step into here, we notice that the variable fruit, that is this, it got assigned the value apple, which is this. And then we print it. I like apple. And then it goes back up here. And if we step again, now the fruit is assigned banana, which is here. We step, it will print banana. Step again. And now finally, fruit got assigned cherry. And then we step. It prints, I like cherry. And then it finishes. It gets out of the loop because it, we say iterated, but it went over each of the items. And now the program ends. And, uh, this, like I said, this variable is arbitrary. It can be named anything. So, for whatever in my list, uh oh, for whatever in my list. So, for example, I can make this like, you know, some, some arbitrary, like variable, like so, it can be anything, right? So if I run this, the same output happens. I like apple. I like banana. I like cherry. Like so. That's pretty much, that's pretty much all it is. Same thing. I just want to show you that this variable is arbitrary. Um, see, one, two, three. It can be anything. Boom. Debug this. And we can, this is why debugging is so important when you're trying to get an intuition for things like loops, like how it works. It's basically like going over each one of these items in the list, and it's giving you a chance to to do something with it, right? But for example, um, to add a little bit more logic in here, we can say like, you know, this is like really contrived, but I'll put this back to, I, I'll say f. This is also like a common practice to do. But we can say like, um, we can say if does not equal apple, for example. This means does not equal. We can say print f, something like this. So, for example, debug this. And then for f in fruits, f gets assigned, uh, apple, which is the first one. We can say if f does not equal apple, we're going to print the fruit. We're going to print f. But it does equal apple. So this actually gets skipped the first time. And then we can say like, continue to just finish the rest of the program. And you can see that it printed everything out except for apple, as we just, you know, decided to not do it. This is some like really arbitrary logic. But for an example of how we are going to use this, um, when it comes to our AI sock analyst in like the real world, um, we might have something like, uh, for example, for example, actually, I'm going to, uh, format this. By the way, I'll, I'll put this, uh, in the link, this, this file, so you don't have to do all of this. I'll format document. Oops. Format document with black formatter. Oh, can you like cut this whole thing out? Who, who's ever editing this? Let me set this up. Okay, you can like start recording again. Uh, so another example of how we might use this. Um, this is like a big list of threats. This is like from our actual like AI sock analyst video, and I'll, I'll put this file in the description, or, you know, a link down below or something. Um, so you can just like download it if you want, but I'm just going to show you something like a real-world example of, um, how a list might be used. So this is actually like, or rather, how a for loop might be used. So this is like a big list of threats, um, that the AI sock analyst found, for example. And we can like, maybe after the code runs, after it did its whole threat hunt and and found them, we might do something like, you know, print out all the threats. So we'd say like, or threat in threats. We could say like, you know, print threat, something like really like simple as this. And we'd say like, print finished, just to show that our, our thing is finished. Something like, like this. And if we just run this, I'll just run it. And you see it just dumps like all the threats out onto the screen. And say we don't want to like dump the whole thing. Maybe we just want to like dump the threat title. So like this is a collection, right? It's a, it's a list of, uh, dictionaries, or a list of JSON objects essentially. So we know that there's like a title key with like a, the value key-value pair. So we, we know that there's a, a key called title. So we can like copy this. For example, I'll collapse this. We can say print threat title, like so. We can break this, start debugging, and we see it breaks, and we see the threat. You know, the threat, which is like our, we say the iterator. This is the thing that represents each individual item every time the, the loop runs. And inside each threat is like a full-on like JSON object, dictionary thing. And if I want to print the title, I can do like this. I can just say threat, and then title. So, and then it will print, and then it just prints the title only of the threat, for example. And these are like actual real threat logs. And again, I just want to say like, this, this is the iterator. It can be like literally anything, any easy variable. Um, it's just, it's like a placeholder. It's going to hold the value of each individual item that's in the collection, or in the list in our case. So, I'll run this one more time just to give you a sense. I renamed the thing to X, and see X, it just has the, um, the value of whatever these individual threats had in, in them. So, same thing, print the titles, like so. Yeah, that's lists. It's just, uh, or rather, that's for loops. Um, it just lets you iterate. We see like it lets you iterate over every item in a collection. Just like a really common collection is lists. So I just used lists for example on this. But we'll see this, um, a decent amount in the actual like production code I guess that we're going to make. Hope that makes sense. Um, feel free to experiment it with a bit, and then we'll see you in the next lesson.
Welcome back. Uh, this is going to be the lesson on functions. This is where it starts like getting kind of hard for people, but function is like integral, integral part of just coding in general. So you really need to like make sure you understand it. But, um, basically, um, a function is when you want to reuse the same code many times without having to type the same code out many different times. So I'll just like give you a really simple example. So this is like a really simple example. So the notation for how to make a function, you say def, and then I'll say like introduction. I'll just name it introduction, and then this is the indent. Um, everything that's indented under like after this function definition is going to be part of the function. So I'll say like, print hello, my name is Josh, for example. Print. My favorite food is cake. Print. I'm 67 years old, for example. And then now, now I'm technically outside of the function. So this, you have to call what's called call the function in order for it to run. So, for example, if I, I'm outside of the function now because I like erased the indent, I guess you can say, and I'll say in here, it's Saturday. So, and then if I just run this, for example, you notice it say, it only says it's Saturday. Like none of this other stuff happened because I didn't call the function. So to call the function, um, all you have to do is type, you just type the function name, b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b
returns a list. So if we want to print the second index of this list, we would do something. Oh, I mean to do that. We do something like this. It's like a bit confusing, but that's just like how it is. So let me do this just so we have something else. So I will start debugging this. It breaks. Then we, if we look at our list here, we see index number three is 0, 1, 2, 3, 4, 5, like so. 0, 1, 2, 3. This is our index three. And then if we get, we're getting index three from my list, which is this, uh, another list actually. And then we're getting index two from within this list. So that's index 0, 1, 2. So this should print three out. Should. And it does. And then finishes. So that's those are lists. Of course, you can do like a lot more with them. Um, we're going to, anyway, we're going to use these like quite a bit in the future, but I just wanted to introduce them and give you like a leg to stand on, I guess, when you start seeing like production versions of this. But yeah, that's lists and we'll see you in the next video.
So, getting into the next lesson, uh, this is where we're going to cover what's known as JSON, which stands for JavaScript Object Notation. It's just a way to represent, um, something in a nice structured way that the computer is, it's easy for the computer to parse out and understand. Um, it can be like a representation of like a real-world object, or it can be like, it can be literally anything, really. So, I, I went to GPT and I was like, "My name is Josh. I'm 40. I'm a cyber professional. I live in the US. I like these things. Uh, please represent me as a JSON object." And it built an object that looks like this. So, this is like a property. And then the value. The name, we'd say like the age property has a value of 40. The profession property has a value of cyber security professional. And then the locations, um, because I said I live in these three locations, it grouped them in a in a list or or an array. You can call this like an array or a list of like objects. So if you see, um, if there's like a group of like objects in in JSON, it will be formatted like like this. You'll see like a square bracket around it. And so locations because there's like three, like, you know, they're all locations, so it formatted them like this. And then the things that I liked, same thing. It's likes. So it formatted them all together in like a list like this. So pretty, pretty straightforward. Um, you can have like, well, you can get like really elaborate with this, which we will cover in the next lesson. And then I told GBT like, okay, create three more humans with the same schema. And schema just means like the way the data is formatted, or the format of the data. So, has me, Aiko, Marcus, and then Sophia, and they're all, they're all like the same format, you know, their loca, or their locations, their likes, etc. It's just a, well, it's just a way to format data. And we're going to get into this, uh, a bit more in the next lesson. By the way, I copied all this and then I created a variable called people and I just, um, assigned people this JSON object, and you can do that. So, for example, if I just simply print people like this, it will print that whole object out. The whole object with like everybody in it. You can see like Josh, Aiko, like Sophia, and everybody else. And this thing, this is actually a list, like it returned it in a list format. You can see like the outer thing is like a square bracket like so, because it's a list. So if I, for example, I collapse this, this is like one item in the list. This whole thing is like one item. So I can collapse it. This is another whole item. So, right, I can collapse this, etc. And if you remember, um, you can access lists by, so basically lists are ordered like from zero. So this is like the zeroth item, the first item, the second item, and the third item, and, or, or like the item at position zero. So if I say like people, uh, give me the one, the person at position zero, which is me, it should just return this whole thing. So if I run this, it will just print out Josh's stuff only. So, Josh, and then cakes, pizza, and sushi, like this. And this is person zero, right? So this is Josh. And if I want to get only like the name property, I can pick the per, the people at position zero, and then I, I can get like their name property, and it will, it should only print Josh, for example, like so. And we'll dive into this a bit more in the next lesson, um, where we talk about dictionaries, and I give some real-world examples of where you might see JSON like this. And dictionary, like, this won't make sense yet, cuz you didn't get to the dictionary lesson, but dictionaries are, are basically in JSON format. This is, this is basically like a dictionary. So, for example, this is the last thing I'm going to do. So, people zero. I'll print this again, just to like give you a sense. And you see it prints out this JSON object essentially, that is a representation of Josh. If we want to see the type for this, like what is it, we can do this. We can put it inside of this type function, equals zero, and then we run it, run without debugging, and then it tells us that it's a type of a dictionary. And the next lesson is on dictionaries. So we're going to like really dive into more depth on that. So we will see you there. That was, this was JSON objects or JSON.
Welcome back, and we're going to get into dictionaries in this lesson. And this is like getting like really real-world. After I do this, uh, simple example, I'll show you what like, you know, a real, like production dictionary looks like and how we're going to use it like in the, um, our project that we're going to do. But basically, um, just like a real dictionary, um, basically there's like what's called a key and then a corresponding value. So in a real dictionary, you'd have like a word and then a definition. Um, but in Python, this is called key, and this is called value, and then these things together is called a KVP, or like a key-value pair. So, for example, this is how you define a dictionary. Well, one of the ways that you can define a dictionary, it's called fruits, and then these are all the keys on the left side, and then these are all the values. So if I want to get access to like, if I want to access or change, um, this definition, or if I want to access or read the definition, this is how you would do it. Um, but I, I'll just like step through it and then explain it as we go. So I'll put a breakpoint here, and, um, by the way, I'll put a link to like this file. Um, there should be a link to that, or a couple files for this lesson. So you can just like either copy the contents or paste them in here, or you can put them inside of your code folder, like download the file into your code folder if you want, but I'll break this, um, start debugging, stops here, and then do this, and then I'll step over this, and then you see on the left, we can see our fruits dictionary, apple, like a word, and then definition, word, definition, etc. And then this is how to access the definition for apple, or yeah, the definition for apple, or the value of this key, like so. This is just the notation to do it. That's just how it is. Um, so you can kind of get used to it. I, I do recommend you like type this out to like get your muscle memory and stuff. Um, it help, it really does help a lot. But we'll, uh, step over this, and then we see it printed the definition for apple, sweet, crisp fruit that comes in red, green, and yellow, just like this. Like so. And then we're going, this is how you add a new fruit and its description. So this is like, uh, this is our fruit dictionary. And then this is the, this is the new key that's being added, and then the new value for the key, or like the new word in English, and then the definition of the word. So if we step over this, we see that grape gets added to the dictionary, like so. And then this is one way to remove a key, or a key-value pair from the dictionary. So if we run this, like delete space fruits mango, it should delete the whole key-value pair of mango and then this juicy tropical fruit. So we step over this. Oh. Oh. Oh, I accidentally, uh, changed the description of banana. So, let me just like, uh, rerun this. I skipped banana on accident. So, I'll break this here, and I'll just rerun it again. So, here we are at banana. This is how you change the value of something. So, if I expand this, uh, it's going to change the value of banana to a soft, sweet tropical fruit. So, right now, banana is a soft, sweet fruit with a yellow peel. So, if we step over this, we see that the value changes, like so. And then this is how you delete mango. I don't know how I managed to skip that, but, um, we will step over this, and then mango should disappear, and it does. And then, um, we didn't actually learn this notation yet. We'll learn about this later. Um, it's called string interpolation, or f-strings. But anyway, it's going to print each, for every fruit, it's going to print the fruit title and then the description out. So we can just like, we didn't learn about this like loop yet. We'll learn about loops later. So just like ignore this. I just got this example from GPT because it was like easy and made sense. And then we can see all the new values getting printed out like so. And then the program ends. So I'll do like a really simple custom dictionary, um, with like people's names and ages. So, um, we can say like, for example, uh, which I do, I'll say like person, I'll do person one, and then so say name, I'll just say no, I'll say people, sorry, people name, then Josh, no, okay, people ages, we'll do this, people ages. So I'll say Josh 40, Aiko 31, comma, and then Leia, I don't know, I forgot, 26 maybe, just two, and Jimmy, no, there's no Jimmy, I'll see, is I think 30. So if we, if we, if we want to see how old Josh is, we'd say like people ages, like so. And then we do, we'd access the person who we want to see. And we see Python's like autocompleting this for us. So if we want to do this, it will just simply, we run it, it will simply print Josh's age. It should say 40. Like so. So that's, um, that's dictionaries. It, it can get way more complex, though, um, which I'm about to show you in a second. So, go ahead and download this, uh, file called Big Dict. That stands for big dictionary. And what you're looking at here, this is basically like, um, an entire, uh, I guess it's called an entire threat. Yeah, it's a, this is a threat that was discovered by the AI sock analyst, and it will, it will output it in this like crazy, this like crazy format here. And this is, this is basically like one big dictionary, but there's like dictionaries inside of other dictionaries, etc. So, for example, just so you can believe me, I'll print type and then what did I call this thing? This should actually be called threat, threat instance. It doesn't matter, but that's, that's what it is. So if I print the type for this, I'll just run this without debugging. Oh, Python debugger. And then you can see it's class dictionary, cuz this, this thing is technically a dictionary. So you remember, dictionary is full of key-value pairs, essentially, like the, the word and the definition, or the key and the value. So what this is from, this is like a real, real-world thing. Basically, we're going to do this and learn about it a lot in the future, but we dump a lot of logs into chat GPT and basically tell it, or the GPT API, and we tell it, find the threats, and then it goes through the logs and then it will like correlate stuff and find something, and this is just one of the threats it found. It's like a, it's a dictionary object. But key, this is a key. And then the value, this is the key. This is the value. This is a key. And then this is a value. And you notice this value is actually just another dictionary. And then you'll notice this is a key. And then this is the value. But this value is just a list, or an array. It's a, it's a list. This is pretty standard. A key and a value. This is a key. This is a value. But this value happens to be a list, and it goes on and on. So if, for example, we're going to deal with like maybe a dictionary inside of a dictionary. So if we say like print, uh, oops, I didn't mean to do that. So let's look at this MITRE key. This is a, a key, right? And then this is a value. So if we, if we print, uh, threat instance, uh, MITRE, like so, I'm going to break this, save it, and then I'll run and then start debugging, and you notice like the threat instance variable over here, it's a dictionary, and you can see like all this stuff, and then this is the MITRE key, and then the value. So if we print this, like it is, it's going to print the MITRE, uh, value. So it, it should print this stuff, right? Just to get a sense for it. So if we step over it, we see that it prints tactic, initial access, technique, blah, blah, blah, sub-technique, which is this stuff right here. It just prints out another dictionary essentially. But for example, if we want to get access to like, what was the, um, you know, what was the description, the description inside of MITRE, like doing this just gets access to all of this, this whole thing, which is a dictionary. But if we want access to this, we have to use the actual description key inside of the secondary dictionary, like so, description. So if we run this, it should print the description for this, like so. And it does. And then I'll do one more thing, really, really quick. Um, so we, this is like accessing a dictionary inside of a dictionary. It's a bit like complicated. I, I know. Um, but that's just like how it is. So this time we're going to access a list inside of the dictionary. So this is actually a diction, this is whole thing is a key-value pair. This is a key. This is the value. Right? So we access, for example, recommendations. So if we just print this as is, or we run it, we'll stop here. Step over. It prints out monitor, [snorts], and pivot. And this is just a list, right? We learned about these a few episodes ago, a few videos ago. But say that we want to like access, you know, pivot, for example, we can do that. Um, but this is like the zeroth item, and this is the first item, or the first index, zero index, first index. So if you want to access pivot, we have to access the first index. So, so if we run this, print it, it prints out pivot. It reaches into, um, recommendations, and then we got the, uh, first index inside of recommendations, which is pivot. And it's a bit complicated, but I, re, I recommend you to like do some activities with this, like look at different values, I guess, and like try to print them out, like so, for example, like try to print this line out. This is a list, right, inside of the log lines key-value pair. So try to print out the first index of this, or try to print out this description, for example, and, or try to print out my email address. This is like a real log, by the way. Try to print out this email address because, um, when, if you're dealing with like APIs, or doing like really, like literally any kind of development that involves the web, or almost anything, you will be dealing with data in in this structure. So, it's like really good to learn how to parse it and like deal with it and stuff. And we're going to like be dealing with this a lot when we're actually building the, um, like the actual AI sock analyst, or however you want to call that. So it's really good to understand it, and yeah, that's dictionaries. Um, you can always like, you know, if you get stuck or have questions, definitely ask in the, the community area, or you can go to chat GPT. You can like literally dump anything into GPT and be like, explain this to me, like I don't get what dictionary is, or like, you know, you can talk to it and then get it to explain things to you in an easier way. But yeah, that's dictionaries. Uh, just try to acknowledge it and be aware of how to use it, and as long as it's not like completely foreign to you when you look at it, you're in good shape. But yeah, we'll see you in the next lesson.
Welcome back. Uh, in this lesson, we're going to cover what's called string concatenation. And concatenation just means like connecting together, like connecting something together. So, connecting strings together. And I'll try to, I'll give you like an example, um, um, of how to, how to do this. I guess that makes sense that we can like make use of some of the other stuff that we learned. So, we'll, we'll do a program. We'll say like, uh, not Josh. Oh my god. First name equals, and we're going to get input from the user. What is your first name? And we will, I'm going to copy this. This one will be last name. What is your last name? And then age, we'll say, how old are you? And then we're going to, uh, concatenate all of these. So we're going to say, we're going to print, and then we'll say, hello. So this is one string, and then if we want to concatenate, [clears throat] it, we can use a plus sign, and then we can say first name, and then we will concatenate more, like a comma. Oh, we'll say first name, and then sorry, we'll do a space. This is, sorry, this is like really troublesome, but it will make sense. Hello, first name, last name, and then we're going to concatenate. That's how you like connect strings together with like the plus sign. Then concatenate again. Oh, wait. You are base. We'll say age base years old, right? I know this seems like really arbitrary, but we'll take a gander at this. So, say this, and we'll break it here. Or maybe I'll break it here, and I'll, I'll just like let this run. So, we'll, we'll debug this, and the code's running. We say, what is your first name? Josh. Your last name, Matakor. How old are you? Six. And then the code, because we put a breakpoint here, we can see here, our first name is Josh, last name Matakor. Our age is six. And then if we run this, it should just like put all these things together. We run it, it says, hello Josh Mator. You are 6 years old. Right? That, that's just string concatenation, basically. Um, it's just putting strings together. And then in the real world, um, when we go to like build the, you know, the AI sock analyst, we're going, we're going to use this quite a bit. But one like really, like, um, main use case for it is, um, creating our prompt to send to the OpenAI, uh, API endpoint. Like when we're trying to do threat hunting, we'll, we'll have something that looks like this. Um, it will be like, uh, user, user desire, whatever, user desire, and then we'll have like a system prompt, and then we'll have, uh, like some logs, for example. So, for instance, instance, let me try to like do a real-world thing of this, one second. So, for example, um, I just, I'm getting some like actual live logs from the side range, a bunch of log on failures against one of our virtual machines. I like copied these. So, for example, we'll have something like this. Try to make this make as much sense as possible. So, this is like a way to do a block of string. So, I paste this like giant thing in here. This is like ton of logs, right? I just, this is a variable with like a ton of logs in it. So the user desire will be something like, um, um, we sus, you know, suspect a computer was exposed to the internet. We are worried, uh, it could have been breached, something like this, you know, a basic thing that we're going to ask the agentic AI, right? We, something's like wrong, can you like look into it and do a threat hunt, please hunt. And then this is where we would, we would provide like the system prompt, um, you know, that that would be like, you are an expert, you know, whatever, [snorts] expert, expert threat hunter, and an Azure and KQL god. Uh, please, you know, examine the logs and let us know if anything is wrong. Please cover MITRE, whatever attack TTPs, etc. Something like this. So basically, we're going to end up with like three strings, um, just the way the, uh, model context and protocol and like the whole agent works, and then we're going to have to like create like one, uh, basically large prompt, um, that we send to the, um, OpenAI, it's like the ChatGPT's API endpoint essentially. So, for example, my god, let me, so, for example, it, it will end up being something like this, um, you know, whatever message to send to GPT, not, not exactly like this, but pretty much, it, it's going to be a concatenation of these things. So we'll, we'll concatenate user desire with, uh, system prompt, and then with the logs at the end. Oh, yeah, this at the end of this, it will say something like, you know, please examine, oops, the logs below, something like this, and then this is the thing that will end up getting sent to GPT essentially, and then it will perform a threat hunt and then etc. So I'll, I'll just like run this, you know, just, just for fun. So, message to send to GPT. This is like the full concatenation of, we concatenated those three strings into this, and then this is what goes to GPT. And for fun, if you want, we can just copy this whole thing and we can go to GPT, and then this is like what will get sent on the back end to the API, like some, it looks like this. It's like some crazy, like big thing of text. It's not exactly like this, but it's like pretty close. And then it's like smart enough to like, you know, look through it and produce some kind of results. This is like really kind of like unstructured data and like a bit crazy, but I just wanted to show you like, um, string concatenation and how it's, and how it's used essentially. And there's like easier ways to do this, but yeah, I just wanted to show you that, and we will look at a more efficient way to do it in the next lesson when we cover what's called string interpolation or f-strings. So, we will see you there.
Welcome back. Uh, in this lesson, we're going to cover string interpolation. It's really similar to, um, string concatenation, but it's just like an easier way to, or more human-readable way to do it, I guess. So, uh, let's see if I run this. I'm just going to run this again, uh, without debugging, just so you can see the output of it. So, what is your name? Uh, Josh. Last name, Matakor. How old are you? Six. And then it prints out this thing like, hello Josh Mator, you're six years old, right? And if we want to do this with string interpolation, um, aka an f-string, it's much easier. And the notation is like a bit arbitrary, but it's just like this. You basically like just type it out. For example, hello. And then first name will go here. Last name will go here. You are age years old, right? Oops. Read. I don't know why I typed that. And then you just put the variables in here. So, first name, last name, and then age. Oops. Age. This is string interpolation. It, it's just like more intuitive to look at. Like this is quite hard to read, right? And you'll like mess it up with like spaces. It's just hard to deal with. But this one, it's easy to read. So, if we run this, um, I'll just run it without debugging. Or, yeah, and I'll use like a different name. Uh, I don't know. Uh, Sandy Wandy Wang. Okay. 90. It's the same. You see it prints the exact same thing, but this one's easier to read. This is like string interpolation. And the way, let me see, for example, um, if you remember that like long thing with like the prompt or whatever, um, where we have like, uh, you know, the user message, um, I want to do X, and then system, system prompt, or system message, you are a master threat hunter, blah, blah. Uh, use the logs below, and then the logs. No, uh, whatever random login data. It's a bit easier to like, um, do string interpolation with these, because you, you can just do something like this. Uh, master message, whatever, or combined message is a better way to say it. Combined message. You can do something like this equals, and you can do f-string, and then you can do like a triple quotes, or like this. You can do something like, um, it's like really like straightforward, say like user message thing, system message, and you would put like the logs here, like so. And then it's just, it's just easier to like look at and deal with, um, to be honest. And you can also do something like this. These are almost the same thing. So, for example, for example, do something like this. You put all these like even on the same line. And you can go back to single quotes. And then you just put like a, a line break between them, or a new line, something like this, like this. And then this is your system message. It's just like really easy to, to put it together. And if you print these, it should probably print the same thing. My message one, I believe, print one. Print two. And I'll just, uh, run this without debugging. It should print like, you know, it prints the same thing. So it just makes it easy to like put strings together without like using the plus sign and like all that like crazy stuff, if that makes sense. So string interpolation, aka f-strings, it's just like, you know, you have a string. I'll do something easy. Cat, dog, name, Jane. You just have a string, right? You can have an empty string, put an F in front of it, put the curly braces, and then you just put the variable in that you want to like combine together. So, and then I, I'll break this and then I'll, I'll end the lesson. So, cat name, Jim, dog name, Jane, combined names, it's just cat name, base, dog name, and then prints the combined names, and Jim, Jane. But yeah, that's, uh, f-strings, string interpolation, and we'll see you in the next video. And this is used like a lot in the real world, and for sure you're going to see it when we get there, and you're going to be like, okay, yeah, I, I learned what this was. That's the whole point of this. Again, I just want to remind you, I'm not like, we're not trying to become like fang engineers or something like this. I'm just trying to get people to like the level, or get you to the level where you can like recognize and interpret code, and then change it. You know, you can change it, um, if you want to change something. Like someone who doesn't know how to code anything, like they've never seen Python before, and if they look at this, they, they won't know like what they're looking at. But you, at least now you have like some idea, like you know what this is, and like if you want to change what gets printed out, you have some kind of idea, like maybe you want to change one of the animals' names, or you want to have like more spaces, or like a line, you know, a line between them, um, or something like that. So don't get like discouraged or anything. Um, I'm just trying to, we're just trying to build like a general intuition and be able to recognize patterns and stuff. But yeah, we'll see you in the next lesson.
We'll come back in this lesson, and we're going to cover what's called for loops. Um, a for loop is basically just a way that when you have a collection of things, for example, like a list, it's a way that gives you a chance to do something or interact with each item in the collection, if that makes sense. It will make more intuitive sense once we actually run the code, but, um, here's a list of things. We learned about lists, uh, recently, and it gets assigned to this variable, and then this is the actual for loop, um, how it's structured, and then, you know, the code ends here. So we'll just run it, and I'll just kind of explain things, um, as we go. So I also, I also made the screen a bit bigger, but it made my run thing inside of here. So I have to like, you know, go in there, but we see the code breaks here, and then if we step, our fruits has these inside of it, and then this variable, this is like a placeholder variable. It can be anything. Um, but the way it's like the grammar syntax is like, for x in whatever your, uh, collection or your list is, and then it will give you a chance to like print out every single thing. So, for example, if we step into here, we notice that the variable fruit, that is this, it got assigned the value apple, which is this. And then we print it. I like apple. And then it goes back up here. And if we step again, now the fruit is assigned banana, which is here. We step, it will print banana. Step again. And now finally, fruit got assigned cherry. And then we step. It prints, I like cherry. And then it finishes. It gets out of the loop because it, we say iterated, but it went over each of the items. And now the program ends. And, uh, this, like I said, this variable is arbitrary. It can be named anything. So, for whatever in my list, uh oh, for whatever in my list. So, for example, I can make this like, you know, some, some arbitrary, like variable, like so, it can be anything, right? So if I run this, the same output happens. I like apple. I like banana. I like cherry. Like so. That's pretty much, that's pretty much all it is. Same thing. I just want to show you that this variable is arbitrary. Um, see, one, two, three. It can be anything. Boom. Debug this. And we can, this is why debugging is so important when you're trying to get an intuition for things like loops, like how it works. It's basically like going over each one of these items in the list, and it's giving you a chance to to do something with it, right? But for example, um, to add a little bit more logic in here, we can say like, you know, this is like really contrived, but I'll put this back to, I, I'll say f. This is also like a common practice to do. But we can say like, um, we can say if does not equal apple, for example. This means does not equal. We can say print f, something like this. So, for example, debug this. And then for f in fruits, f gets assigned, uh, apple, which is the first one. We can say if f does not equal apple, we're going to print the fruit. We're going to print f. But it does equal apple. So this actually gets skipped the first time. And then we can say like, continue to just finish the rest of the program. And you can see that it printed everything out except for apple, as we just, you know, decided to not do it. This is some like really arbitrary logic. But for an example of how we are going to use this, um, when it comes to our AI sock analyst in like the real world, um, we might have something like, uh, for example, for example, actually, I'm going to, uh, format this. By the way, I'll, I'll put this, uh, in the link, this, this file, so you don't have to do all of this. I'll format document. Oops. Format document with black formatter. Oh, can you like cut this whole thing out? Who, who's ever editing this? Let me set this up. Okay, you can like start recording again. Uh, so another example of how we might use this. Um, this is like a big list of threats. This is like from our actual like AI sock analyst video, and I'll, I'll put this file in the description, or, you know, a link down below or something. Um, so you can just like download it if you want, but I'm just going to show you something like a real-world example of, um, how a list might be used. So this is actually like, or rather, how a for loop might be used. So this is like a big list of threats, um, that the AI sock analyst found, for example. And we can like, maybe after the code runs, after it did its whole threat hunt and and found them, we might do something like, you know, print out all the threats. So we'd say like, or threat in threats. We could say like, you know, print threat, something like really like simple as this. And we'd say like, print finished, just to show that our, our thing is finished. Something like, like this. And if we just run this, I'll just run it. And you see it just dumps like all the threats out onto the screen. And say we don't want to like dump the whole thing. Maybe we just want to like dump the threat title. So like this is a collection, right? It's a, it's a list of, uh, dictionaries, or a list of JSON objects essentially. So we know that there's like a title key with like a, the value key-value pair. So we, we know that there's a, a key called title. So we can like copy this. For example, I'll collapse this. We can say print threat title, like so. We can break this, start debugging, and we see it breaks, and we see the threat. You know, the threat, which is like our, we say the iterator. This is the thing that represents each individual item every time the, the loop runs. And inside each threat is like a full-on like JSON object, dictionary thing. And if I want to print the title, I can do like this. I can just say threat, and then title. So, and then it will print, and then it just prints the title only of the threat, for example. And these are like actual real threat logs. And again, I just want to say like, this, this is the iterator. It can be like literally anything, any easy variable. Um, it's just, it's like a placeholder. It's going to hold the value of each individual item that's in the collection, or in the list in our case. So, I'll run this one more time just to give you a sense. I renamed the thing to X, and see X, it just has the, um, the value of whatever these individual threats had in, in them. So, same thing, print the titles, like so. Yeah, that's lists. It's just, uh, or rather, that's for loops. Um, it just lets you iterate. We see like it lets you iterate over every item in a collection. Just like a really common collection is lists. So I just used lists for example on this. But we'll see this, um, a decent amount in the actual like production code I guess that we're going to make. Hope that makes sense. Um, feel free to experiment it with a bit, and then we'll see you in the next lesson.
Welcome back. Uh, this is going to be the lesson on functions. This is where it starts like getting kind of hard for people, but function is like integral, integral part of just coding in general. So you really need to like make sure you understand it. But, um, basically, um, a function is when you want to reuse the same code many times without having to type the same code out many different times. So I'll just like give you a really simple example. So this is like a really simple example. So the notation for how to make a function, you say def, and then I'll say like introduction. I'll just name it introduction, and then this is the indent. Um, everything that's indented under like after this function definition is going to be part of the function. So I'll say like, print hello, my name is Josh, for example. Print. My favorite food is cake. Print. I'm 67 years old, for example. And then now, now I'm technically outside of the function. So this, you have to call what's called call the function in order for it to run. So, for example, if I, I'm outside of the function now because I like erased the indent, I guess you can say, and I'll say in here, it's Saturday. So, and then if I just run this, for example, you notice it say, it only says it's Saturday. Like none of this other stuff happened because I didn't call the function. So to call the function, um, all you have to do is type, you just type the function name, b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
going to like combine them into a variable and then return that variable. So, uh, we'll call it sum of our numbers equals and I'll set this equal to num one plus num two. And then we'll return this of our num like so. And then we will we can say we can call it um, and we can return the value and put it in a variable and then print it. And I'll I'll show you like what this means. It it's a bit complex and it takes some time to get used to, but anyway.
So we'll just make another variable called our number. And then this is how you do that. You say equal addition. And then we would pass like some value to number one. So 50 and then some value to number two. Uh something easy 25. So then we can print our number. And this is why debugging is like really important because you can see the flow of everything that's happening. So I'm going to break this, save it, and then we'll run the entry point.
So basically I'll explain what's going to happen like this this function will call like so and then the interpreter goes up here. Now we see number one is 50 and number two is 25 because we passed 50 into number one and 25 for number two. So when the code is executing in here we can see these are the the values and then these are going to get added and then put into some of our numbers. So if we step over this, we see some of our numbers as 75. And then when this code executes, it's going to return this value to here and assign it to our number. So if we click this, we see like the return is 75. And then when we step, we see our number gets assigned the value of 75. And now it's just going to print it to the screen and then the program finishes.
So I'll do this like many times so you can get a sense. One one 3 five six. So I'll break this run debug and then we can like slowly step through and just try to get a sense of like what's happening. Oh um well it's okay. I I this this variable is going to get overwritten every time but that's okay. So if we step into this see number one is 50, two is 25 because we passed it into here. They added some of our numbers is 75. It gets returned. And now our number is equal to 75 currently. But now this function is going to call again. If we step into it, we now see number one is 51. Number two is 21 because of this. Add them up. 72. We step 72 gets returned. So 72 is getting returned. Our number is still equal to 75 or rather it still has 75 in it from the previous function call. But if we step it's going to 72 from this call is going to get assigned to our number which was just what happened. If we run this third third one you can see these got passed in they get added up to four. It gets returned and then our number is still equal to 72 but once we step now it's equal to four again. Then the last one's going to call. See this get changed. They get added up to 11. Gets returned. Return is 11. Now it's going to overwrite our number. It's going to store 11 in our number. And then it's going to print 11 to the screen like so.
Yeah, that's functions. Um, pretty basic. There's a a bit more of course that you can do with them, but it's if you can like get to this point where you can kind of understand what's happening here, you're going to be in pretty good shape. And the way I I personally learn coding, I I have like a I'm pretty certain I have like ADHD and like probably like a bit of autism. And I don't learn coding very well from those like theory and like rigid like definition and stuff. I learn it more based on like pattern matching and like if you do this then this will happen and if you do this then this will happen. So that might help you if you if you want to think about it in that sense. Um it may help. I don't know. Um but functions um functions are used like used like quite a bit. Like we might do something like um I have like a an deck or I have like some code that creates flash cards. Um well that's probably not a good example. you can erase that.
So, um, we're going to probably use some code in the future, um, where a function is something like I'm not going to actually write write the function, but it's called like a ask chat GPT and then you would pass like a the prompt into it like this and then there would be some like um I'm going to put a comment uh some code that reaches out to GPT and asks a question question and then GPT will like return the answer or whatever. I'm just going to put like GPT's answer something. I'll put a string interpolation. So I'll put like prompt prompt and then I'll do a new line and then I'll say like GPD's answer maybe GPD answer like XYZ whatever and then you would call this by like you know you'd say like Um my question you can do something like this for example my question input uh what would you like to ask chat GPT for example something like this and then we can say like uh ask chat GPT call our function and then we would pass my question into here like so like So, and we'll we'll run this so you can get like a sense. Um, normally there'd be like a bunch of code in here that, you know, reaches out to GPT and all this stuff, but I just want to like show you something. Oh, yeah. I got to return this too. I forgot. Okay. So I question question thing is and then we would say like um I'm inside a v a VM right now so like the the it's like really slow and like troublesome. Um, okay. Like this. We say print answer like so.
So, I'll just kind of explain this as we do it. I'll I'll run this through a couple times so you get like a sense. So, we start debugging. We'll break here. Now, I'll step over this. What would you like to ask Chad DPT? Uh, what is the I should have This is why it's kind of important to do the back slashn here cuz you see it's like typing on the same line. It's like a bit annoying. I'm going to re re rerun this. I'll step over this. What would you like to ask Chad GPT? What what is the best cat breed in the world? And then you see my question gets what is the best cat breed in the world assigned to it. Then now we're calling ask chatb chat GBT and we're passing this what is the best cat breed in the world inside of it which is my question. So when we step into the function we see that the prompt now has the value what is the best cat breed in the world like so then you know some code happens etc. And then chat GBT like comes up with an answer. But in the answer um I just simply like put the prompt again. And then I just made up you know answer is XYZ cuz we didn't really ask Chad GPT. And then the answer will get returned like so. And we can see we can see what the return value is. And then there's no answer variable here yet. But when we step answer gets assigned to the prompt. Then chat GPD's answer. So if we step over this, it will print and then the code will finish. So prompt what is the best cat breed in the world? GPD's answer XYZ. And probably we probably don't necessarily need this just for like readability.
So I'll I'll run this like one more time then we can end the lesson. So I debug I step into this. What would you like to ask chat dbt? Um oh no which watermelon breed is the best and we see that that question which watermelon breed is the best uh it gets passed to chat GPT um you know pretend that we use our prompt um to ask Chad GPT the question the prompt gets assigned this the answer we'll get you know this from Chad GBT the answer is this and then gets returned. We see that return is this GPD's answer is XYZ and then we see that it gets assigned to answer and then answer will get printed out GPD's answer is XY XYZ.
So that's functions. Um, we'll see we'll see like a ton of this when we actually get into the code like the AI socket analysts were making. Hope it makes sense. Um, it's really really important to understand these just just in general. Um, it's integral for like any kind of development at all. So if you have questions go to you know the cyber range community or you know the community wherever you happen to be ask questions for the community members um use chat dbt to like help you understand it um help you explain things maybe give you some more examples. Um, yeah, we'll see you in the next lesson.
Welcome back. Uh in this lesson I'm going to talk about uh built-in modules. It's basically um something included in Python that you can import uh into your code um and just like use it to do certain stuff with. So for example um to do it you just use like the import command and then whatever the name of the module is that you want to import. And there's like a ton of these by the way. Um, you don't need to like memorize all of them. Even off the top of my head, I can only think of like two or three for some reason, but there's like a ton of them. And it's just like extra code that you can import to do stuff with. And I'll show you how to like um create like a custom like local module in the next video, but just like get it try to just get an intuitive sense for what they are and how to use them.
So, for example, you can do different stuff with this. Um, you can you can like um pause the flow of code, for example. So, for instance, uh I'll say I'll just print a bunch of random messages. Um, I don't know, hello. Something like this. And if I do this, you know, I'm not going to debug it. I'll just run it. Run without debugging. And you'll see that it just like dumps hello on the screen, right? But with the time module, for example, you can say stuff like time. for example, and then however many seconds you want the program to pause. So, for instance, copy this and do this like just a few arbitrary times in here. I'll I'll do 1 second, maybe sleep for 3 seconds, 2 seconds. Yeah, 1 second for that one. And then, I don't know, 5 seconds. No, 3 seconds. Okay. And then if I run this um it will run. I'm not debugging, right? And you can see that it it prints. And then you can see it's like kind of pausing for a few seconds and it prints a three more pauses a bit. Um, cuz I'm using like the sleep module to like pause the flow of the code. Um, if this makes sense. It's just like something you can do. The the point of this lesson is you can import stuff into your code and then you can do um like extra functionality without writing the code yourself if that makes sense.
So if I like delete this actually um you see that like it becomes like a a syntax error or some kind of error and if I try to run it um it won't you know it it won't work. It will say time is not defined. Do you did you forget to import time? And you can like um hover your mouse over this and you can say quick fix and then you can say like add add import time and then it it fixes them all. And there's there's some other ones too. There's like um random believe. So, if I have like a list of like, you know, best animals, I'm going to have to use GPT to like do this. But cat, dog, fox, arm, owl. I believe you can do like um like the best. I think you can do you can do like random and then Oh, choice. Okay. And then you pass in like the the collection of the stuff you want to choose from like so. And then uh I'll just actually I'll just do this single best animal. This makes more sense. And then I'll just print it. It's not what I did. So So I'll break this and we will debug. And we can see um this random which is this. It's a module. So if we step over this, we see our best animals. Cat, dog, fox, bar. And then I believe this this will just like randomly pick an animal from here. I believe random choice uh dog. Dog got assigned a single best animal. And then it will print out dog. And you can you can do like randoms for um picking like random numbers too. Like if you want to like pick a random number for something. And just to show you that this is random, I'm just going to print the same code many times. And it's probably going to pick a different animal or, you know, it's going to pick a random one. So I'll just run this without debugging. Oh, my mistake. I I was supposed to like print these actually. Hold on. do this. Oh, and then I'll just run this without debugging like this. And then Oh, that's so interesting. Cat, fox, farml. Oh, yeah. Yeah, it's it's relatively pretty random. I thought that was like less random, but let me do this a bunch more times. Yeah. And it see how it's like kind of irregular in the order uh in which it shows the different animals cuz it's like randomly picking them, if this makes sense. But yeah, that's pretty much all I wanted to show in this one. I just wanted to like make you aware of um the existence of modules. And there's we're going to be using like a ton of like just a ton of modules and then making our own modules as well. And there's even like a there's like a open AI module for like dealing with chat GBT and like there's just literally modules for for everything and just got to get used to using them. um they just extend the type of code that you can do and allow you to do different things. But when we actually get into building the agent, um you'll see examples of different ones and then at least you'll know like what you're looking at instead of it just being random code. Um, but yeah, we'll see you in the next video where we we make our own custom module and then use that a bit. So look forward to that.
Cool. Welcome back and we're going to create our own custom module uh in this lesson. So clear this and let me think I'll do something like really really simple to start. So this is main this is like our main um you know our main Python code I guess. So in the code folder go ahead and create like a new uh file. We'll call this keys. py keys means like passwords. Oh my god. keys. py and then inside of keys. py we'll create a variable in here all uppercase um my password and then when you do all uppercase in python it it means that this value is not supposed to change. We call it a gosh I think it's like no don't quote me on that. I I think it means like a um let me Google what does all uppercase in Python denote I want to say like static variable but um I think That's correct. Oh yeah, it's not supposed to change. Yeah, I think that's what I said. So it's not supposed to change. So this is just a variable, right? But it's like a password, right? Cyber lab 1 23 for example. Just for example. And then so we made a module called keys. So we can say like uh import ease like this. So, and then we can say like print ease dot my password. You see this comes out. And then if we run this I'll just yeah I'll debug it. So if we run this and then we say step into it just simply prints out the password like so. even though like there's no CyberLab 123 over here, but inside of keys, it's here. And then we imported the keys module and then we're able to like print this out. And this this doesn't have to be like capital capitalized by the way, but it's like a convention when you like define some variable, it's not supposed to change. So if you can say like, you know, um I'll change this little password and I'll do like my VM I just want to show you that it doesn't really matter, you know, if it's like uppercase or not. It's just like a convention. My virtual machine password. We'll call this one like lab user, you know, some characters. And we'll save it. And if we go back to here, we can print out keys do my Gmail password. Can print out keys do my VM password. So, and I'll just run this without I'll debug it bug. And then we can see it prints cyberlab 123 and this prints lab user blah blah blah. Um, and something you can do in VS Code like you can drag this window to like the edge so you can kind of see both. It can be a bit convenient. Um, if you want to see what's inside your module or you want to see more than one file at the same time.
So, for example, let me like get rid of these. And you can actually um I'm going to rename this. Um, no, I'll I'll leave it the same name. So, I'll save this this. And then you can put more stuff inside of here that's not just like um variables, right? You can put like a whole function inside of here. So I'll say like definition um I'll call this uh m multiplication and then number one two and then I'll just say like uh product equals number one times number two and then we'll return product. So, I forgot this. Uh, I'll rename this keys actually to math. I'll I'll rename it to new math because there's actually already a math function. So, I'll call this like uh new math something like this. And then you can like import new math like so. And then I can say like uh my number equals and I can call new math dot. This is how you like get the access to the the function inside and you would say like num one equals um everybody knows what's not maybe not I don't know uh two * 3 is so number one all set is two and then number two I'll set number two is four like So, and I'll do this like a few times. So, I'll like paste this a couple times. One and three, five, and six. I realized that I was not putting spaces here. It doesn't matter, but just for readability. So I'll break this here. I'll save it and I will start debugging breaks here. And then if you step into this, you can see the code actually like goes to the other module and you can see it doing stuff. So and you can see the local variable number one is equal to two which is this. Number two is equal to four. This got multiplied and product is equal to 8. And then eight is going to get returned. We can see I'm going to make this uh I'm going to make this like a bit smaller so we can like see. Sorry. And we can see uh 8 got returned. And then if we step we see my number is now equal to 8. If we step into this one, new math, right? Multiplication. New math multiplication. And then it's adding. It's going to, you know, do its thing. Multiply the numbers. Product is equal 1 * 3, which is three. Return them. We can see three got returned here. And then my number is still equal to 8. So if we step into this, um, it's now equal to three. And then, you know, I'll just continue the code. So, and then it finishes. We didn't print anything out in this one. We just simply like were inspecting them in memory.
So this the whole like reason for this is it will like kind of clean up your code and then make it more modular. I guess that's why they're called modules. But in in real life um you're going to end up having like a lot of different functions and the functions are going to have different functionality and it's just going to end up being a lot. So, it tends to make more sense to put like certain code in their own uh in their own modules and then just call the modules in like your main uh your main Python file, I guess. So, it it's just more easy to read and it's more easy to like digest and look at and it's easier to change stuff.
So, that's modules. Um, we're going to use both the built-in modules like for example uh time or not time, yeah, time and then math. There's actually a module called math. Um, it's built in. So for example, if we say print like math um I think we can just say like math.py, right? And it it will just print pi out for example like so. It printed pi though. And then there's also math square root which is square root of uh 9. 3 * 3 is nine, right? So it should print out three. So, um, there's a lot of like built-in modules like this, like a ton of them, and then we're going to use them, um, in like the AI sock analyst code where we're building that thing, but we're also going to create like a ton of our own like custom modules as well. So, I just wanted to expose you to them just to like give you an idea so when we actually get to that and start dealing with it, at least you'll have like some kind of understanding on it, understanding of it. But yeah, that's modules uh built-in modules and then custom slash uh local modules as well. So yeah, we'll see you in the next uh lesson.
Cool. Welcome back. Welcome to the lesson on error handling. I just want to show you like what's possible. You don't have to memorize all the syntax and everything, but I just want to give you a sense for what it is and why you might use it. So um basically error handling is a way that lets you to gracefully manage something when an error happens uh in Python or like any any programming language. So for example, if you remember, we can do things like this. Um, we can say like um my number my [snorts] number equals um 10, right? This is like an integer or a number. But if we do something like this, my number equals 10 and then your number equals 20. We can't do like new number equals my number plus your number because my number this is a string. Your number is a an integer and you can't add like a string with another number. It like doesn't make sense to Python. So for example, if we Oops. We try to do this. I'll break this and I'll just step through it. So, we'll get uh we get this big scary like red error thing uh where it's like exception has occurred. Type error uh can only concatenate string like not integer. Basically, it's saying like you can't add up a number in a string cuz it like doesn't make sense. But, you know, we can do something like this. Um, see my number, we can we can cast it. For example, just as a reminder, if we just like run this, I'm just going to run it. We notice it. It works, right? So, in order to like um prevent I'm going to run this again. In order to prevent this crazy thing from happening or like this like these errors and like having the program crash, we can use something called like a a try accept a block uh and it gives us an opportunity to like catch any errors and then let the program complete um without crashing essentially. So basically it just looks like this. we'll use like try and then we like indent these and then we'll say like accept and then you we can put more in here but I'll I'll show you that later. Accept. And then this is what you want to happen um if an error occurs in here. So maybe we want to print something out to the um to the to the user like an error happened. Uh try again something and then we can say print finish say in as usual and then if we run if we run this. So we see my number your number and then it's going to attempt to do this stuff. So, and then it it couldn't do it because an error happened cuz you can't add a number in a string. So, instead of printing this, it immediately went into the accept block. And then it's going to print out an error happened. Try again. And then the program finishes without like crashing. Um, our action didn't happen, but the program like it didn't crash like so. An error, it just said an error happened instead of showing that crazy red screen. Um, so if you want to display like exactly what the error was we can say something like this. So we can say except exception as and then this this is just some random variable. So we can say like I just want to show you you can put anything here in this variable and then this thing will store the exception information. So I'm going to use a string inter interpolation here and I'll I'll say like an error happened and I'll say like uh new line so and then I'll put the giraffe. This giraffe stores the error information. So for example and run this. I'm just going to uh I'll debug it so we can really see. So step it's going to try to do this impossible action failed. Now we see that giraffe contains the error information. You can only concatenate string not int to string. So and then you see that it it prints out and then the program finishes like so. So this can be like kind of useful in certain ways. Um, for example uh say instead of like hard coding uh these numbers in here, we can say something like uh I'm going to like do this. We can say this is going to be get like a bit complicated. Um, but we can do like a an infinite loop while true. And then we're going to indent this stuff and put it to put it inside of the loop like so. And then for my number, we can say like uh we'll say my number. This is going to get a bit complicated, but I'll step through it and then you can like understand the logic behind it. So my number equals input uh please enter a number like so and then uh we're going to number my number or we're going to cast this to an int. So, cuz when you do this, it's always going to be a string. This will always be a string. So, we have to try to cast it to an int if we want to add it with your number, which is also an integer. And then we're going to print it out or we're going to say, you know, I'll use an F string. You uh rather Yeah. Yeah. Okay. Here we're going to print it out. Our oops our combined numbers just something really simple. And then uh we have to well I I'll I'll show you something. I'll just run this as is now or no. Okay. Or and then when we're done we're going to use break. And break is a way to force yourself to like get out of the infinite loop, right? But if the person enters something in here that's not a number, it's going to attempt to cast it into a number. So for example, if they enter cat, it's going to try to turn it into a number. It's going to fail. It's going to output the error to the user. And then because we're in an infinite loop, it's going to prompt the user again for their number. And it's going to keep going until they enter something that's correct. Like this line will pass, the number will print, and then the loop will break. So I'll just like uh run this and you'll see like exactly what I mean. This is like this pattern is used quite a lot. Um, it's used quite a bit in in programming. So your number is 20. We hardcoded this. I'm going to pull this out a bit and then we're going to enter this infinite loop and then it's going to try and then it's going to ask for our number. Please don't enter number. I'm going to enter I'll enter 10. I'll do something proper just just to so you can see it. We enter 10. It makes the new number by adding 10 to 20 which is 30. it prints it and then it will break which breaks the loop and it will automatically go outside of the loop like so and then the program finishes. So let's try to run this again. Uh, but we're going to enter something that's not a number. So I will I'm going to enter the word cat. This is not a number. So we try to step over this it fails and goes into the exception block and it prints error to the screen. Invalid literal. You can't like convert cat to int and then it go it just goes back into the loop again. It accepts and then because this whole thing is inside of the infinite loop, it will just keep going forever until we can like pass this stuff and then break and then get out. So for example, I'll just uh step this step. Please enter a number dog. It tries to cast dog into an integer. It accepts or fails, prints the failure, and then just keeps going forever and ever like so. Please enter number and then finally if I if I enter like 88 for instance that is a number so this passed now it's going to print it and then it's going to break so it will get out of the loop like so yeah this is this is used like this pattern is used quite a bit I I use this too um I don't want to get like too complicated or anything but basically and I do want to say like one final thing you don't have to like memorize this just like I guess understand what I'm saying and acknowledge it. There's like a lot of different uh exception types and the very like most generic one is just called exception. So for example um I will let me see what's the best way to do this. Um, okay for example I'll like erase this and then uh we can say uh let's see we can say I'll just okay I'll just print like 10 / 0 for for example and then I will run this and then this this is an exception zero division it's It's like a special it's like a very specific exception versus just like a generic exception. So for example, if we say like um we can say try oops try um print oops print 10 / 0 having a hard time. And then we can say except zero division errors specifically as and then I'll before we had giraffe here. Um, but the the normal notation for this is is e I believe is the normal thing to do. Then we can say like uh we can just print E for instance for example. And then if we I will I'll debug this and then it's going to try to do this. It it hit a zero division error. So it went directly into this block and then it's going to print the error out division by zero. And then I think we can do like something like this like a generic one. Uh, actually let me let me do this later. And then I'll try to do another illegal operation in here. I'll print a dog + 10 for example. And then I'll try to I'll debug this actually. Sorry. Let me let me put this first. Let me restart this. So, it's going to try to print dog + 10. And then actually there's no um there's actually we're not catching this specific type of error. And this type of error actually it's called type error. Oddly enough, we're only catching zero division error. So, I just want to I want to show you the fact that you can catch like really specific errors or you can just catch like a general error. So for example, this will be a bit confusing but just like bear with me. We can we can put like a a different exception. So for example, we can accept this is like generic exception like any error will any error that's like generic or that's not caught above it will fall into this category. So for example, we debug this And then it will try to do dog + 10 that you can't do that. So an error happened. So now Python is going to start checking the different exceptions that we have like provided it. So it checks a zero division error like this. It doesn't match this cuz it's not a zero division error. But just plain old exception will accept any any type of error like whatever causes an exception or an error this will get triggered etc. But if we want to like specifically catch this type of error we can say for example accept uh oh I forgot what this I forgot what the error was called. Let me like let me just like run this code again so I can see what it is. I'm just going to run this so I can copy the error type. Um, oh it's type error. That's right. Type error. Okay. So if we want to catch this specific error type it's called the name of it is type error like you can see down here. So we can say like accept type error as e as well. And then the the whole point of this is like we can we can do like some specific thing if a specific error happens or we can say some specific thing to the user like uh you know you can't add and or concatenate those things. And then this zero division error we can say like if we want to we can say uh didn't you learn in elementary that you can't divide by zero? It gives us a chance to like do something specific for every like type of error. And then for this generic one like and this is a scenario as a programmer where we don't actually like know what else could possibly go wrong but just in case it does we're going to like catch it here. So we can say like uh unknown error occurred. So if if you've had to spell occurred. Oh my god my spell check has like ruined my life. But if you've seen those like errors in Windows where or whatever that's like an unknown error occurred. Is there two Rs in this? Oh my god. I think there is. It looks dumb. Whatever happened. Okay. If you've seen if you've seen this in Windows, it usually means like something unexpected happened that the developer didn't even like anticipate, but they they caught it anyway with like a generic exception. So, we can do this like so. Then we can uh run this. So I'll try to think of something to trigger this. Oh, I have a good idea. Okay, so going to try to do this dog + 10 that makes an error. So it starts checking the different exceptions that match it. Type error matches it. Okay. So then it will like print that stuff. you can't, you know, it will print out our custom message and then it will print out the the error object. So, another error that we can do is I'm going to import JSON JSON module and then we're going to try to like load some invalid JSON. So, uh I'll I'll just say like my object equals JSON.load JSON.loads loads uh blue whale. This is not a JSON object, so it should crash. So we'll run this. [snorts] Then we will step and then it's going to try to load this into a JSON. It immediately accepts uh it through an error. So now it's going to start looking for which error type it matches. it it couldn't find any here or here. So, it just went to here. Um, this is like the generic one. And then we're going to say an unknown error happened. And then accepting value line one. It doesn't it doesn't really like say anything actually. Let me look inside of this error inside of this E variable because I don't remember like actually what's inside it. Exception is E. So, we're going to look inside of here. Uh, oh. Yeah, that's that's not even very much stuff that's in there. Okay. So, if we want to catch this specific uh this specific error, I'm going to like crash the program on purpose and then see what error it throws. Like so. I'm just going to start debugging this. Oh, it's going to it's going to run. Okay. Okay. It's going to throw an error here. So if I step um this is the exception that threw JSON decoder error. So we can copy this and we'll end the program and then I'm going to accept a new one. So I'll say like uh accept JSON decoder error as E. Then I'll say like print your JSON string was not valid. And then maybe I want to print the the actual error out as well. What's wrong with this JSON decode error? I wonder if I have to do like That's interesting. I had to like pull this out of this library. Uh, oh. Okay, good. So, I will move this back into here. These are like three illegal options so far. We're going to try to load some invalid JSON trying to uh, you know, add dog + 10 and then try to divide by zero. And then I'll show you what like the JSON object like is supposed like a valid one just so you know my valid JSON my valid object JSON loads. This would be like a valid one. We can say like um oops we can say name name animal name colon blue whale. So we're going to run this again. run start debugging. I'm going to do like one more example after this just to like hopefully it helps and then this is a valid action or it should be anyway. Oh, it wasn't. What did I do? Animal name blue whale. Why is this Why is this not valid? Hold on. Let me let me This is a I'm going to leave this in. It's like a good lesson, I guess. So, I'm going to say [snorts] I'll just say like, yeah, what's wrong with this? Oh, I guess I reversed the quotes. I didn't know that was like a problem. So, I'll just like copy this. Oh, yeah. Maybe. Oh, I guess I did. I guess I did know that. So, I'll like paste this in here. And I'll just like run this again. The the quote on the outside, I guess, is supposed to be a single quote, I suppose. So my valid JSON object, this one's real. This syntax is correct. But this one uh is not this is not JSON string. So it it can't load into JSON. So an error happened and it's going to start checking the different error blocks for like which one matches. And then found that JSON this this is the same error that through here or that happened. So now it's going to print this stuff out. Your JSON string was not valid. uh expected whatever expecting value blah blah I don't know like this is like really poor um messaging but at least we able to do like a custom message based on the error that happened so maybe like the user can can know right and then I'll try to do like one more thing um I'll make a a dictionary here I dict dictionary uh and then we're just going to like um name Josh uh height 183. This is a valid dictionary, right? And it has you know has the keys the key value pairs of key name value height or sorry key name value Josh key height value 183. This is 6 ft if anyone was wondering. And then that that's all we have like name and height. So we're going to go in here and [clears throat] we're going to try to print uh we'll print uh my dictionary name and then we're going to print my dictionary a uh yeah age. So name is inside of here, but age is not inside of here. So it should throw an error as well. So we're going to debug this again. And you see my dictionary here, name Josh, height 183. So we're going to step into here. We're going to try to print out my dictionary name. And that should print what? Prints Josh. And then we're going to try to print my dictionary age. There's no key in here called age. So naturally it throws an error and then it's going to start checking for like if we tried to handle that specific error and we didn't. So it just goes to the exception block like the generic error handling block says an unknown error happened and then it just like prints out age I guess. So if we want to like handle this properly um we got to see uh what the actual error is called. So for example, we'll take this and then we can just do this like so and we start debugging break it here and then when it tries to access this uh age key which which doesn't exist it will tell us the error type an exception has occurred key error. Okay so we can copy this we end the program and then I'll like remove this one and then we can add a new exception block down here. Anywhere. Um, we can say except key error as E then we can print uh there is no key uh I think this I think this stores age I I I think uh but I I'll I'll just say like you tried to access the value for a key that doesn't exist and then I'll print the E. Print E. So, so if we try to run this again, go to run and then it's going to try to do uh some of these actions. Most of them are legal. Oh, okay. So, it's going to print out my dictionary age. It does. or my sorry my dictionary name and it prints Josh. It's going to print out age. It fails. It's going to check like do we have an exception that will specifically handle this? And we do cuz it was a key error. And then we can print to the user you tried to access the value for a key that doesn't exist. And then it shows the the name of the uh the key essentially. So hopefully this makes sense. Um, you don't have to like me to be honest with you. I just want to say like I don't I don't memorize this syntax cuz it's it's a bit different for every programming language and I I had to like Google this or like ask chat GPD before I made this lesson cuz I don't I don't remember like it it's slightly different always. Um, so just know in your head [snorts] that it's you know it's possible that an error will can happen in your Python code and it's possible to gracefully handle the error and then allow the program to finish without it crashing if that makes sense. So I'll just say like you know print fin here, right? And then if we just like run this, it will just run all the way through. It lets us know that there's an error, but the program the program's still finished, right? It is still finished. So it just gives you a chance to like um handle stuff without abruptly ending the program and stuff like this. or it will like give you a chance to like repeatedly ask the user for input with that the infinite loop until it gets something that it can use. So yeah, that's error handling in Python. Of course, there's like slightly more stuff that you can do with this um like finally uh print for example. This always prints. Um, I'll just like run this without debugging. Just just an FYI, I believe. Yeah, you tried to access a thing that doesn't exist, which is here. And then this finally block, this thing always prints. This is like part of like the try accept block. Um, but yeah, that's try except block error handling in Python. Uh, hope it makes enough sense. If it doesn't or you have questions, um, of course, you know, use chat GPT, but you can always use a community and tag me in there and we will see you in the next lesson.
Welcome back. Up until this point, we've pretty much covered all the fundamentals. And then from here on out, we're going to start building more complicated things that are directly related to the cyber security agent/ AAI sock analos that we're going to build. And to actually follow along from this point, um, you're going to need two things. Uh, the first thing is you're going to need an open
AI API key, which is this thing right here. Um, this is used to communicate with ChatGPT programmatically with Python. Um, and we need that because we need to be able to communicate with models like on the back end to do like the threat hunting and whatnot.
And then the second thing you need is access to the cyber range. And this is going to sound like really salesy, but um, just bear with me. I'll explain why that is. I'll explain like what the cyber range is and like why you need access to it. So, basically, like, the cyber range is a live production-scale environment. There's hundreds of user virtual machines in there and literally like tens of millions of organic logs because it's constantly getting attacked by random bad actors and bots on the internet. Not to mention, there's like a thousand users in there already just doing, you know, practicing making resources and doing their own vulnerability management and threat hunting. It just makes like a ton of organic logs and telemetry data, which we're going to actually use to build our AI sock analyst. And all of those logs are getting stored in what's called a log analytics workspace. And we're actually going to be like querying that thing live with Python and then using those logs to do our threat hunting.
So, it's just this course was actually built for people who are already in the cyber range. Um, I'm just releasing it to the public. So you can like watch it and still follow along and get something out of it. But it's highly recommended um that you join the cyber range cuz I mean, there's a lot of other good stuff in there as well. I'll explain what it is just so you know what you're paying for like if you do join it. But cyber range, um, it's just like a full live production-scale environment like I said, has a lot of virtual machines. It's a, there's a full enterprise sock like security operations setup in there. Um, for our SIEM, we use Microsoft Sentinel. For our vulnerability management platform, we use Tenable, like the fully enterprise-licensed version of it. We use Defender for Endpoint for our endpoint detection and response. And there's also step-by-step courses, like video courses that show how to um, use all of these tools and do various security operations. And we have like um, weekly live calls with me. And there's internship opportunities as well. Like for anyone who wants to do it, you can get verifiable like sock experience on your resume and then we will like sign off on it when the company actually contacts us for um, like a reference for you. And like I said, I think I said this already, there's already a thousand members in there. Um, there's a theoretical max of about 1,800 members before I have to scale it out again. Um, so there's still room for people to join. Um, but I imagine when I start releasing a lot of AI content, it will probably fill up again and I need to scale it out. And I'm pretty certain there's like nothing else like this on the internet currently because it's, it's a bit of a liability for us to run and the price point is like really low for the stuff that goes into it. Just cuz I wanted, we wanted it to be like accessible globally. Um, but yeah, that's that's what the cyber range is. Feel free to like ask questions, you know, below in the comments and we'll, we'll try to answer them. But again, uh, you need an API key from OpenAI. We'll walk you through how to do that. And then you need to join the cyber range to get access to like um, all of those organic logs and attack traffic.
So, if you're already in the cyber range and you haven't gone through the security operations course yet, I highly recommend you do that. Um, that course teaches you like how to do security operations manually and how to query the logs and use KQL and like all the stuff that we're going to like actually end up automating with our AI agent. Um, so yeah, definitely go through that course if you haven't yet and you're already in the cyber range. And if you're not, uh, and you're serious about following along, go ahead and I'll put a link on the, either in the description or on the screen somewhere. You can check it out and join that way. And yeah, this is the environment the course was built for. And we will see you in the next lesson.
Welcome back. Uh, in this video, we're actually going to uh, install the OpenAI library. That's that's what that's called. And I just want to give like a demo of how to do that and explain um, what libraries are and like why it's useful. So, uh, first things first, um, just go ahead and open up VS Code and then open up the code folder on your desktop. It's okay if like you don't have anything in it or other stuff in it. Um, it doesn't matter. But mine's already open, so I'll, I'll close it and then I'll just like do a recap of what that looks like. So, we can just click these two. We can say open folder here or we can go to file and open folder. It does the same thing. So, go to my desktop or desktop here and then code and then select folder. And there'll be like a, a link um, at the bottom, uh, in the description or like in this video if you're watching inside of the school community and that link will um, open up to this thing. It's just like some boilerplate code for the next lesson we're going to be doing. So, just copy this code here and then go back to VS Code and then we'll create like a new file in here. We can call it, what did I call this? Um, main openai. It doesn't matter like what you call it, but I'll just call it main openai.py like so. And then just, uh, paste the code in here like so. And if you try to run this as is, of course, like, you know, a lot of stuff is going to prevent it from working, but just try to run it and you'll see like um, you'll probably see this error like mod no module named open AI and this thing will be unders have like an underline and then you can like hover your mouse over the top of it and you can say like a quick fix. Okay, it's not here. Okay.
So, to make this work um, we have to install the library like the OpenAI library. And all a library is, if you remember like in the previous lessons, um, you can create like a local module and then you can like import it into your code in a way that looks something like this. But there's a lot of libraries that like maybe a large company made or an organization or like some other group or somebody made it and it just contains like a lot of code that's it makes it easy for you to use, but you just have to like download it first. So, to do that, uh, in this case, we can use, uh, what's called pip. Um, I forget exactly what this stands for, but I think it's like Python something installer. I can't remember. But to install this library, we can just type pip, uh, space install space and then openai like this. And it will go out and I can, you can cancel this um, if you want. I'm just going to close it. But it will go out and then install the um, OpenAI library, uh, onto your machine and then after it does that, you'll be able to actually use this code. So, we will just let this finish and this like error should go away once it's done. So, so, and then this underline like went away. I'm going to like close this file and like open it again. One of the Okay, it turned green. Yeah. So, this should be good now. And then when you're at this point, um, your OpenAI library is installed. So, you can like use it. So, we can, we can play this again. And it, it will fail anyway because we don't have the API key here. But at least it, at least it says, um, at least it's not complaining about the library being missing like the new, the new error. Let me see what does this say. Incorrect API key provided. Yeah, of course. Because there's no API key here.
So, in the next video, um, we're going to work to figure out how to like create an OpenAI account and then get our API key and then, uh, fund the account and then we can actually start, um, making calls to the ChatGPT API or OpenAI API, which is pretty exciting cuz once you can use APIs, you can pretty much like do all kinds of stuff and it really opens up the world, uh, in terms of coding. So, yeah, look forward to that and we will see you in the next lesson. And by the way, you only have to install this like once. Um, it installs it locally on your, on your computer and then after you install it, you can just like, I guess, use it forever until you have to update it. But yeah, we'll see you in the next lesson.
Welcome back. In this video, uh, we're going to get your OpenAI account set up and then get your API key and then we're going to, uh, fund the account cuz it costs money. Um, you know, we're, it's essentially using ChatGPT and it's, [snorts] it's different if you have a ChatGPT account and you're actively using ChatGPT like in the web browser, that's different from the API. Like you can have those two things, uh, exclusive of each other. So, we're going to get an OpenAI account and then get our, uh, API key. So, also this code, um, I'll put a link for it in the description. Um, whether or not you're watching this inside of school or on YouTube, there should be a link somewhere to get this code, but worst case scenario, you can type it out. It's not that big of a deal, but I'll put a link to the code as well. But anyway, uh, just, you can go to Google and search like open a, open AI create account API, something like this. And then there should be like this, like a, um, login platform.openai.com, something that looks like this anyway. And then you'll just simply like sign up, um, however you want to with your Google or an email address or something like this. And then inside the code, I put some links inside of here. Uh, this is how to create your API key. So, you can control-click on this or however you do that on Mac. And then you can create new secret key. And then you don't have to name it. Um, you might have to select a project, um, if you don't have one already. Um, but just click create key and then you'll only be able to see this key once. Um, after you close this window, it's going to go away and you won't be able to see it. So, I'm going to copy it. Say done. Go to my code and then paste in here in the string. Paste it. Okay. And then save. Interesting. Anyway, go back here and then if you lose your key or something like this, um, see how like you, you can't see the key anymore. It's just like gone. Um, so you have to, I don't think you can see. Yeah, you can't see it anymore. So, you have to like delete it if you forget what it is and like create a new one, right? And this is basically a password. So, you want to like really protect this. After I release this video, I'm going to like delete this key, right? Because it's the same as giving people access to your like ChatGPT essentially.
So, we have this and I'll try to run this code. Um, it won't work because I didn't fund the account. So, for example, I'm just going to like, you know, look at this. So, I'll break this here and I will say start debugging Python debugger. I will, I'll zoom out a bit. The screen is like a bit noisy or getting too full. And then you can read the error that it says like message, uh, you exceeded your current quota, please check your plan and billing details for more information, blah, blah, blah, too many requests. And it gives you like a bunch of like, uh, links and stuff. Um, it just means like we, we don't have any money in the account. The API key works, as you can see. Well, you know, it worked enough to be able to communicate with OpenAI's API, but we need more money. So, we can stop this code and then we go back here. And then, um, you can just go to billing here. Um, or I believe you can like click on this and it will go straight to billing. And then you can like add payment details. And then you can add your card number and stuff in here. Um, you know, it's safe. It's like a SaaS product, like an expensive one. So, I'm going to like go and do that and I'll be right back.
Oh, I'm back. And on the very next screen, it's asking you like to enter like your amount. So, it's going to basically like fund your account. And you can kind of read all of this. Would you like to set up automatic recharge? So, if you're like API, you know, if you use up the $5, do you want it to like refund it? And then there's other options down here below like when credit balance goes below, like what's going to happen, bring the balance up to this, and you can like do all of this stuff. Um, you know, do whatever you want to do. I have like three API accounts already, so I, I don't need to like, I don't need to do all of this. I'm just going to like use my other ones. I'm just creating this just for this video. So, I'm just going to say five bucks and then not let it refund and then I will confirm payment. Payment was successful. And now you can see like your, uh, credit limit is, you have like five bucks of API usage. So, you can like use the API a bunch until this like goes to zero. It might go to like negative, like negative a few cents and then it will stop working again. And you can go to, I think you can go to usage and then you can see like how much you're using and like how much you're spending or whatever. And then you can look inside of limits as well. There's like other stuff in here. Um, but anyway, you know, you can look through this a lot, but, um, now the API, it should be working. And then I'm going to explain all this like in the next video. We're going to go into this like, you know, really deep dive and like do a lot with this. Um, but and I'll explain it, but basically this is just sending a prompt to ChatGPT and this is like printing the answer to it, basically. So, you can like leave this prompt in here if you want. I'm going to clear, you can clear your console down here by typing clear and then this is literally just using ChatGPT and you can, if you want to do a different prompt, you can. Um, but I'm just going to run this without debugging for now just to like observe it working and we will, we'll see what it comes up with. Give me a very short recipe for a cake. And we're using the model GPT5, which literally came out Pro, I think yesterday, actually. And here's here's what it came up with. You can read it. The beautiful thing about like LLMs and AI, and yours is most certainly going to be different. And if you run this again, um, it's most certainly going to be different cuz the way that, um, the way that this is currently configured, it doesn't remember like the previous things we talked about. Like every time we run this program, it sends like a new, it's like a brand new conversation. And see, it came up with a different thing this time. And this time and actually gave us instructions on how to like, uh, cook it like and all this stuff. But if you're able to get a response like this, it means your thing is set up. Your account is funded and your API and everything is working. Um, so let me just like, I doubt the usage got updated yet, but I'm just going to like check it to see if anything changed. Oh, it already did. So, total of 34 tokens we used already. And we're going to talk about tokens and all that stuff like eventually. Um, but I think I can see the balance yet. It probably wasn't even like one cent to be honest. Yeah, it's still $5. It might not have updated yet, but anyway, if you get to this point where you can like get the cake recipes or like whatever you put in this prompt, we're good to go. And if it doesn't work, you know, go to whichever form you're watching this in, probably in the cyber range, um, you know, if you're doing this, and then just make a post in the community and tag me. Someone will probably help you before I get to it. But, um, we want to make sure this is working before we move on to the next stuff. But yeah, we'll see you in the next lesson.
Welcome back. In this video, we're just going to use ChatGPT a bit with Python. Um, I just want to give you a sense for a few different things. We're going to be using the same file as in the last, uh, video. So, we can just, you know, download that again or make sure you have it open and then make sure that you have your API key and everything. And then make sure that your account is funded. And if you forget where to get the API key, it's here. And then for billing, to make sure your account is funded, um, just like, uh, you know, go to this link and then billing. And then make sure that there's some kind of like money in here, at least at least like a bit, right? Cool. And then, um, I'm going to set the model to GPT4. Um, if you, if you've used ChatGPT on the web, you'll know that like, um, before you can like kind of set the model version up here, like if you want to use like four or like a different version or something, but if you're using the API like this, um, you just have to do it here. So, for example, I'm just going to like show you something. If you, I'll explain like all of this in a bit, but if you go here and like put double quotes or you type a quote, it'll just show you like all the quote-unquote available models for you to to use. GPT4 is like, it's pretty fast. Um, so I'm just going to use that for because it's good enough for our intents and purposes. So, um, just make sure that this runs. So, we'll save it and we're just going to, um, you know, put a different prompt if you want. What is the best country? Answer in, uh, five words or less. You know, just whatever, just to make sure that it works. So, I'm just going to run this without debugging. See what comes out and then I'll kind of explain everything. Subjective and based on personal preferences. Very GPT answer. Okay.
So, uh, I'll just kind of explain this stuff line by line and then we're just going to, I'm, I'm going to explain the stuff and then we're going to kind of like rearrange this in like a more optimal way, uh, based on stuff that we learned in the previous lessons, just to like solidify those concepts in your head. So, I'll break this and then I'll start debugging. And then, by the way, you can always paste code into ChatGPT and ask what it does, like actual like web ChatGPT. This, it tends to be pretty helpful, but, um, this is just the module for, um, OpenAI, ChatGPT. There's like a bunch of code in this that I don't know what it does, but it's, it's basically magic to me to be honest, but it allows us to interact with OpenAI API and use ChatGPT with, um, Python. And then this line of code, um, you can just think about this is just think about it as a special like object or, yeah, just think about it as a special object that takes your API key, aka your password, and then the thing that it returns is just, to me, in my head, this thing is just a special variable that allows us to interact with ChatGPT. It's much more than that. But, [snorts] to be honest with you and like, you know, transparent, I'm not super smart and I'm like, actually, this contains whatever. But it, to me, this is just a magic variable that lets us like interact with ChatGPT down here, as you can see. So, if we step over this and then if we're debugging, like if you click this, you can actually see what's inside of this special variable. This OpenAI client is here. And you can see it's like just a bunch of stuff. And, you know, I don't, it's a lot of like technical stuff, but I don't, I don't know what it does. I could learn it and you could learn it, but for our intents and purposes, like, we just don't need to do that right now. It's just a variable that lets us interact with GPT. And then this, of course, um, this is just a string, as you've learned in the previous lesson, just quotes with some arbitrary characters in it. It gets assigned to this variable. We just so happened to call it prompt. We could have called this variable giraffe or zebra or like whatever. So, we'll, we'll skip over it. It makes sense. Uh, not skip over it, but we'll continue the code. It just makes sense to call it prompt because that's what it is, right? Cool. And then this thing, um, you'll notice like a single equal sign here, like this whole thing is just a special function that asks ChatGPT a question and then it will return the answer to us, which will get stored in this variable. All this is is a function. Um, it takes, it takes well, it takes more than two arguments, but currently we're passing two arguments to it. Um, one of them is just a string representing the model, like we're telling GPT which model we want to use, and then the second one, uh, is a is an array of messages. I'll talk about this in a bit. Um, but this is just a array that contains our prompt, um, to like the thing that we want to ask ChatGPT. And if we step through this and step over it, so it will return something. So, we have this response now and this has our answer in it somewhere. So, if we, uhoh, so if we look in the variables on the left, this is what got returned from ChatGPT, the API. So, if we expand this, you can see there's like a whole bunch of stuff in here, like the model that was used. This is probably like, I'm assuming, like the date time stamp, some kind of like time saying that it's created. And there's just a bunch of stuff in here, which I don't know like what most of this is to be honest, but I know what some of it is, but so we can look inside of choices, for example, and then, um, that's what this thing is, response.choices is a list. So, choices, it's in a, it's a list with zero or rather a single object in it. And then inside of this single object, there is something called messages, like so, or rather message, and there's something called message. Sorry, there's something called message, which is here, and then content, which is here. And this is like our actual, um, answer that ChatGPT gave us, the like subjective to individuals, personal preferences. Um, we didn't even see this printed to the screen yet. Uh, this time around, it's, it's still here. So, if we step over this and then it's, it's going to print this out. So, basically like this line here, it took the thing inside of like the response, which is here, inside choices, in the first element of this list. So, choices, the first element of the list, and then inside of message, inside of message, there's content, content, and it took this string and assigned it to this variable, and then now it's just going to print that variable out. So, if we step, it prints it out and then the code finishes.
So, uh, I just want to explain like a couple of things and like rearrange this a bit and make the program like a bit better. So, for example, um, you might notice that, well, I don't know if you noticed it or not, it's really hard to notice, but this messages thing, um, these square brackets on the outside of it means that it's sending a list of things, but there's only one item in the list, like a single, this is called like a, a message object, I guess, for ChatGPT, but if you look at it closely, you'll notice it's, it's actually a dictionary. So, for example, for example, I will take this out. I can, I'll cut this, rather. Sorry. I will cut this. And then we can say like, uh, um, I'll just say like dictionary because that, that's what it is. I'm just calling this a random, a random variable called dictionary. And then we can do something like this. And then you'll notice this is actually like the key value, key value, like so. So, we can arrange it in like a, a way that maybe makes more sense and it's like easier to understand, like so, just so you can see like what it actually is. This is like key value, key value dictionary. And then we could just take this for example and then pass this into here, like so. Like so. And then I'll explain like the role user and then the content prompt thing in a bit. But instead of like hard coding the prompt like this in the code, we can use input. If you remember from like the previous lessons, um, we can say like, um, I don't know, what does ChatGPT normally ask? Let me look. Oh, ask anything. Okay, fair enough. Ask anything. Whatever. And then I'll say a new line like this. And then I'll just like run this code as is. Um, I'll just run it once without debugging just so it runs as a normal program. And then we can, uh, practice using it. So, this is literally just ChatGPT. It's just, we're just using it in Python in the command line. So, I'm drinking something. So, um, what is the total macronutrients? Oops. This should be one word. Whatever. For a grande Starbucks latte. Oh, I'm, I'm going to misspell them. It's just, it's okay. Latte with cinnamon. Don't make fun of me. Honey, and an extra shot. I got this in Shodome, Japan, if that matters. And it's raining out. Uh, I'll say to make it interesting, please respond. Uh, no, I, I don't want to do that. I'll, This is good enough. So, I'll just say enter, like so. And then the program should just run and do everything. So, we'll see what ChatGPT comes up with. And it responded and it got dumped to the screen. The nutritional information. Oh, yeah. The nutritional information may vary slightly. Blah, blah, blah. So, it tells me the calories and like all the stuff. The extra shot of espresso. Anyway, like, you get the idea. We have like a working ChatGPT and then the program, uh, just ends, basically.
So, we can, um, if you, I want to like talk about some stuff a bit. So, let me undo some of this and put this back to like how it was originally. Cool. So, this is like our original code more or less. So, you'll notice this, um, messages thing where it has like a role user and then content prompt. And these square braces on the end means that it's trying to accept a list of messages, but we just, we're just so happened to be only passing one message in here. So, we can do more than one message and there's like this thing called role and you can specify, there might be more than this, but you can specify either user or you can specify system. And if you specify a system role, it just gives ChatGPT more context for how you want it to behave. So, for example, um, I will take this and then maybe, um, we're going to, let's see, let's make, I'll make our own JSON object full of with that's a list of dictionaries, if that makes sense. So, just bear with me for a moment. So, I will say like, uh, full prompt, this all of what I said probably didn't make sense to like anyone listening to this, but it will make sense hopefully after you see what I'm doing. And by the way, I learned all this just from using ChatGPT and like Google, like asking ChatGPT more and more, and there's documentation for this as well. But anyway, so I'm just going to call it full prompt and I'm going to replace this whole thing with it. So, I'm going to create a list, like so. And then I'm going to order, I'm going to like format it like this so it's easier to read. And then there's just going to be like, uh, two messages in here. So, the first message will be like the, we call it like the system message. So, I'll cut this actually and I'll just like replace this and separate by a comma and then I'll paste this one more time. And then actually, I'll change the top one to the role is system and then the content. This is where you like tell ChatGPT like how to behave. Um, so, for example, if you've ever seen those YouTube videos where it's like, um, this was the best prompt for ChatGPT for learning math. Pretend you're like a math tutor and like all this stuff, you know, it, it gives it context for like what you were trying to accomplish. So, um, this is like where you specify how you want ChatGPT to behave. You will create a message, um, for with the role of system and then the content inside for the content, you'll put like how you want it to behave. So, I'll say like, um, you know, in the terms of, in terms of our like AI sock analyst, we'll be, we're going to be like, you're an AI sock, blah, blah, blah. But for this, I'm just going to say like, um, answer as if you are a world-leading rocket scientist. And then the user prompt is just going to be like whatever we happen to ask, right? It's going to get put in here. And then this full prompt thing, this is a list. So, I'm just going to pass this to here, if this makes sense. This might be easier to read. Like so. It's just another way to like organize things to make it possibly more easy to read. And I'm just trying to show you like what's possible. This isn't like how you're supposed to do it. I'm just trying to articulate that this is a list of dictionaries that are actually messages for GPT. And one of them can be a system message, like for how you want GPT to behave. And then other ones, like your actual prompt as a user. Um, it just gives the model context for how you want it to like answer. So, I'll just break this like so. Um, I'll break it here and I'll start debugging. And by the way, of course, when you get stuck, go to the boards and then for the category, pick like AI plus cybersecurity and ask all your questions there.
Oh, actually, I wanted to like, um, I wanted to get our own input. So, I'm going to stop this. I'll say input, ask anything. Okay. Now I'll, Now I will, Oops. Now I will debug this. Okay. So, I will step over this. Says ask anything down here. Um, I'll ask, uh, please come up with a similar recipe for the Starbucks, Starbucks creme brulee. I don't know how to spell this. Brulee. I don't know. Whatever. I want to say creme brulee. That's embarrassing. Whatever. Latte in Japan. Just do your best. I don't care. So, and then now our prompt got stored into here. We can see our prompt string over here. And this is our full prompt. Uh, it's a list, but it's a list of dictionaries. And these are, these are messages for, um, the ChatGPT like model. So, if we step over this, like so. Now over here, we see full prompt and we see it's a list and the first item is the system role, uh, message, answer as if you're a leading rocket scientist, and then the second one, this is our prompt that we just typed for the Starbucks like, uh, creme brulee. I spelled that really bad, but whatever. Anyway, so now this is the function where it's going to like actually ask ChatGPT like our question and it's going to provide the context where we wanted to answer as if it's a leading rocket scientist. That whole thing is inside of this, uh, full prompt thing. And by the way, um, the way this is organized, um, it's just, it can be like this. In the previous lessons, the function was organized more like this. It's like inline, like so. It just tends to be easier to read, um, if it's separated on multiple lines when it starts getting too long. So, I can do it like this too, where the, this is the create is a function. This is the first, uh, parameter or argument we're passing. This is the second argument. This is non-negotiable. This is like what's inside of the actual function. This is the thing we're giving it. This is non-negotiable. Like it has to say messages. This is the thing inside of the actual function that we can't see. But this is the thing we're, we're passing it. So, if we step over this, um, the thing. Okay. Uh, just ignore this. It's because I, I changed the lines a bit like in the middle of the debug. That's why. Don't worry. Okay. Now GPT is, uh, it's asking GPT. So, we'll see what it comes up with. I'm sorry. This, it's out of, it's out of whack because I, I messed with the lines. And then if we finish this, it should like print it to the screen. So, I asked it to answer like it's like a reading, like a leading rocket scientist or whatever. So, it says, "As a rocket scientist, I must admit that crafting beverages is not my usual expertise." Blah, blah, blah. And then it just, whatever, gives the instructions. I don't, I don't know why the instructions, like if this is how a rocket scientist would answer, but it acknowledged that we had the system prompt, um, to answer as if it were a rocket scientist. Use a kitchen torch, blah, blah, blah. Okay. So, maybe, maybe you like can get the idea. And there's more you can do with this. Like this is the full prompt that's being sent to GPT. And you can send more than like two messages at a time to it. So, for example, if I copy this and just like paste it, and then I, I'm just going to make up another prompt. Um, I don't know what's going to happen if I do this to be honest. I'm just going to disregard this whole thing and then I'm going to send another prompt. Uh, my favorite cake is banana something. This is nonsensical, right? So, I'm, Oh, this, there needs to be a comma here. So, again, this is a, a list. It's a list of dictionary objects. And these are, these are messages for, um, the ChatGPT like model. And one of them can be a system message, like for how you want GPT to behave. And then other ones, like your actual prompt as a user. Um, it just gives the model context for how you want it to like answer. So, I'll just like send this to GPT for example. I'm going to remove the API key and then I'll say like, you know, um, let me like remove this. You should try to get in the habit of not sending your API key to ChatGPT. And I'm just going to ask like, um, Oops. Oh my god. I'm going to say, why didn't ChatGPT API acknowledge that I like bananas, banana cake? We'll see what it comes up with. It didn't acknowledge that you like banana because of how the API's messages array works and how you phrased your final prompt. Okay, that's probably why. When you said this, you're not giving it a conversation where the model is asked to respond to both pieces of information. Instead, the system message sets the persona, which is this. The last message, zebras are fast, is what the model primarily treats as the current question. The earlier question, my favorite cake is banana, is context in the conversation history. But since you didn't ask anything about it or connect it to the zebra message, the model has no reason to bring it up. Um, it focuses on the latest, uh, the latest turn, which is this. This is kind of what I thought. So, basically, this is, you know, persona, how it's supposed to act. This is context for our previous conversation that we like, quote unquote, had. And then this is, uh, the current prompt that GPT is supposed to answer. This makes sense. And we can kind of read more of this. The API doesn't automatically acknowledge all prior facts unless they're relevant, uh, to answering the current question. So, it's giving like examples if we want to force it to acknowledge it. So, maybe we can say like, um, maybe I can say zebras are fast. Um, wait. Maybe, maybe, um, I don't know. I don't know if it's going to like care about this, but I'll try to say like, "What do you think is a good fruit, uh, to feed them?" And then maybe I can like bait it into mentioning the banana. I don't know if this is going to work, but it's like a good experiment, um, based on the knowledge that we just learned from GPT. So, I'll just, I'll try to run this that we might have on hand. Yeah. So, I'll just, I'll just try to run this and see what happens. I'll just run it without debugging. I learn, I literally like learned something. I, I kind of assumed that's how it worked, but I never bothered to like check. So, zebras being herbivores have a diet of grasses. However, some fruits might be acceptable, um, if they're readily available. Oh, it didn't, it didn't, I couldn't bait it into talking about the banana. These are like two, like two dissimilar things probably. But, um, anyway, I hope that makes sense. And then you can like experiment with this a bit. Um, a good project would be to like, you know, how like if you're using ChatGPT, you can like kind of keep talking with it. Um, and it will, it will kind of keep track of the conversation, I believe. Um, so one way we could try to like come up with like a program that actually behaves like ChatGPT that keeps adding previous messages onto like the full prompt like every time you call GPT and then it will have context to them. That would be kind of a cool project. But, um, you don't have to do it. It's just like something that came to mind. But hopefully this like kind of makes sense. Um, if you have questions about this, like no doubt, you know, use ChatGPT, of course, to ask, but definitely go to the, um, go to the community, ask questions and everything, and just make sure you like, kind of understand at a high level of what's going on. You don't have to memorize like all the syntax for this and stuff, but just acknowledge the fact that like, okay, we're using an OpenAI library. This allows us to talk with ChatGPT. Okay, this is a special variable. We pass it our API key, which is our password. And then if the API key is correct, we can use a special variable to talk with ChatGPT like we're doing here. And then think about like, um, when whenever you communicate with ChatGPT, you have to tell it like what model you want to use. And then just know that you can change the model like so. And then also when you communicate with ChatGPT, it's going to expect, uh, a list or an array, but a list of messages and they need to be formatted like this, like so. Um, because if you, you know, if you just send like a prompt to like, if you send like a just a flat string to it like this, um, it's going to be like, this was malformed. So, I'll just like show you what that looks like now. It says, uh, error, error code 400, expected an array of objects but got a string instead. So, it expected an array of objects is like this, and then it got a string instead. So, I can be like, oh, an array of objects, huh? So, I'll just give you an empty ar, an array full of empty objects like this, and then we'll see like what it says. It should crash with this as well. But we're just going to like experiment, you know, just to get like a sense. This is literally an array of objects. It's just empty. But now it's complaining. Uh, error code 400, missing required parameters. Uh, type invalid request parameter messages zero role code, missing required parameter. Oh, so it's missing like this parameter, uh, of the role parameter. So, I'm like, oh, maybe I, I'll just like add that in here. Here you go. And then with like an empty string, for example. And I'll just, I'll just send this as is for sure. is going to like have another error probably. But let's just see what happens. It's complaining again. Uh, invalid value. Um, so this, this is an invalid value. So, I think it's, it's expecting to have like system, user, or like something like this. So, for example, we, we know how to fix this already because this is like the, this is how to do it. But you can always, I'm just showing you random stuff. Like you can take this and then go to ChatGPT, like so. If you get an error, then you can go back here and you can like, uh, take this error. It's better to take all of it, but I think it's going to understand if I get this much. And I'll copy it. Oh my god. I hope that copied. I feel like it didn't. Oh, it did. Okay. And then I'll just like send this to GPT. It probably is probably going to be able to figure it out. Okay. So, these are the, these are the fields apparently that, uh, GPT is, um, welcome to get in there. So, either system, user, assistant, function, tool, developer. I don't know. I know what tool does, but I don't know what these other things do. So, maybe, um, I can like pass assistant, I guess. Like so. But it's going to complain now that there's like no content or no prompt, I guess. So, if we run this, yeah, again, invalid value for content, expected a string, got null. Uh, it didn't actually, there's like no content anyway. It's, it's because it's missing this. So, basically like the point, um, I'm just trying to make is, um, ChatGPT, um, when you send it something, it expects like a list and it, it expects like certain, a certain dictionary like with certain keys and values in it. It just needs to have those in order to like function properly. So, um, I, I guess apparently assistant is a valid role and then we just need to like, this is like the content is
Our actual prompt we're asking it. So, um, answer is the best cake. I I don't know if this is like correct, but we'll just run this. I'll just run this and then we'll end the lesson. This is not being used, by the way, at all. And then it it answered properly. The the answer to this question largely depends on personal preference blah blah blah blah. So, I'll just like get rid of all this and I'll I'll run it like one final time. We'll just do like one more since we went all the way. So, I'll pass full prompt to here again, which is this. And we'll just like run through it and we'll step through the code uh one more time. Um I'll do something real. Answer. Answer as if you are a girl working on the street of Kabuki who is good at making cakes and then we're just going to do a normal user role and then the content. This is our prompt that we're going to actually ask Chad DBT. So, I'll say like uh what is the best uh cake in Tokyo? No, I'll say the best sushi. Okay, I'll just And then this time I'll debug it just so we can get like one final final sense. So our client is created our API key and then I'll show you actually no I'm going to show you like one more thing after this our prompt is being constructed and then we see our prompt over here constructed ro system this is the context for how we want to behave this is our prompt and then we're going to ask GPT with the GPT4 model and our full prompt here and then we will get the answer. And then she answered in perfect English. While I spend most of my time baking and perfecting cakes, I do have a fondness of sushi in my opinion. Sukiyabashi Jiro. Oh yeah, this is like a really even I know what this is. It's really expensive. Um, however, as a cake artist, my expertise lies more in pastries. Would you like some suggestions on where to get the best cakes? That's so funny. Um, yeah, that's that's really interesting. And by the way, uh this is the last thing I wanted to show you. This is our API key, right? Right. Like our password. And if I like change one thing in here, like instead of this three, maybe I put like a two and then I run this. I'll just run it without debugging. No doubt. This this object is going to be invalid and it's going to crash because the API key is like incorrect. And it says the error message uh incorrect API key provided. You can find your API key here. And then you, you know, you have to like generate a new one, uh, if you don't remember what your other one is. But, um, I just reverted it. And yeah, that's like, um, I forget what this lesson was called, but just interacting with and using chat chat GPT. Hopefully, you have like a good sense, like a better sense for how chat GPT works and just, I don't know, a better a better intuition. But yeah, let me know in the forums if you have any questions and we'll see you in the next video.
Welcome back. Uh in this video we're going to talk about uh forcing uh chat GPT to output in JSON format. So what I mean by that is for example uh this is English please describe a main cat succinctly and it just outputs this normal English sentence with like properties of the cat and like what it looks like and then if I say to describe it in JSON it will output something that looks like this. It's like structured data that's easily parsable by a computer. That's like that's the difference. And if we go to like the API for example, um there's kind of like two ways to do it. Uh I'm going to remove this for now. Like this line, this type JSON object as well as like this comma. I'm just going to cut it like control X. And then I'll say like um for example, please describe a pineapple succinctly uh in JSON. Like I'll tell it to do it in JSON instead of like, you know, I'll just I'll just put it in the prompt, right? That's one way to do it. So, if I run this and then I'll just uh I'll just run without debugging. Just let it run. And then you'll notice it does actually describe it in JSON, but you'll see it like puts this like this is technically a string in front and a string in the back. This is like a This is markdown. And this this like tick tick tick JSON then tick tick tick. This is what makes uh this like kind of gray square like this. That's that's why it's like that. So for example, if I if I copy this for example and then I open notepad and I paste it. I paste it. You'll see it like here's response in JSON and it it puts like strings and like all this stuff in in front and behind. And this this is the actual perfect JSON inside but it actually put a bunch of stuff before it which is like not JSON. And if we try to like this will make sense later but if I try to like directly load this into a JSON object um it will crash the interpreter it will crash the program. So, in order to like avoid that, like strictly avoid it doing that, like putting these ticks in front or like any other kind of like preceding text, we can add this thing back. I'm going to like undo this. We can add this thing back, this comma, and then we can pass this response format type JSON object like so. And this will like this will force it to be in JSON, like perfect JSON every time. So, I'll say, "Please describe a pineapple in I'll just say, okay, I'll I'll show you something. I'll just say, please describe a pineapple without saying like anything about JSON, and we'll run this. I just want to get people used to seeing like errors and reading them and dealing with them. So, basically, an error happened, right? You might see the error up here or you might see it down here. So for example, let me see. Let me run this one more time. I'll run this like without debugging. I think if I run without debugging, it will show down here. It's easier to copy. Yeah. So there's an error and it basically said uh error 400 error. Uh messages must contain the word JSON in some form to use the response format type JSON object. So basically what this is saying is if we use this we have to say the word JSON in our prompt somewhere. We have to either just say JSON or just tell it to like output in JSON format something like this. So for example if again I just want to remind people you can copy stuff like this and then you can just go to chat GPT and then just paste it without any context and it will usually like it will usually tell you what you have to do. Make sure your request includes JSON in the message. So basically what all this means again please describe pineapple uh please output it in JSON format like so. And then if we run this, I'll just run without debugging. And then you can see this like perfect JSON format gets uh got outputed like so. Perfect object. There's nothing before, nothing after. It's just a nice uh nice object representing a pineapple. But there's still kind of a problem with this. For example, you see it's a JSON object and you remember from the lesson like we should be able to do like something like I'm going to like make this a comment. So we should be able to do something like this uh answer name and it should print pineapple you know it should because it's a JSON object. This is just a big dictionary like key value key value and if we if we do this it should be able to extract the value and it should just print pineapple right should. So, we'll run this uh I'll run and debug this one more time. Like so. And then if we step over this, we're going to get our answer. So, this is this is actually interesting. It's it's another point that I wanted to like show you. you see that the the JSON not only is it not an actual well okay there's no there's no name in here firstly that's like the first problem um which is something I wanted to get to next cuz before the the previous um the previous object that was returned by GPT the first item or the first like property was name scientific name category but now we have fruit scientific name and then I don't know what's else after this I can't see it appearance there's like no category and there's No, there's nothing named name like first of all. That's like first problem. Um, so this for sure is going to crash anyway. It does. So the first issue that we have to deal with is if we just say something like this to GPT like please describe a pineapple, output it in JSON format, it's it's going to make up its own schema rather it's going to make up the way that it's going to make up the structure of the data. Like the first time it decided this structure like it's going to have the name property, scientific name, category and then the second time we ran it, it it had like a fruit category, scientific name. It didn't have name and that the structure is like kind of all over the place. So we can actually like tell it the format that we want to like output uh the that we want. We can tell it sorry we can tell it the format that we want it to respond in. So we can either just like make up something like if we know like how we want to use it. So we can say like uh please output in JSON format and we can say something like this. We can just like make up our our own JSON object like so we can say like name and you know string category string uh we can say maybe colors because maybe there's like multiple colors and we can say like array array and list is it's basically the same thing for all intents and purposes for what we're doing because maybe the maybe the pineapple comes in more than one color right maybe there's like a red one like I don't know and then we can say like uh locations like where where it grows right and this this will be a string so with this we can we can kind of format we can force GPT to like use this schema every time so we know uh the format it's going to be in when it outputs, right? Otherwise, we have to like guess and it's not very useful if it's returning um like a freaking different format every time, right? We can't it's hard to use. So, if we do this, we can force GPT to like um put output it in this format. And it doesn't have to be like this. It doesn't have to be exactly like this. We can say it in like many different ways. And GPT is smart enough. We can just say like please output it in JSON format. Only include the fields name, category, colors, and location. and it will be smart enough to like figure out what to do, which I'll show you in a second. So, for example, we'll just like run this. I'll run this without debugging. Um, just going to observe the output. And instead of this long Oh, what what happened to this? Oh, okay. Oh, let me let me let me fix this. Sorry. Okay, I'll run without debugging. I just want to print it to the screen. And you can see it printed uh name pineapple category fruit colors yellow green brown location tropical regions. Fair enough right? So we can also do it a different way. We can say like um please only include these field these properties. I don't recommend doing this way by the way. um name hold on category colors location. I recommend making the actual JSON object um because I don't I don't want it to like randomly uh choose like arrays for some things. It's just better to like make the full object yourself so it knows. But you can do this anyway. I'm just going to run it and just we can observe the difference if there is any. You can see name pineapple category fruit colors yellow green brown yellow brown green fair enough location tropical regions. It's pretty it was pretty much the same. It's almost exactly the same and it worked well. But still, I I just recommend um using like a proper like a format like this. So there's like no mistake. And you can always like go to chat GPT for example. I can say like please describe me a or I don't know sorry please give me a schema in JSON format that describes a pineapple. I put pypos in here, but it's okay. And it should it should do some it will do something like this. It's maybe this is like too long. Please make this way way shorter just for our intents. Oh, this this is good enough. Uh schema only please. Like so. So this is this is a this is a schema for describing a pineapple. So if we copy this for example and then go to GPT we can just like use this thing that GPT gave us if you want or you can make your own just like if it's troublesome to make the schema for yourself. This looks slightly different than mine but um GPT is going to understand it either way. So, if we I'm going to actually debug it this time. And this is like really long. So, I'm going to collapse it and I'll debug this. And remember, just try to understand like what's going on and use GPT and use the forum. Um, you don't have to do anything like too crazy. Just like just be like, okay, yeah, that makes sense. That level is like good enough. So, it responded. We can see we're going to extract the answer and we can see it. We're going to print it out and then this this is the schema that we gave it. Uh exactly. It should be anyway. So let's compare it to make sure. Yeah. So the type is an object and then these are all the properties it should have. So it should have name, scientific name, color, taste, nutrition. Name, scientific name, color, taste, nutrition. And then nutrition is an object itself and that has calories, vitamin C, fiber, calories, vitamin C, fiber. And it's it's good and this will likely be um perfect uh every time. Um this format will be perfect every time we we do it. So So we can do this. And then we see that uh next we're going to try to like for example, we're going to try to print out pineapple because remember this is just like a big dictionary. This is a key. This is a value. This is a key. This is a value. Key value, etc. So to access pineapple, we would just say like uh you know this thing is called answer. And then we do something. It's not what I did. You'll do like this like so. And in theory, this should this should take name from here. And then it should print pineapple like so. And then same with this answer. And this should print out whatever ananas whatever scientific name. So we take this put it here like so. So I'll break this here and I'll restart the program. The schema should still be intact. Like it should return the same format of like pineapple like the same JSON format every single time. So look and it seems to have it seems to have done it because we have name pineapple scientific name an ana ananas whatever so technically this should print and you notice that it crashes and that's because like the thing that's returned from chat gpt is actually it's actually not a dictionary it's actually not an object at all it's just like a long string it just looks like JSON but in fact It's just a long string. And if you remember, a string is just like a anything. It's like anything surrounded by quote. God, it's any arbitrary characters surrounded by quotes. It just so happens that the string that got returned from chat dbt, it's in JSON format. It looks like JSON. So, we can actually use this and we can fix it um with the JSON module or library. I think it's module is the correct term. So basically the JSON module um allows us to take a string and if it's formatted correctly, we can turn it into a dictionary object or like a proper like JSON object. So to do that, we'll go to the top and then we're going to import JSON. Oh my god, I'm in a VM and it's like really the mouse is like really screwed up if you're wondering why I keep like messing things up. So we'll say import JSON like so. Like so. So we can use this um this is our answer. So we can say uh I'm just going to name it like answer you know dictionary and then to to load this string into a JSON object we'll use the JSON library that we imported and then we'll use the loads function and then what we'll pass answer into here. So, and then I'll just break it here and then we will debug this. So, basically actually I'll break it here. So, this is the response from chat dbt. We're going to pull out the answer from it. So inside of answer now you see this like basically it's just a long string that looks like a it's a JSON object but it's a it's actually a string. So if we paste this in text edit it looks like this. It's like a has a quote in front of it and stuff or it has like anyway it's a it's a string but this line of code is actually going to take that answer and then load it into a JSON object. So if we do this you see here we have answer and then now we have answer dictionary and this is a proper uh JSON object. So if we expand this we can see properly like name pineapple scientific name that thing color taste nutrition etc. So now um well this is this is going to crash anyway because I'm still using answer um I need to use like answer dictionary here instead of answer. So we'll watch it crash. So we'll stop this and then instead of answer we'll use answer dictionary cuz this this answer dictionary is what actually is going to contain the object that we can parse out and use like this. So I'll run this one more time. Run start debugging. And we'll step over this. Step over this. It loads the object and then now we should be able to see it prints out pineapple, prints out anus komosus and then it finishes like so. Cool. And then going back to the thing that we talked about in the very beginning, um if you remember, we added this in here and this this forces chat GBT to um output everything in like perfect JSON. So if we remove this like so and we'll try to run this, it might work, it might not. I don't think it's going to work. Uh because if you remove that thing, it it removes like the perfect JSON capability, I guess. Um, so we'll we'll we'll see what happens. So if we start debugging and then now we have our answer. So we'll step over this. Um, we have the answer. Oh, actually this this looks okay. And then if uh it might be this might sometimes it actually is okay. So if we step over this like so it actually this actually worked to be honest. Sometime sometime the problem is like sometimes it doesn't work and sometimes it like actually does. Uh this time it actually did output in perfect JSON. I think it's because um I provided this schema so it knows like exactly what to do. But I think if I don't provide this, we'll like experiment. Um it's kind of interesting. I'm just going to like leave this in the video. So I'll just I'll just change our prompt. Please describe a pineapple. Please output it in JSON format. I'm not going to provide a schema. Um, I'll just like run this and see what happens because I I think if you do this, it it won't be in like perfect JSON. It will like try to output in like a markdown and we'll put like the three ticks in front of the JSON or something, but we'll we'll see. I'm not sure. Yeah, it it did here. So, if we try to load this, it will crash um because the thing that it the thing that it provided is not perfect JSON. See, there's like a um three tick marks in the front and then I think there's like three tick marks and then the word JSON in the back. And you can you can kind of like clean it up sometimes. Um for example, hopefully this is like not too confusing, but uh I'll show you something. Answer, you can say like uh replace and then this this is a this this is a function. And when you tack it onto a string, it will like it will take whatever you put in the first argument and then replace it with whatever is in the second argument. So I basically said like look for any instance of this back tick and then just replace it with nothing. That just means erase them. And then also replace this is going to get confusing, but I'm just going to show you anyway. and then replace JSON with uh nothing as well cuz if you recall it put like I hope hopefully I have this open still like it had something like this in the beginning it was like JSON and it had like three ticks and then in the end it had like three ticks. So I'm basically [snorts] saying like man manually like remove these ticks and manually remove JSON. So for instance I'm just showing you some some random stuff. Okay, just bear with me. So, we'll step over this to get our answer. And you see like there's three back ticks in the front of the answer. And then the very end there's like three back ticks as well. And the front also has the word JSON. This like um ruins the perfect JSON format. But this line of code is actually going to like take the back ticks and replace them with nothing, which means erase them. Take the word JSON, replace it with nothing, which means erase them. So if we step over this, this these ticks in JSON should get removed. Like so. See how they're gone. And then the back ticks in the end are gone. And then I I don't know if this will load JSON. It will if it will load correctly. Um Oh, it did. So, this is like one way to kind of like, you know, manually clean up the response if you're not using um this thing. It's like a way to manually clean up the response and then it it works. It's probably going to print the stuff. It did. Um but it's it's better to like at the API level to force the the response to be in JSON. If you can force it to be in JSON and you can provide the schema, you're going to know like exactly what GPT is going to return and it will return like a perfect JSON every time. So, yeah, I hope this makes sense. Um, you can have fun with this like trying to like maybe describe an object on your desk and trying to like print the the properties for it out. Like I'll just do like one more um before we quit. I'll just pick something on my desk. So, give me one second. Let me remove these. And what's on my desk? Oh, I'm inside of the Mato Coup in Japan right now. So, I'll I'll say like please uh describe Matu Japan. It's just like a really like nice area in Tokyo. Um, [snorts] please output in JSON format. And then I can go to GPT. If I want to have a schema for it, I'll just say like please come up with a JSON schema for describing a uh any district in Japan. I'll I'll say like this and I'll say schema only in JSON please. Some some typos but that's okay. GPT is like always trying to do so much extra stuff. Godamn. Please make it like one/10enth of this size every time. And shorter going. Okay, fair enough. And by the way, like I don't whatever. I I don't feel like really I don't I don't know what this is to be honest and I wouldn't write the schema like this but apparently this is probably like the proper way to do it but I don't know but I'm certain chat dbt will understand what I'm what I mean by it. So use this schema. I Okay, I'll paste this here like so. Like so. And then I should be able to like, you know, I can I can I know what the output are like the district name, prefecture, population, area, etc. So I can do something like this. Um I'll just use string interpolation here like so. and do this. Don't worry about the errors. We'll fix that in a moment. So, how many? One, two, three, four, five, six. So, I I can do something like this. Uh, let me zoom out a bit. District. District. I can say the next thing is prefecture, population, area, latitude, longitude, and I like to like line up Oops. I like to line up the outputs like so. Like so. Like so. And because we know like um we know what the output is going to be like the schema because we're forcing GPT to use it. So we can like preemptively like do stuff like this. Bear with me. I think if you know what I'm going to do already, you know, feel free to just do it. And then we just put the property names in here like exactly in quotes. Let me just preemptively put these. Oh, actually, you're you're not supposed to use double quotes. Damn it. You're not supposed to use double quotes like inside string interpolation, I think. So, I think I should like make these single quotes. I think it will work, but it will like warn you not to do it. So, let me do something like this. And this this will likely run without crashing even though we're like doing a lot prefecture population area latitude. Okay. So, uh I will yeah I'll I'll break here. I'll get rid of this and I'll just uh start debugging this. I'm going to collapse this prompt in the schema. It's like quite big. Inku is like really crazy. Has some crazy architecture. So, okay, we're going to step over the content. We got our we got our message here. Oh, someone rang my doorbell. One moment. Okay. So here uh it's [snorts] going to load our JSON response into a proper dictionary object. We see it over here. Answer dictionary. We see district name, prefixure, population, area, latitude, longitude, etc. And then we we provided the schema so we knew exactly like what the property names are going to be. So this should just print without like without any any issue like so. And finish. Cool. And then we can do we can do like one more. Um, I'm not going to like change the prompt too much, but I just want to show you like because we provided the schema, we can we can pass like different things into here like every time. Describe the Congo, for example. And I'm I'm just going to run this without debugging cuz the housekeeper is like trying to clean my room. I'll probably do like two more just to like drill the fact home. See, it dumps all the stuff out. And then the same schema. We can keep the same code here because we it's predictable like what GPT is going to return because not only we used the response format type JSON property. We told it to respond to JSON and we provided a schema to it. So if we do this like every time, we can like repeatedly like use like the same prompt and everything and it will keep outputting like the same the same thing right for like whatever city or country or whatever we put in here. So I'll put like Nishinari. I'll do a couple more just to like drill this point home. Nishinari Osaka and then I usually live in I usually live here and then I'll do one in like I'll say like something obscure. I'll say it Mons. I think that's the moon mountain or something. And I don't know like you know what's going to come out. It might crash. Prefecture Mars population zero area very big latitude. And I'll say okay please describe uh this last one. I I don't know what's going to happen because this is not like a you know obviously I'll just run this without debugging but we if it if it doesn't crash I'll be like relatively surprised. Oh maybe there's a freaking actual city called banana. Okay. How about like elephant man boy chimp uh cake debugging? It might crash, but I don't know. That's so interesting. Um, it didn't crash um cuz we we hardcoded the schema in here and we told it to respond in JSON format. So, it just it just did its best, but it just got confused and set everything to zero. But it's still it still returned an object that had all of these properties in it. So, for example, I'll just like do this one one last thing and then we're going to end it. I'll just put like something obscure in here. Uh what's obscure? Uh I don't know. Uranium 238 flavored cheesecake something. I don't know. and I'll debug this and then we'll take a look at the response and then we'll like end this. I I'm just drilling the fact home that you can like for force GPT to respond in like a certain way with like a certain schema without crashing your your program. So, if we look at this um answer dictionary, population 238. Oh, it's like making jokes in here. Uranium 238 dessert. It's making jokes. It just made a joke. It it just did its best to fit the response format that I asked and it it shoved a bunch of like joke stuff in here. And then it it still it still did it and the program didn't crash because it adhered to the rules we provided it. So hopefully this makes sense. It got like a bit abstract in the end, but again, I was just trying to show you, you know, that you can force it to respond like a certain way. And in the [snorts] real world, this will this will make more sense and we're going to use it to like format uh our threat hunt results. But yeah, hopefully this makes sense. And if it doesn't, go to the forums, ask questions, tag me, use chat dbt, and we'll see you in the next lesson. Cool.
Welcome back. Uh this is a really interesting lesson. Uh, it's going to be like a bit of a difficult one, so just do your best to pay attention and get ready to ask questions in the forums if you need to. Um, I was having trouble coming up with a actual title for this lesson. I think I'm going to call it something like um making sense out of user ambiguous input or or something like this. Um, like we basically want we want to take some input from the user and then distill it down to what exactly they they meant like their true intention and then use that to make some kind of decision in our code. And you'll see like exactly what I mean in just a second. And you need um two files with this one. Of course, you can like type everything out if you want to. And I do kind of recommend that just for muscle memory, but I'm going to include this like um what is it? This node tools main.py py and this tools main.py. Um, so just like get them from the link or the yeah the link below and then add them to your folder and then open your folder in VS Code. But basically I'm just going to explain uh what this program does and then we're going to this is a program without using open AI or without using any any AI at all. And I'm going to show you like I'm going to use this program um to show you why what we're trying to do is useful like why this the tools mechanism or the open AI function selector I forget what it's called but anyway you'll get an idea of the problem with this code and then we're going to solve it with inside of the tools.mmain. py if that makes sense. So basically what this program does I'll just explain it and then I'll run it. We have like a list of unhealthy foods. And by the way, don't get caught up on like like candies can be healthy. Like just, you know, bear with me on this. So we have like a list of unhealthy foods. And then we have like a list of healthy foods. And basically we ask the user like what is your favorite food? And then based on their answer we decide um you know we just make the decision that the person is healthy or the person is like or sorry the person is unhealthy or the person is healthy based on their favorite food. So if someone's favorite food is donuts, right, we can based on this code anyway, we can make the assumption that the person is not healthy and then later later on in the code, if the person is healthy, we give them a praise and if the person is unhealthy, we like, you know, scold them, right? Um but if we we can't make the decision like we don't know, like we're going to just say we don't know, right? So we're just going to run this program. Um, I will break it right here after we get the user input. So, I'll say run, start debugging and you'll see like why this is troublesome. So, what is your favorite food? I'm going to say vegetables, right? I'll say vegetables and then we'll step over this and this says like the answer is vegetables cuz we typed it. So, we look is if answer is in unhealthy foods, we're going to say that they are not healthy. So vegetables is not in here. So if we try to step it will skip over it. So we're going to check is answer inside of healthy foods. Looks like vegetables is in here. So like so person is healthy gets assigned to true. And then it says if person is healthy equals true. They do or I guess it is. So it prints good job. Keep it up. And then the program finishes like so. And then likewise, um, I'll run this one more time for example. And I'm going to run it without debugging this time. I'm just going to let the output show. Or maybe I should I should debug it actually so people can get a sense. So I'll I'll debug it. So it's asking uh what is your favorite food? I'm going to say like donuts this time. I'll say donuts. I'll say enter. And then the person the person is unhealthy, right? It got assigned person is healthy is false. If person is healthy, true. They're not. It skips. If person is healthy equals false, it is because they're not healthy because they eat donuts. And then it prints to the screen, you need to make better choices. And then finish. So, uh, what if we want to like enter a food that's, you know, that's unhealthy, right? But it's not in these lists, right? So, I'll run this again. I'll debug it and I will say like what's something that's not healthy? Uh, like Twinkie, maybe. I'll say Twinkie Twinky Twinkies. So, it's going to check is an Twinkies is it's not healthy, right? Everybody knows this. So, we're going to but we're going to look in unhealthy foods. Is it uh in here? And it's not actually. Um, is it in healthy foods? It's not. And so, it will default to person is healthy equals none cuz like we don't know. We couldn't discern if they're true if it's like they're healthy or not, right? So person is health equals true. This is not true. Person is health equals false. That's not true either. So it defaults to I don't know. It prints I don't know. And then the program finishes. So like an easy a really easy way to fix this. We can just say like okay like you know Twinkies are not healthy. Twinkies, right? We can just simply add it to the unhealthy food list. So we'll like run this again. We'll debug it. So what is your favorite food? I'll say Twinkies. And then is answer inside of unhealthy foods? It is here. So naturally they get assigned person is healthy equals false. Got to show that these are like actually like separate. Um, so what goes down to here is person healthy equal true? It's not because it's false. Oh I I messed this up. Oh my god. It's okay. Is person healthy is per person healthy equals false? That's true. So that will print. You need to make better choices. And then the program finishes. But what if you know we debug this again? And then what if we want to say something like uh what's like what's something else that's unhealthy, right? Like a a giant cake for for example or a giant red cake for example, right? You can see like where this is going. like giant red cake is not in this list, right? So, you know, it doesn't know how to answer. So, it just sets it to like none because it doesn't know if they're healthy or not based on our parameters. So, again, it's going to print I don't know. So, yeah, of course, we can fix this by adding like, you know, giant red cake, but you can kind of see where this is going. There's basically like infinite number of stuff that's unhealthy and like infinite number of stuff that's healthy like effectively infinite. So you need some kind of like cognition like not a hard-coded list but you need some kind of like cognition to make the discernation or make is that the right word to make the decision whether or not something is healthy or not. And then this is where like Chad GBT uh and Open AI and I guess LLMs in general come into play to help with this. So we're kind of done with this. no no tools.m main uh function here. So we'll just say well we can save it. Doesn't really Oops. It doesn't really matter. So we're going to move to I'm going to close this. Close this. So next we're going to move into tools.main and then I'll kind of explain like how this works. I suppose I'll just run the program first and then you can kind of see what happens. Um, and I will I'll run this without debugging it. I'll just let it run through and then I'll explain everything in the end. So, I'm just going to clear this output down here and then I will just say run without debugging. And then, what is your favorite food? a giant god damn red cake filled with Twinkie and uh ding-dongs, for example. Obviously, we don't this is not going to be in any list anywhere, right? So, we'll just like run this and then our program runs. It returns. Oh, I should like uh stop printing these. I'm going to like comment these two out, but it says, "Oh no, that cake is a heart attack waiting to happen. Seriously, stop eating junk. Eat some real food before your arteries uh file force." Okay, so I'll I'll run this one more time and I'll say like a healthy food for once. So I'll say like start uh run without debugging. What's your favorite food? Um, a fresh hot bad spelling giant Atlantic salmon uh with lemon and a side mall of course of brown rice. Sounds healthy enough. So, we have a response. Good job. That's an awesome meal. Fresh salmon blah blah blah. It's it's healthy, right? So, basically um we have to use like you know the the way our code is set up, right? It basically will like figure out if the person is healthy or not and if they are if they are healthy they're going to print good job and like note to user like this random message and if they're not healthy it's going to print oh no and then no to user right so basically I forget what this thing is actually called I think it's called like a open AI functions or something like this and the way I'm using it in here is not I don't think it's the intended way for it to be used but basically um if you recall All this this thing is what we've been using to ask chat GPD questions or rather the open AAI like GPT endpoint where we specify like the model and then we specify like the the prompt like the message. Um but now we're passing like two special things. Uh one one thing [snorts] is tools. This tools variable is like non-negotiable but we're we have to pass it like a special object and then a tool choice which I'll kind of explain. Um, we can say like auto or required or maybe something else. But this this lifestyle assessment tools, I'm going to expand this and kind of explain what it is. So the tools were passing this this basically just passes a bunch of context to chat GPT. And it has to be in this format. So don't worry about being like, oh, this format is like uh confusing. I have to memorize it. Like you don't have to memorize it. I just I learned this from probably Google or like their API documentation and I just like retrofitted it to what I wanted to do. So don't get too hung up on that, but I'll just kind of explain it. Um so type is function. Um just take this face value for what it is. You can kind of ignore it. And then this is the actual function and the name. We're not actually using the name, but the description is like what's important. Um, I'm giving it context for what I'm trying to do. Like a lifestyle recommendation. Like this is going to return a lifestyle recommendation for the user based on their favorite food. If a user's favorite food is sweets or unhealthy, encourage them to eat healthy. If their favorite food is something healthy, encourage them to keep going. Be extremely blunt. For example, if their favorite food is Crisco, you might recommend that they take make some serious changes. This prompt is like really bad, but you get like the gist of it. like we're we're going to assess what the user is like eating like what their favorite food is and then we're going to make recommendations based on their favorite food and then this parameters um this is basically what uh GPT is going to return to us and this will make like a lot of sense later but basically um it's going to when it inspects their prompts it's going to take this stuff into consideration and then it's going to make some kind of decisions in its big AI brain and then it's going to return this stuff to us. So for example, person is healthy. This is a boolean. So it's going to return person is healthy, true or false based on this. And the description of this person is healthy is a boolean value to determine if the person is healthy based on their favorite foods. Assume they consume this thing regularly that they entered. This is like more context for GPT. And then this other thing, note to user, this is a string that it's going to return. Recommendation to the user. uh for example, good job, keep it up, or stop eating junk. So, basically, we're going to feed the prompt into chat GBT. We're going to give it this context, and then we're going to tell it, you need to return these two things to us. And then we're telling it, uh it's required to return both of these things. So, this is like the lifestyle the lifestyle assessment tools that GPT will use to kind of uh make a decision or it's extra context for it, we can say. So, this is like kind of the same thing. Um, I'm just going to break this and run it again. So, I'll start debugging just so you can like walk through it and observe. I know this is like a bit confusing. Um, but that's just kind of how it works. So, what is your favorite food? I'll say like um you know what's something dumb? Uh, I'll say blueprint protein powder by Brian Johnson. Don't die brand for example. Enter. And then we have our prompt here. Blueprint powder. Blueprint protein powder by Brian Johnson is like don't die thing. So it's going to ask Chad GBT and it's going to pass this is a model we want to use. This is our prompt. And then it's going to pass this whole whole lifestyle assessment tools object into the tools parameter. And then the tool choice is required. So it it needs to choose um uh it needs to choose oh my gosh I don't actually know. Oh, it it needs to choose something. I think that's what this is. It has to like return something to us. It can't say that there's like nothing, right? So it has to like do its best to choose um something from here and like it has to use the tools. So we'll like continue with this. So and it's asking GBT now. And so we're going to
extract um the answer. And then we're going to extract or we're going to convert the answer into a dictionary object or JSON object. So if we expand this, we can see like a answer dict. This is like the actual JSON object that got returned. It says person is healthy equals true. And then this is the custom message. Good job. You actually prioritize quality protein like Brian Johnson blah blah blah. But we'll let this finish and I'll show you some more stuff.
So it extra it extracted those and it assigned two variables note to user and then person is healthy and then if person is healthy if this is equal to true it's going to print this stuff good job and then this is healthy blah blah blah and then the the program finishes like so. So I'm going to do like a couple more of these. I'll just like let it run through. You can debug yours if you want if you want to really inspect it. Um, but I'm just going to run this a couple of times and then I'm going to like augment the tools a bit and augment our code. Um, just for some like extra stuff to show you to show you something and give more context. Give more context.
So, I'll just run this without debugging. And then I'll give it like something difficult. A giant Caesar salad filled with chicken breast. bad spelling. And uh with 3x Caesar dressing and croutons, whatever, and bacon and a bunch of cheese. This could like kind of go either way, but probably because of my verbiage, it's not going to like it. Oh no, you crammed a salad with fried chicken, extra dressing, blah blah blah. He kind of makes fun of me for for doing that.
So, I'll just do like one more. I'll say start debugging and I'll say I don't know what's something else that's interesting. Um, 10 raw eggs. So, it it doesn't like this. Um, but you kind of like get the idea. So we can like augment this a bit. For example, if we want to return um we want to return something else like right now we're just returning if the person is healthy or a note to the us and a note to the user which is like this note that it's giving us stop eating raw eggs blah blah blah. Um we can we can augment it and we can do more.
Or so I'm just going to like copy this and then I'll paste it and I'll say like uh I'll call this one self justification for example and then for this and then I'll say something like um this is the reason for your choice if you decided the user was not healthy or healthy based on their favorite food. You have to explain why here. So self-justification they called it this. So for example, I'll scroll down. reason we can say answer dict so and then I'll pause it here so we can actually like see um this answer dict is what gets returned from chat GBT um based on this tools function like we told it what we what needs to be returned oh I need to like put this here too so I'll put this is required so it needs to say something it needs needs to return it.
So, I'm just going to start debugging this. What is your favorite food? Um, I'll say uh vegan brownies. Brownies made Oh my god. made with cacao powder and pineapple whatever juice as a sweetener. So, and then it's going to ask GPT. So, this will take a couple seconds. Let it do this and expand this. I'll like look through this so you can like really see it.
So this is the response that we got from GPT. It's like a pretty big object. So if we look in here, response choices and then the zeroth element. So if we go to response choices and then zeroith element and then message tool calls, we go to message tool calls and then the zerowith element in here like so. Um, this is I think the answer should be in here. Oh, it should be function. Oh, so this thing, this tool calls this whole thing inside of here is going to get assigned to this answer variable. So if we like step over this and then we have our answer variable. So if I go up here and then answer function arguments. So answer function arguments and then this this is the thing um that GPT returned. It returned like a a JSON string. It's a string but it's JSON. Um where we can see personality is true and we can see a note to user and then we can see like the the justification should be in here as well. Um, but it's like really long.
So, I'm just going to um step over this. And then we can see our answer dict. And then we see like person is healthy, true. We see note to the user, which is like what we're going to tell the user. And then this is the justification. Um, we can see it here. It's a bit like, you know, hard to read. It's quite long. Uh, let me see if I can like do this because I forgot to print it to the screen. So, I'll just like paste it. This is the justification of why GPT um decided it was healthy. Cacao powder provides antioxidants. Pineapple is a sweetener. A big upgrade over processed sugar. Blah blah blah. This is its justification. So, we can just print this out as usual. Um, I didn't actually use the justification. I just like assigned it. So, and then we can maybe we can like augment this. Um, me like [snorts] do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh "extract um the answer. And then we're going to extract or we're going to convert the answer into a dictionary object or JSON object. So if we expand this, we can see like a answer dict. This is like the actual JSON object that got returned. It says person is healthy equals true. And then this is the custom message. Good job. You actually prioritize quality protein like Brian Johnson blah blah blah. But we'll let this finish and I'll show you some more stuff.
So it extra it extracted those and it assigned two variables note to user and then person is healthy and then if person is healthy if this is equal to true it's going to print this stuff good job and then this is healthy blah blah blah and then the the program finishes like so. So I'm going to do like a couple more of these. I'll just like let it run through. You can debug yours if you want if you want to really inspect it. Um, but I'm just going to run this a couple of times and then I'm going to like augment the tools a bit and augment our code. Um, just for some like extra stuff to show you to show you something and give more context. Give more context.
So, I'll just run this without debugging. And then I'll give it like something difficult. A giant Caesar salad filled with chicken breast. bad spelling. And uh with 3x Caesar dressing and croutons, whatever, and bacon and a bunch of cheese. This could like kind of go either way, but probably because of my verbiage, it's not going to like it. Oh no, you crammed a salad with fried chicken, extra dressing, blah blah blah. He kind of makes fun of me for for doing that.
So, I'll just do like one more. I'll say start debugging and I'll say I don't know what's something else that's interesting. Um, 10 raw eggs. So, it it doesn't like this. Um, but you kind of like get the idea. So we can like augment this a bit. For example, if we want to return um we want to return something else like right now we're just returning if the person is healthy or a note to the us and a note to the user which is like this note that it's giving us stop eating raw eggs blah blah blah. Um we can we can augment it and we can do more.
Or so I'm just going to like copy this and then I'll paste it and I'll say like uh I'll call this one self justification for example and then for this and then I'll say something like um this is the reason for your choice if you decided the user was not healthy or healthy based on their favorite food. You have to explain why here. So self-justification they called it this. So for example, I'll scroll down. reason we can say answer dict so and then I'll pause it here so we can actually like see um this answer dict is what gets returned from chat GBT um based on this tools function like we told it what we what needs to be returned oh I need to like put this here too so I'll put this is required so it needs to say something it needs needs to return it.
So, I'm just going to start debugging this. What is your favorite food? Um, I'll say uh vegan brownies. Brownies made Oh my god. made with cacao powder and pineapple whatever juice as a sweetener. So, and then it's going to ask GPT. So, this will take a couple seconds. Let it do this and expand this. I'll like look through this so you can like really see it.
So this is the response that we got from GPT. It's like a pretty big object. So if we look in here, response choices and then the zeroth element. So if we go to response choices and then zeroith element and then message tool calls, we go to message tool calls and then the zerowith element in here like so. Um, this is I think the answer should be in here. Oh, it should be function. Oh, so this thing, this tool calls this whole thing inside of here is going to get assigned to this answer variable. So if we like step over this and then we have our answer variable. So if I go up here and then answer function arguments. So answer function arguments and then this this is the thing um that GPT returned. It returned like a a JSON string. It's a string but it's JSON. Um where we can see personality is true and we can see a note to user and then we can see like the the justification should be in here as well. Um, but it's like really long.
So, I'm just going to um step over this. And then we can see our answer dict. And then we see like person is healthy, true. We see note to the user, which is like what we're going to tell the user. And then this is the justification. Um, we can see it here. It's a bit like, you know, hard to read. It's quite long. Uh, let me see if I can like do this because I forgot to print it to the screen. So, I'll just like paste it. This is the justification of why GPT um decided it was healthy. Cacao powder provides antioxidants. Pineapple is a sweetener. A big upgrade over processed sugar. Blah blah blah. This is its justification. So, we can just print this out as usual. Um, I didn't actually use the justification. I just like assigned it. So, and then we can maybe we can like augment this. Um, me like [snorts] do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh *[snorts]* do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh "extract um the answer. And then we're going to extract or we're going to convert the answer into a dictionary object or JSON object. So if we expand this, we can see like a answer dict. This is like the actual JSON object that got returned. It says person is healthy equals true. And then this is the custom message. Good job. You actually prioritize quality protein like Brian Johnson blah blah blah. But we'll let this finish and I'll show you some more stuff.
So it extra it extracted those and it assigned two variables note to user and then person is healthy and then if person is healthy if this is equal to true it's going to print this stuff good job and then this is healthy blah blah blah and then the the program finishes like so. So I'm going to do like a couple more of these. I'll just like let it run through. You can debug yours if you want if you want to really inspect it. Um, but I'm just going to run this a couple of times and then I'm going to like augment the tools a bit and augment our code. Um, just for some like extra stuff to show you to show you something and give more context. Give more context.
So, I'll just run this without debugging. And then I'll give it like something difficult. A giant Caesar salad filled with chicken breast. bad spelling. And uh with 3x Caesar dressing and croutons, whatever, and bacon and a bunch of cheese. This could like kind of go either way, but probably because of my verbiage, it's not going to like it. Oh no, you crammed a salad with fried chicken, extra dressing, blah blah blah. He kind of makes fun of me for for doing that.
So, I'll just do like one more. I'll say start debugging and I'll say I don't know what's something else that's interesting. Um, 10 raw eggs. So, it it doesn't like this. Um, but you kind of like get the idea. So we can like augment this a bit. For example, if we want to return um we want to return something else like right now we're just returning if the person is healthy or a note to the us and a note to the user which is like this note that it's giving us stop eating raw eggs blah blah blah. Um we can we can augment it and we can do more.
Or so I'm just going to like copy this and then I'll paste it and I'll say like uh I'll call this one self justification for example and then for this and then I'll say something like um this is the reason for your choice if you decided the user was not healthy or healthy based on their favorite food. You have to explain why here. So self-justification they called it this. So for example, I'll scroll down. reason we can say answer dict so and then I'll pause it here so we can actually like see um this answer dict is what gets returned from chat GBT um based on this tools function like we told it what we what needs to be returned oh I need to like put this here too so I'll put this is required so it needs to say something it needs needs to return it.
So, I'm just going to start debugging this. What is your favorite food? Um, I'll say uh vegan brownies. Brownies made Oh my god. made with cacao powder and pineapple whatever juice as a sweetener. So, and then it's going to ask GPT. So, this will take a couple seconds. Let it do this and expand this. I'll like look through this so you can like really see it.
So this is the response that we got from GPT. It's like a pretty big object. So if we look in here, response choices and then the zeroth element. So if we go to response choices and then zeroith element and then message tool calls, we go to message tool calls and then the zerowith element in here like so. Um, this is I think the answer should be in here. Oh, it should be function. Oh, so this thing, this tool calls this whole thing inside of here is going to get assigned to this answer variable. So if we like step over this and then we have our answer variable. So if I go up here and then answer function arguments. So answer function arguments and then this this is the thing um that GPT returned. It returned like a a JSON string. It's a string but it's JSON. Um where we can see personality is true and we can see a note to user and then we can see like the the justification should be in here as well. Um, but it's like really long.
So, I'm just going to um step over this. And then we can see our answer dict. And then we see like person is healthy, true. We see note to the user, which is like what we're going to tell the user. And then this is the justification. Um, we can see it here. It's a bit like, you know, hard to read. It's quite long. Uh, let me see if I can like do this because I forgot to print it to the screen. So, I'll just like paste it. This is the justification of why GPT um decided it was healthy. Cacao powder provides antioxidants. Pineapple is a sweetener. A big upgrade over processed sugar. Blah blah blah. This is its justification. So, we can just print this out as usual. Um, I didn't actually use the justification. I just like assigned it. So, and then we can maybe we can like augment this. Um, me like [snorts] do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh *[snorts]* do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh
```
extract um the answer. And then we're going to extract or we're going to convert the answer into a dictionary object or JSON object. So if we expand this, we can see like a answer dict. This is like the actual JSON object that got returned. It says person is healthy equals true. And then this is the custom message. Good job. You actually prioritize quality protein like Brian Johnson blah blah blah. But we'll let this finish and I'll show you some more stuff.
So it extra it extracted those and it assigned two variables note to user and then person is healthy and then if person is healthy if this is equal to true it's going to print this stuff good job and then this is healthy blah blah blah and then the the program finishes like so. So I'm going to do like a couple more of these. I'll just like let it run through. You can debug yours if you want if you want to really inspect it. Um, but I'm just going to run this a couple of times and then I'm going to like augment the tools a bit and augment our code. Um, just for some like extra stuff to show you to show you something and give more context. Give more context.
So, I'll just run this without debugging. And then I'll give it like something difficult. A giant Caesar salad filled with chicken breast. bad spelling. And uh with 3x Caesar dressing and croutons, whatever, and bacon and a bunch of cheese. This could like kind of go either way, but probably because of my verbiage, it's not going to like it. Oh no, you crammed a salad with fried chicken, extra dressing, blah blah blah. He kind of makes fun of me for for doing that.
So, I'll just do like one more. I'll say start debugging and I'll say I don't know what's something else that's interesting. Um, 10 raw eggs. So, it it doesn't like this. Um, but you kind of like get the idea. So we can like augment this a bit. For example, if we want to return um we want to return something else like right now we're just returning if the person is healthy or a note to the us and a note to the user which is like this note that it's giving us stop eating raw eggs blah blah blah. Um we can we can augment it and we can do more.
Or so I'm just going to like copy this and then I'll paste it and I'll say like uh I'll call this one self justification for example and then for this and then I'll say something like um this is the reason for your choice if you decided the user was not healthy or healthy based on their favorite food. You have to explain why here. So self-justification they called it this. So for example, I'll scroll down. reason we can say answer dict so and then I'll pause it here so we can actually like see um this answer dict is what gets returned from chat GBT um based on this tools function like we told it what we what needs to be returned oh I need to like put this here too so I'll put this is required so it needs to say something it needs needs to return it.
So, I'm just going to start debugging this. What is your favorite food? Um, I'll say uh vegan brownies. Brownies made Oh my god. made with cacao powder and pineapple whatever juice as a sweetener. So, and then it's going to ask GPT. So, this will take a couple seconds. Let it do this and expand this. I'll like look through this so you can like really see it.
So this is the response that we got from GPT. It's like a pretty big object. So if we look in here, response choices and then the zeroth element. So if we go to response choices and then zeroith element and then message tool calls, we go to message tool calls and then the zerowith element in here like so. Um, this is I think the answer should be in here. Oh, it should be function. Oh, so this thing, this tool calls this whole thing inside of here is going to get assigned to this answer variable. So if we like step over this and then we have our answer variable. So if I go up here and then answer function arguments. So answer function arguments and then this this is the thing um that GPT returned. It returned like a a JSON string. It's a string but it's JSON. Um where we can see personality is true and we can see a note to user and then we can see like the the justification should be in here as well. Um, but it's like really long.
So, I'm just going to um step over this. And then we can see our answer dict. And then we see like person is healthy, true. We see note to the user, which is like what we're going to tell the user. And then this is the justification. Um, we can see it here. It's a bit like, you know, hard to read. It's quite long. Uh, let me see if I can like do this because I forgot to print it to the screen. So, I'll just like paste it. This is the justification of why GPT um decided it was healthy. Cacao powder provides antioxidants. Pineapple is a sweetener. A big upgrade over processed sugar. Blah blah blah. This is its justification. So, we can just print this out as usual. Um, I didn't actually use the justification. I just like assigned it. So, and then we can maybe we can like augment this. Um, me like [snorts] do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh "extract um the answer. And then we're going to extract or we're going to convert the answer into a dictionary object or JSON object. So if we expand this, we can see like a answer dict. This is like the actual JSON object that got returned. It says person is healthy equals true. And then this is the custom message. Good job. You actually prioritize quality protein like Brian Johnson blah blah blah. But we'll let this finish and I'll show you some more stuff.
So it extra it extracted those and it assigned two variables note to user and then person is healthy and then if person is healthy if this is equal to true it's going to print this stuff good job and then this is healthy blah blah blah and then the the program finishes like so. So I'm going to do like a couple more of these. I'll just like let it run through. You can debug yours if you want if you want to really inspect it. Um, but I'm just going to run this a couple of times and then I'm going to like augment the tools a bit and augment our code. Um, just for some like extra stuff to show you to show you something and give more context. Give more context.
So, I'll just run this without debugging. And then I'll give it like something difficult. A giant Caesar salad filled with chicken breast. bad spelling. And uh with 3x Caesar dressing and croutons, whatever, and bacon and a bunch of cheese. This could like kind of go either way, but probably because of my verbiage, it's not going to like it. Oh no, you crammed a salad with fried chicken, extra dressing, blah blah blah. He kind of makes fun of me for for doing that.
So, I'll just do like one more. I'll say start debugging and I'll say I don't know what's something else that's interesting. Um, 10 raw eggs. So, it it doesn't like this. Um, but you kind of like get the idea. So we can like augment this a bit. For example, if we want to return um we want to return something else like right now we're just returning if the person is healthy or a note to the us and a note to the user which is like this note that it's giving us stop eating raw eggs blah blah blah. Um we can we can augment it and we can do more.
Or so I'm just going to like copy this and then I'll paste it and I'll say like uh I'll call this one self justification for example and then for this and then I'll say something like um this is the reason for your choice if you decided the user was not healthy or healthy based on their favorite food. You have to explain why here. So self-justification they called it this. So for example, I'll scroll down. reason we can say answer dict so and then I'll pause it here so we can actually like see um this answer dict is what gets returned from chat GBT um based on this tools function like we told it what we what needs to be returned oh I need to like put this here too so I'll put this is required so it needs to say something it needs needs to return it.
So, I'm just going to start debugging this. What is your favorite food? Um, I'll say uh vegan brownies. Brownies made Oh my god. made with cacao powder and pineapple whatever juice as a sweetener. So, and then it's going to ask GPT. So, this will take a couple seconds. Let it do this and expand this. I'll like look through this so you can like really see it.
So this is the response that we got from GPT. It's like a pretty big object. So if we look in here, response choices and then the zeroth element. So if we go to response choices and then zeroith element and then message tool calls, we go to message tool calls and then the zerowith element in here like so. Um, this is I think the answer should be in here. Oh, it should be function. Oh, so this thing, this tool calls this whole thing inside of here is going to get assigned to this answer variable. So if we like step over this and then we have our answer variable. So if I go up here and then answer function arguments. So answer function arguments and then this this is the thing um that GPT returned. It returned like a a JSON string. It's a string but it's JSON. Um where we can see personality is true and we can see a note to user and then we can see like the the justification should be in here as well. Um, but it's like really long.
So, I'm just going to um step over this. And then we can see our answer dict. And then we see like person is healthy, true. We see note to the user, which is like what we're going to tell the user. And then this is the justification. Um, we can see it here. It's a bit like, you know, hard to read. It's quite long. Uh, let me see if I can like do this because I forgot to print it to the screen. So, I'll just like paste it. This is the justification of why GPT um decided it was healthy. Cacao powder provides antioxidants. Pineapple is a sweetener. A big upgrade over processed sugar. Blah blah blah. This is its justification. So, we can just print this out as usual. Um, I didn't actually use the justification. I just like assigned it. So, and then we can maybe we can like augment this. Um, me like [snorts] do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh "extract um the answer. And then we're going to extract or we're going to convert the answer into a dictionary object or JSON object. So if we expand this, we can see like a answer dict. This is like the actual JSON object that got returned. It says person is healthy equals true. And then this is the custom message. Good job. You actually prioritize quality protein like Brian Johnson blah blah blah. But we'll let this finish and I'll show you some more stuff.
So it extra it extracted those and it assigned two variables note to user and then person is healthy and then if person is healthy if this is equal to true it's going to print this stuff good job and then this is healthy blah blah blah and then the the program finishes like so. So I'm going to do like a couple more of these. I'll just like let it run through. You can debug yours if you want if you want to really inspect it. Um, but I'm just going to run this a couple of times and then I'm going to like augment the tools a bit and augment our code. Um, just for some like extra stuff to show you to show you something and give more context. Give more context.
So, I'll just run this without debugging. And then I'll give it like something difficult. A giant Caesar salad filled with chicken breast. bad spelling. And uh with 3x Caesar dressing and croutons, whatever, and bacon and a bunch of cheese. This could like kind of go either way, but probably because of my verbiage, it's not going to like it. Oh no, you crammed a salad with fried chicken, extra dressing, blah blah blah. He kind of makes fun of me for for doing that.
So, I'll just do like one more. I'll say start debugging and I'll say I don't know what's something else that's interesting. Um, 10 raw eggs. So, it it doesn't like this. Um, but you kind of like get the idea. So we can like augment this a bit. For example, if we want to return um we want to return something else like right now we're just returning if the person is healthy or a note to the us and a note to the user which is like this note that it's giving us stop eating raw eggs blah blah blah. Um we can we can augment it and we can do more.
Or so I'm just going to like copy this and then I'll paste it and I'll say like uh I'll call this one self justification for example and then for this and then I'll say something like um this is the reason for your choice if you decided the user was not healthy or healthy based on their favorite food. You have to explain why here. So self-justification they called it this. So for example, I'll scroll down. reason we can say answer dict so and then I'll pause it here so we can actually like see um this answer dict is what gets returned from chat GBT um based on this tools function like we told it what we what needs to be returned oh I need to like put this here too so I'll put this is required so it needs to say something it needs needs to return it.
So, I'm just going to start debugging this. What is your favorite food? Um, I'll say uh vegan brownies. Brownies made Oh my god. made with cacao powder and pineapple whatever juice as a sweetener. So, and then it's going to ask GPT. So, this will take a couple seconds. Let it do this and expand this. I'll like look through this so you can like really see it.
So this is the response that we got from GPT. It's like a pretty big object. So if we look in here, response choices and then the zeroth element. So if we go to response choices and then zeroith element and then message tool calls, we go to message tool calls and then the zerowith element in here like so. Um, this is I think the answer should be in here. Oh, it should be function. Oh, so this thing, this tool calls this whole thing inside of here is going to get assigned to this answer variable. So if we like step over this and then we have our answer variable. So if I go up here and then answer function arguments. So answer function arguments and then this this is the thing um that GPT returned. It returned like a a JSON string. It's a string but it's JSON. Um where we can see personality is true and we can see a note to user and then we can see like the the justification should be in here as well. Um, but it's like really long.
So, I'm just going to um step over this. And then we can see our answer dict. And then we see like person is healthy, true. We see note to the user, which is like what we're going to tell the user. And then this is the justification. Um, we can see it here. It's a bit like, you know, hard to read. It's quite long. Uh, let me see if I can like do this because I forgot to print it to the screen. So, I'll just like paste it. This is the justification of why GPT um decided it was healthy. Cacao powder provides antioxidants. Pineapple is a sweetener. A big upgrade over processed sugar. Blah blah blah. This is its justification. So, we can just print this out as usual. Um, I didn't actually use the justification. I just like assigned it. So, and then we can maybe we can like augment this. Um, me like [snorts] do something like this. Let me add like a couple of like line breaks or whatever so it's like easier to read. And then maybe I'll do something here. Print reason. I think I assigned the justification. I did. I assigned the justification to the reason variable so it will just like I'm going to use an f string here just so I can uh maybe do a line break before it or something. This is going to look uh no that's probably okay.
Okay. So I'll just like do another one just for fun. So we'll run this. So I will I'll just run this without debugging once. You can debug yours if you want. So what is your favorite food? I'll say a pizza with uh crust made of chicken breast and what's that cheese? Parmesan made crispy. Double baked. uh low sodium uh sodium sauce and fresh fresh mozzarella. I don't know how to spell mozzarella, but whatever. Fresh mozzarella cheese. I will say this, this is could go either way. You don't we don't know, right? Boom. Good job. Nice job. This pizza is like whatever. It's good for you and high protein, low unnecessary carbs. And then this is like the justification that it gave. So maybe I maybe I should like do like say back slash and justification. And then I will like uh do one of these. Actually I don't need to. This is like redundant code because we're going to print note to user anyway. So I'll say print um I'll say note to user then I'll say note to user like so and then I will maybe I'll do like one more and then I will I'll break this one and we'll step through it.
What is your favorite food? Uh, what is in my room right now? Okay, I have this thing the hotel gave me. Kakatan with cheese cream cheese in cockatane cheese. It says this all over the box. Cheese black pepper. Uh, buraku pep cuz I'm in Japan. Cheese. Wow. Okay, that's my favorite food. I just typed what was on the box. So, uh, we will I'll just like continue this and we'll should break down here. Oh, it didn't. Okay, I'll continue this again. And then it's going to extract the answer. And then it's going to pull this out of the dictionary. So note to user person is healthy. Uh I can see it's false on the left already. And the reason um I'll just like let this print I guess. Oh sorry didn't do that. Let this print. Uh person is not healthy. So it skipped to here. Said oh no note to user. Uh that's a cheese overloaded with processed snacks and intense flavors. You should try toning it down with some veggies and fruit once in a while. Your arters will thank you. And this cheese like it does taste like really it's like a cracker. It's like quite weird. Uh it tastes [snorts] okay. It tastes okay, but And the justification uh I don't kakatane cream cheese with extra black pepper is a high sodium, highfat snack. It's heavily processed. Oh yeah. Okay. I could have guessed that much. Um but yeah, hope this makes sense.
Um, actually while we're here I'm just going to like add one more thing in here. Um maybe so now we have like person we we're going to have it return person is healthy a note to the user selfjustification and then we're going to add one more like a alternate alternative suggestion or something like this. So like instead of this why don't you have this? So I'll say like alternate suggestion. So we can say um suggest I don't know an alternate more healthy thing if the user uh I don't know I don't know. Okay, I'll say suggest suggest a more healthy thing regardless of if the whatever use I'm going to put bad spelling on purpose. Users favorite food is healthy or not. And then I'll add that here. Alternate suggestion like so. Oops. And then I'll go down here. And then I'll just copy this alter suggestion. My gosh. Alternate suggestion like so. And then I'll like I'll just like add this down here as well. We'll say print use an f string alternate alter. Oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh
```
expected to see like rows or something like this. Columns time generated. I assume there's like rows somewhere. Oh, it's here. No, data frame KQ query. I wonder why that is in here. That's so interesting. Oh. Oh, this is the uh I think this is it. Underscore values maybe. Size 380. That's interesting. I don't know why it's like only that many long when I had like a 100 records. But anyway, you kind of get the idea.
The main point of this was just to show you that we can like do KQL KQL queries with Python and then we can return the data and we can like observe it and kind of do something with it. So I'm just going to look in like one more table instead of device lo on events. I just want to show you that you can look in other tables as well. And there's like there's like a ton of tables. So for example, let me look what should we look at user behavior analytics. User peer analytics. I just want to like see what's in here. For example, behavior behavior analytics take 50. time process. Oh, this is interesting. Oh, okay. Failed log on. Oh, that's so interesting. Uh, okay.
So, we can take this just for instance. Instance, I want to do two more things in this lesson. So, I'll copy this. I just want to query another table just to get a sense that it's possible. So, I'll paste the query in here and I'll just like re rerun this and I'll just let it dump to the screen so we can observe it and we'll print it. And then we see it prints. Um, it looks like it it truncated like the um it summarized the rows too cuz there's like too many. They put like three dots because we didn't we didn't project anything. So for example this is the query right here. So if we want to like project only certain logs we can or certain rows we can say like uh project time generated uh maybe activity type action type username. The these are like the actual uh cyber branch usernames. Oh, maybe we should use user principle name and then event source source IP. This is like the actual Cyber Range member IP address. And this is why um I didn't talk about this in this course yet, but um if you're a Cyber Range member, your user principle name or your username that you log into the Cyber Range with is some like crazy um it's like a grid. It's this crazy number because we can see like the logs in the cyber range and if this says like you know Maggie would like whatever Maggie Wilcox uh inside of you know San Jose whatever and the IP address it like completely docks this the person you know um so it's you know this is why we did that and if your your organization can see similar things as well so you know just like bear that in mind I guess and then source IP location and maybe that's like that's like enough.
So, we're going to like run this query just to like see what it looks like. User principle name is blank. So, I'll just use username I guess. And then maybe I'll say like where action type or I'll say where I'm just giving you KQL like um lesson I guess we can say where is not empty action type and then and is not empty uh what is the other thing I said username. So, we'll run this. And now we see we see some like, you know, nice like healthy amount of logs. Um, whatever. So, we'll copy this. I'm just like doing an exercise, right? And we'll paste this in here. And I'll just say like take 25 or something. And we'll just run this again. And it's going to print. And then we see it prints the data frame out. Um, has like the time that happened, the activity, the IP address. [clears throat] This is probably the what is this? Oh, the location. It It looks like it truncated or like summarized and removed some of the rows as well. There's probably like some reason that it does this. Like it wants to print out really pretty and it's like too many rogues or something. I don't know. But if we want to and we will in the future, we can like programmatically like reach in here and like actually pull like turn this into a raw string and then we'll like send it to the G send it to the GPT API and then do threat hunting with it and everything. So the whole point of like pulling these logs is cuz we need them to like you know do threat hunting and like send to the model and stuff. So I just wanted to like have this lesson to show that it's actually possible to query log anal query log analytics workspace with Python. And hopefully this makes sense. Uh if you get stuck or have questions or anything um you know absolutely go to the cyber range forum and make a post and tag me and then uh you know let let us know what's wrong. Otherwise we will see you in the next lesson.
Welcome back. Uh welcome to the next lesson. U this one we're going to actually be quering log analytics workspace some more but we're going to be doing it in a more structured way um actually using a function and then um choosing the data that we select from the table uh in a more like kind of organized way and hopefully it makes sense as we go along. But um this lesson's going to be really important because we're going to build on top of it. We're going to build on top of it in the next lesson. Um, basically we're going to like work on uh optimizing our our query because you know in the end we're going to be building like a a AI sock analyst like agent like an agent that does threat hunting and basically like the more logs we send to chat GPT the more it costs you know so we want to really minimize the amount of logs that get sent to chat GPT so with this um we're going to like build on top of this a bit and make all of that make a lot of sense in the next lesson. So, I don't want to talk about that too much, but we'll just like hop into this one and I'll kind of uh explain what all of this is.
So, basically, um there's a lot of different tables that we can query uh and look up logs in inside [clears throat] of Log Analytics. So, for example, if you log into Azure, you know, portal. Log in with your cyber range username and you go to log analytics. It's our log repository. Take the cyber range one. Then go to logs and then close this. And if this says simple mode, change this to KQL mode. And then make KQL mode default. I don't. And then you'll see there's like tables here and then there's a lot of different tables. So different types of data gets logged in different tables inside of the environment. So for example um Azure activity well Azure activity is like if you create a virtual machine or like create any kind of like objects inside of the Azure portal it will get logged in Azure activity and sign logs is like um when you if somebody like logs into Azure like a cyber range member or something like this um it will log everything like the if it was a success or a failure like where they were etc. There's just a ton of logs in here, right? But for this exercise, um I'm just going to be working with like these logs in particular or these tables like so like device login on events. Um this is like if somebody tries to log into a virtual machine. This is like uh the cyber ranges network security group aka like the firewall and then Azure activity just stuff in the portal uh creating virtual machines, deleting stuff and then signin logs whenever somebody signs into Azure. So that's basically what these are.
And then this thing here. Uh this is a dictionary called fields and then for example this is like the table name and then these are the fields that um I want to query within the table. So for example um and I just like handpicked these. So I'll show you what I mean. So, if I go to if I copy device login events, then go to log analytics and just paste device login events, there's like there's too many fields. These are like the columns or fields. There's there's too many. There's a lot and we don't need a lot of them, right? And if we collect all of these, it just creates a lot of unnecessary tokens cuz we don't need to collect the tenant ID right every single time and send like ton of tenant ids to chai GPT cuz it doesn't help with our like I mean it might but it doesn't in our use case mostly it's not going to help find threats or whatever. So you can also say something like uh get schema like so and then run this and then you can see like the different fields aka columns and you see there's like there's a lot there's like 53 right you don't need all of these to do threat hunting so I just like handpicked out the ones that I thought were like most useful for like a simple threat hunt which is these for example we go to device lo on events we can use the project uh keyword I And then just like paste these and then then instead of returning like all like 53 columns it will it will just return like you know these six or whatever whatever we put 1 2 3 4 5 6. Yeah just six. Then let me see like what this actually yeah there's only 0 through five. So there's like six. And this will like cut down on our token usage a lot which we're going to talk about in the next lesson. So basically what I'm getting at is like all we have to do the way this query runs actually I'll just like I'll just run it and I'll show it to you. So you can do this along with me. So go ahead and break it here and we'll start debugging. And then you notice like for the table name I set it as Azure activity right like I preset it. So we will oh we'll just step over this we can see stuff getting assigned up here the variables the table name Azure activity and then the fields this is a big dictionary remember so key value key value key value etc and then 1 hour ago we're going to create our log analytics client um you have you had to have used a login on the command line at some point uh for this to work. And then this is just the function definition. So it's going to get built and then skip over this. This is a function definition. um the function didn't run but it just the interpreter like acknowledged its existence and now this is where the code actually like runs for the first time or rather this is where the code actually starts running. So we're going to call the query log analytics uh function and we're going to pass the log analytics client which is the client. Close this. We're going to pass the log analytics workspace ID which is going to replace this. We're going to pass the table name which is Azure activity which is going to get put into here. And then we're going to get the fields. So we're going to get the the fields that we want to use. Right? So remember this fields uh thing this variable is actually a dictionary and it contains uh the different fields that we want to project for each given table. So basically how this works if you remember like the way you access um a a value in a dictionary is you take the the variable name and then you pass the key here. In our case the key is Azure activity. So we use the fields variable and we pass Azure activity for the key and it's going to return the fields specifically for Azure activity. And I'll run this again in another way that hopefully makes more sense. And then hours ago is here. it gets it's going to get put into time span hours ago. So if I say step into now it will go into the actual function. This is the function and then now you can see like the client this is our like client that allows us to interact log analytics workspace ID the table name and then the fields that got extracted from the dictionary and then the time span which is just like should be 1 hour and then now it's going to create a variable called KQL query and it's actually it's just going to build a KQL query that's like literally all this is so it's taking the table name like so and then it's projecting the relevant fields like so. So we'll let this build. The KQL query gets built in the function. And then if we look at it, it's like a bit uh weird to look at here, but if we print it down below, this this is KQL query, right? So if we copy this just for example, you don't have to do this, but let me go here and paste it. This is like the the query that got that got created and this is what's going to run actually inside of our inside of Python. So we will step over this. It's going to get the response and take out the tables item and then or this is a list and then the zero with element. So inside of response and then tables and then element zero and it's going to store that in table result. So it's going to store like this stuff in table result. So if we step over now we have a variable called table result and we can see the stuff inside has like the columns column types the schema and then the rows. So if we step over this, this gets returned like this is where the function got called and then table results got returned to results like so. So we have a new variable called results that has all of our the query results in it. And we're going to say if rows is equal to zero means it's empty. So just exit the program. It's not. So it skips down here and then pulls out the columns. Pulls out the rows. So now we have like a columns rather we have columns here then we have rows here. So in the the data frame it's going to build a data frame again. If we look at the data frame this is similar to like uh what we were looking at in in the previous video. It just basically has all of the stuff but it's in a different format. Um, I'm not going to look look at this too much. But this actually like converts the data frame into like just a flat string. So if we look inside of this records thing, it's just like a huge Oh, it's going to be hard to see. See if I can. Yeah, if you hover your mouse over it, you can see it's just like a huge like thing of all the records um that got returned by the query. that is it's basically just this this stuff that got returned but it's just in a huge string format. Then it's going to print to the screen like so be hard to read. Maybe I can do this all the records and then the code is going to exit.
So, um, basically this [clears throat] just did the same thing as the previous like the code in the previous lesson except for it was more structured. We we actually used like a function and passed stuff into it. So, I'm going to actually make this a bit more easy to read. So, uh, instead of let me see here, we can make this more easy. So I'm going to say like for example I'm going to erase this uh after I make it easier to read. So I'm just going to make a new one. Results equals query log analytics. This is the name of the function. And then the first argument is a client. So I'm going to do this client equals log analytics client. And then the next thing is the workspace ID. Workspace ID. Log analytics workspace ID. It's a bit it tends to be more easy to read if you put things in line like this and then you like when you're passing the thing in. If you like assign it to the actual name of the variable that's inside of the function. I don't know if I said that the correct way. it be it's just like a bit more easy to read and understand because this is the function definition. It takes it's going to use like client workspace ID, table, fields, time span, and it just makes more sense and it's easier to read if you write it like this. Table, all this table, then table name, which is here, table name, table name, and then uh fields. And then to make more sense of this to help uh I guess to help it make more sense I'll put another variable up here called like um fields and columns is like the same thing columns. So I can I'll I'll just call it like okay I'll call it call call it fields fields we want to include and then remember we're getting these by like using the fields dictionary. So for example like fields and then you know if we if we pass like for example device lo on events like so if we pass this fields device lo on events it's going to return like this stuff right um but in order for us to like like I guess one way to do it that's like a bit more clean just for our intents and purposes if we set the table name so for example if the table name we want to query is is device lo on events. We can just simply like use this and then we can just instead of putting like hard- coding a string in here, we can just do this cuz this is device login events. And then if we pass the table name, it's going to pull out the fields that we want specific to the table name. When we run it, perhaps it'll make more sense, but I just want to show you like a different way to do things. So fields equals this and then the last thing was uh time span hours ago equal to hours ago. So and this this tends to be like a bit easier to read than this. So I'm just going to delete this.
So this time we're actually going to query um instead of device login events um I'll I'll query the Azure network analytics CL. This is like the firewall essentially. So I'll just put this in here and then I will debug this. And by the way this is like quite hard like function is like a bit difficult for people to understand and wrap their head around. So, I just recommend like using GPT to like help you understand what's going on. And then absolutely don't be like afraid to post in the forum and ask questions if you need help understanding something cuz it's worth it's worth learning to understand and it's worth like making sense of this and being able to like augment it and change it to do stuff uh the way you want to do it. So, it is worth understanding and don't get distur don't get discouraged if you feel it's like too difficult. So we'll step over this. Going to assign the log analytics table name, get the fields. These are just the variables being built and hours ago. Then get the the uh client function definition. And then now this is where we define like which fields we want to include in our query. And if you'll remember, this is a dictionary. And then we're going to pull out the Azure Network Analytics CL value from the key. So this key, we're going to pull these out. That's what this does. We'll step over it and we see fields we want to query here on the left. It's all the fields for the Azure network analytics table, aka the network security group table, aka the firewall. And then now I'm going to step into this function. KQL query is being built going to be printed which is here. This is the thing we're querying. So if we if we copy this we can copy it again just like trying to connect what's going on for you and we paste in here. This is like this is what's going to come out like the flow type the public IP destination port etc. This is like basically firewall traffic. So step over this and then let the query execute. It's going to pull the tables out and then return the result. And then the result is going to get returned to here. This variable results over this. Pull the columns out. Pull the rows out. Build the data frame. Create a giant string of records which is here. We're going to use this to threat hunt uh at some point going to print those and then it's going to finish. And that's pretty much all that's pretty much all there is to it. And I I just want to say like um the whole point of this lesson is to just show that you can have a create a function and you can like manually like kind of create a structured KQL query inside of it based on the table and the fields that you want that you want to like uh look up. Of course you can do like more complicated stuff. Um we can say like for instance um blow type we can say for instance where flow type equals malicious malicious flow. So if we only want to return like malicious like traffic. So we could we could take this right and then copy it and then go to the code and then like right after the table name we can do like something like this like this. And then this this would work too. Uh I'm going to like run this right. I'll just uh yeah, I'll just start debugging it, but I'll just break it maybe at the very end. Me get rid of these break points. I'll just continue this. You can see the query here and you see um all the stuff that got printed. That's records a lot of and you notice it only has malicious flow as a flow type now and that's very cool and dandy. So we'll finish this but like what happens for example you know if we don't want to instead of querying the firewall maybe we want to query like the sign-in logs table for instance and we paste this here. So if you run this um see I will I'm going to break it here right before the query happens. So we see that our query got printed here. So I'm going to take this copy it and I will paste this here. This is our new query. And you see you might notice there's like already a problem with it. Oh So if we run this it's like where operator failed failed to resolve column or scalar expression name will like flow type s. This just means like this the signin logs table actually doesn't have a flow type column in it. So it won't work right. Um yeah that's pretty much all. And to like I guess prove this to you, you can say sign and logs get schema. Sorry, my nose is like stuffed or something. I don't know what's going on. Then can you just like speed this up layer? Like cut this out or Miho whoever happens to be editing this. And then you if you look through this is the whole schema for signin logs. You'll notice there's like no uh there's no malicious flow alphabetical order, right? No malicious flow. So if we go back to the code, this thing is about to execute this like invalid query. So we we'll just like see what happens, you know. It says a an error occurred and same thing failed to respond failed to resolve the column flow type s. So that's just like something you have to think about this this it's I don't want to say it's easy but it's it's possible to like uh formulate the function in such a way that it prevents stuff like this from happening. Um, but I just wanted to like I guess show it to you. And we're going to like deal with this in the future like when we build our agent because we're going to have a function that actually builds the KQL query for us. But we need to like uh account for different columns in different tables if that makes sense. So I'll just delete this for now.
And what I recommend for you is to, you know, take note that we only used like, you know, four tables here. There's like ton of other tables. So I might recommend maybe just so you can like build an understanding like choose like another table like outside of these. So for example if you go to log analytics go to tables you can go to like sentinel and then maybe you can go to like device file events for example. This is a table right device file events. So you might you might go to like you know um you might add that in here like device file events and then you might uh device file events and then you might want to like look to see what the schema is. So for example device file events and just take 10 for instance and just see what there is and see which um columns or fields are useful to you like look useful. You can say like time generated maybe is that's pretty useful because you you want to know the time that something happened. What the heck? Project time generated. Action type is probably useful. Uh additional fields maybe. I don't know. Device name is useful. Maybe file name is useful because it's a file events table. Uh maybe folder path. You might care about that. By the way, this is like cyber bunny. This is just like literal uh cyber range member uh virtual machines like files that we're looking at here. It's funny. Anyway, maybe like initiating process command line is useful for example command line for instance. So I would just like take these for instance, copy it and then I would create another comma enter and then another dictionary enter another key value pair. So device file events and then the keys or the rather the columns I cared about like so. And then now when we when we run this uh code, it's going to query this table and then it's going to look up the fields we want to return for this table and it's going to project them and it's going to like uh show them to us down here. So if I just run this again instance It built the query already. It printed it. This is the query that's going to happen. So if we copy this for instance and actually the query returns for the last hour and it's going to show like something like this probably going to show these. So if we go back and we just like let this run and you can see um it probably printed the same thing or something like really really similar. Um, but I didn't take 10. It just like I think it printed like a whole bunch of them. But hopefully uh hopefully that makes sense and you kind of get the idea. There's like a ton of tables. I just want to like drill that into your head. And I just so happened to like um only, you know, pick these four plus the fifth one that I added at the end. But yeah, let me know if you have questions about this. Um, I know it's like getting a bit difficult, but it's I again I think it's really important to learn like what's going on and just learn it in general. It's just really useful if you're able to understand this type of thing. But yeah, we'll see you in the next lesson, I believe, where we start talking about tokens and optimization. So we will see you there.
Welcome back. In this lesson, I'm going to talk about tokens and cost and then we're going to do a a demo to show the different costs of different models in terms of tokens. But hopefully uh we can get a sense for it. Uh it's really really important because when you're making an agent or dealing with AI in general or large language models, it's good to understand that um you know you should you should optimize your prompt like especially if you're using them a lot, it's good to optimize your prompts as much as you can and like optimize the model because it can it can make a huge difference in terms of cost. So basically um don't think I'm cheap for doing this. It's just it was just convenient. Um, basically like tokens. Um, I just use like GPT to like make a quick lesson, but what are tokens? Like when you use chat GPT, all of your text, like the inputs in the model's responses, like when you say hello and it says like hello back to you, um, it's broken down into tokens rather than characters. And a token, like a single token is roughly around four characters in the English language. Um, I don't know like the technical details of how tokens are calculated. Um I'm not I'm sure some people do obviously, but um we have like libraries and stuff to help calculate like how many tokens something is, which you'll see you'll see in the demo coming up. But every time you send like something to GPT, like the prompt, like you type something and send it. And then every time you receive a response back, that counts. Um those are all tokens, right? There's like prompt tokens and then response tokens. And then that whole thing I believe like when you send something and it sends something back I believe that whole thing is called like the window right so for example if you say like hello that's like about six tokens and then the response this is roughly seven tokens and then you can say that conversation used 13 tokens. And then why it matters is like kind of like we just talked about the longer the prompt is the more the tokens are consumed and then like the more tokens get consumed the like more the conversation costs essentially.
So we're going to be using uh these four particular models in the upcoming demo like really quick and you can kind of see like the difference between them. I I put a link for this in the actual source code um for this lesson so you can just like get it there or you can just type it. But basically, Chad GBT or OpenAI specifically has like a ton of different models. There's just like a lot of different ones and the cost for them are different and they're like just better at different things. So, for example, you can see like um Oh, that's interesting. They have intelligence instead of reasoning for this one. That's interesting. But um you can see like GPT 4.1 is like quite intelligent compared to GPT 4.1 Nano. And then G G G G G G G G G G G G G G G G G G G GPT5 is like slower but has like better reasoning than GPT5 mini. But if you look down here you can see like um how much it costs per like million tokens. So for example um per million tokens that's about what is like a token what what did it say like a token is like um four characters as a token so you can kind of get a sense right so for GBT 4.1 it's it's quite cheap although I won't say cheap but it's like cheaper than the other ones like 1 million tokens um 1 million input tokens is 10 cents or yeah 10 cents and then GBD5 mini is like 25 cents and then GBD 4.1 is like $2 per million tokens. So it it makes you know it makes like a significant difference right and it looks like for example with like GPT 4.1 and 4.1 nano you can see like the the window um context means like the prompt essentially and the window means like I believe it means like the total space for like a single conversation to take place. So, uh, the GPT5 Mini has like a total window of 400,000 tokens, um with a maximum like output tokens. I believe it's like the response from the model. It's like a maximum of 128k tokens. And you can like limit you can like uh, manually limit the output that GPT responds to you with. So, I believe that means that you can like put more into the input, I guess. But anyway, like the point I'm trying to make is like these cost like different amounts of money and they're better at doing different things and then like the window is like larger on some models and then some models um the output is the output max is different and there's just like a lot of variation. So it's generally like pretty like good idea to you know use a cheaper model. Um unless there's like something you really really need to be like you know really accurate or something. And by the way, I believe this is just a theory and like this is probably going to get aged out, but um when you use like GPT in the browser, you you sometimes kind of have control over the model you're using, but like sometimes you don't. And like I I have a theory that like when you're using GPD5, I think it like will randomly use like a different model on the back end depending on like what you're asking it. So, if you're using like the API with like your code, um it's I believe well I'm I'm relatively certain that it's going to use the model that you specify in the code, but if you're using in the browser, like I feel like it's kind of like it's manipulated by OpenAI on the back end, but who knows? But hopefully this makes sense. Um, I might split this video up into like two separate videos, but um who knows? But anyway, uh we're going to go on and like uh start doing the coding part now. So either we'll see you in the next video or we'll just like continue with this one I suppose.
So for this um this demonstration you need to download this I guess two files you need or potentially three I'll put three. You need this like tokens lessons. py you need logs short. py and then logs long. py and then we also need to um install uh tick token and then colorama as well. So to do those um go ahead and like download this code and put it in your folder and open it or however you want to do it. And then you'll say like pip install tick token like this. Um, I already installed it so it should be okay. Tick token is used to like um calculate tokens. And then we'll do pip install colama as well. This is going to be used to like color some of our output so we can see like if something is well you'll see um if it's under budget or over budget. And then we have these. I'll I'll kind of explain all of this here. What I'm doing right now is not necessary. I'm just like lining these up. Um, this you can do this. I'm like OCD sometimes. And then see how much better this looks. But anyway, we're going to do like a few exercises um where we I'll kind of explain what this is. So this logs short and logs long. If you open this um it's just like a multi-line variable, but you might recognize like what this is. This is like a random output from a device processes events table in log analytics. So if you go to log analytics and type you know uh device processes events I'll just like take 10 for example just so you get like a sense of what we're what we're working with and there's a bunch of logs in here right that's that's pretty much all this is it's just some logs and we're just using it as like a sample input um for our exercise that we're going to do. So that's what this is. Uh import log short from logs. It just it literally just uh imports this thing as a single variable with like a bunch of stuff in it. That's that's pretty much like all this is. And then take token uh it's used for calculating tokens. And then colorama is used for coloring stuff on the out on the the screen, I guess. And then I'll kind of explain like what all of this stuff is. Um, who whoever is editing this, you can just like cut this part out. I'm just going to make a copy of this. Okay.
So, before I like dive into this and explain everything, uh I'm just going to break this. Um yours will probably be line 65 like this like if choice like exclamation if choice does not equal Y just break this and then I'll just like run this once and then you'll get like a sense or rather Okay. Sorry. I'm going to need to like cut a lot of this out. Okay. So, I'm actually going to break the code like um right here where it's setting default and current model. I'll just break it here and I'll just kind of explain things as it runs. I'm not going to explain like every single thing in this lesson um because there's a lot of helper functions that do stuff and like the main point of this lesson is I just want to show like estimate. Well, you'll see what I want to show. So, I'll just start debugging this. I I want to get you to like have a good sense of like the different models and like token cost and that type of stuff. So, I'll break this. I'm going to manually set the model to GPT 4.1 Nano. So, we'll like step over this and we'll step over this. So, our current model is GPT 4.1 Nano. And then these are like all the different models. Well, not all of them, but the ones that we're going to like care about for this demo potentially. And you'll you might notice like these are from here. Um I just like manually you can like manually add different models here and like this like the cost and like maximum token window and like all that stuff. Um I just pulled them in from the website and put it here cuz we're going to use it in our code to like estimate some random stuff. Not random but some various different things. So we'll stop over this. And then by the way in Python when you see like an underscore here. This is basically just a comma and it helps you to like visualize the number better you know you can easily see this is a million whereas if there was like no underscore you might like you know think it's like a 100,000 on accident but hopefully that makes sense. So this is just stepping over the different functions another function then creating our open AI client which we use to interact with chat GPT. And then this is uh important um this is a prompt that we're going to send to the GPT API. And then we're doing a bit of prompt engineering here like you are a threat hunter. Are there any anomalies or potential breaches? And then we're passing in the security logs like this this big thing right the the log short thing. We're basically like making this big prompt. So if we look at this prompt it's like So if we if we look at this prompt, it says like you're a threat hunter, any anomalies, and then it just dumps the logs like straight away. It's a really really crude prompt, but it's just for the sake of like practicing dealing with tokens. And then the the message is created. If you recall, this is like roll user and then the content. And then this is like our actual prompt cuz we need to like use this message like for two things. We have to send it to chat GBT in this format but we also use it to calculate the um estimated number of tokens. We have to send it a message in this format. If we step over this our message is created our prompt message. You can see it over here like so. And then it's going to estimate the number of tokens in that prompt. So, if we step over this, we see like estimated prompt token count estimated about 25,000 tokens in that big prompt. So, now we're going to calculate uh the max number of tokens in that's allowed in the response as well as the model costs per million tokens based on our current model. So, basically, it's going to like the code is going to use this models dictionary. if you remember this thing up here and it's going to look that we're using GPT 4.1 nano and it's going to check like okay like what's the max like window and output and then what's the cost per million that's basically all it's doing so it's going to get the max tokens used in response like the max possible and then the cost per million and then you see you can see this here this is like 32768 straight from GPT or straight from open AI's documentation And then this should be like 10 cents like 0.1. This means like um 10 cents per million tokens used. And then we're going to estimate the total token count based off of the max tokens used in response plus the estimated number of tokens that we're sending. So, so estimate of about 57,000 tokens in this conversation potentially. And then we're going to calculate um how much it's going to cost, not the actual cost. We're just like calculating it based on the estimated number of tokens. And by the way, just try to understand what I'm saying. Don't like think into it like too deeply. We're going to like run this a few times. So now we'll just step through this and it outputs the approximate cost. So this is this isn't 5 cents. This is approximately a half a cent for this uh conversation. So we can say Y for yes to proceed breaks. If choice equals does not equal yes, exit yes. And then uh now we're going to send the actual thing to chat GBT, the actual conversation. I'm going to like bring this out a bit. actual prompt tokens. Okay, so now we can see like how much like the actual prompt cost in terms of tokens. So this is the response we got back from GPT. This response I'm going to try to try to zoom in a bit here. This is the response variable we got back from GPT. So if we look in our debug over here and we look at response, we can look in response usage prompt tokens. So underneath response is usage and then prompt tokens. So this is the the actual number of tokens that are prompt contained. That was like the you're a threat hunter. These are the logs. This is the actual number of tokens. And then this uh response usage completion tokens. This is like how much how many tokens were sent in the response back from GPT. So this completion tokens is only 602 tokens got sent back in the response and then total tokens is just a combination between the two. So there's usage. This should be like total tokens. This is like this plus this and this. This is like the total token count used for the interaction. So if we step over this and then we can calculate the actual cost um based on the actual number of tokens used, actual response and then the the cost. So this function is going to do that. I'm not going to go into it. I'm just gonna like let it run. And then the actual cost, if we hover over the top of it, actual cost was actually um it was like 1/4 of a cent, like 0.25 cents. So, I'll bring this back down a bit. And then it's just going to output everything like so. And then we can look at this. The estimated cost was half a cent. The actual cost with a was a quarter of a cent. The estimated tokens was 57,000. The actual tokens was 25,000. And you might be wondering like this this program's going to end. And by the way, inside of this answer, um, this is the actual like threat hunt analysis. Um, I'm not going to like go over this. If you want to, you can like you can print it out like so. Um, and then it will like show it, but that's like not the point of this video. So, I'm like not going to do it. But, oh, it's already going to print. So, I'm actually going to like comment this print thing out because um it's not the point of the video and I I don't want to like get too hung up on the the the threat hunt that it performed. You can look at it if you want and you can leave it uncommented. But anyway, you'll you'll notice like um there's a bit of a discrepancy here. Like the actual cost was like twice as much as this and then the estimated tokens was like nearly twice as much as this. And that's because um we were estimating like the the number of tokens used based on this is going to be a bit complicated, but we were originally estimating the the total tokens used for the conversation based on the the max output tokens. So we're assuming that GPT is going to maxim like use all of the tokens possible for its response. And we don't necessarily need to do that every
time because we can manually limit, like how much GPT is allowed to respond with. So, for example, I made this variable here called `max_output_tokens`, and I just set it to 5,000. So, if I want to say, like, GPT, like, you, you can't respond with like over 5,000 tokens, we can do it.
So, to do this, um, I'm going to change this because here, here is where we like estimated, like, um, the max tokens used in the response, and we did it like based off of like the model we were using. So, like GPT4.1 nano, you know, has, uh, GPT4.1 nano has a max output response of like 32,000 tokens. But if we don't want to do that, for example, we can do, we can like actually like comment this out, like so. And then we can manually set the `max_output` to 5,000.
And then where this gets used, um, it gets used in, well, it gets used to calculate the chat cost here. So, instead of 32,000, this is now 5,000. And it also gets used, um, when we actually send the chat to GPT. So, this is the function that sends the chat to GPT. And there's actually like a parameter that we can put, `max_completion_tokens`, and we can set this to like a number of like 5,000, for example. So, if we don't want it to use more than 5,000 tokens in the completion, we can do that.
So, I'm going to run this code. It's just going to be the same thing, the same model, the same prompt, like the same logs we're going to analyze, but we're going to like limit the response that GPT can put out. And then, in turn, it's going to like change the estimate for how much it costs. So, it should be like closer to the actual. And I'm sorry if this is like confusing. I know it's like not easy, but just, you know, let's just do our best.
So, we set this. We picked our model, 4.1 nano. We're going to go over this: the functions, build the API client, build the prompt, build the user message, estimate the token count, set the max tokens used in the response to 5,000, get the cost per million, estimate the total token count. So, now this is going to be less because we're using 5,000. We're going to estimate the chat cost. And then now, you notice it says, like, the chat will cost approximately, uh, 0.3 cents. So, before, if you remember, it was almost double that, 0.58 cents. So, now it's estimating 0.3 cents because we limited the output tokens.
So, we'll just say yes, it breaks. And now we're going to actually ask the model. We're going to send our prompt. And then it's going to pull out the actual, like, uh, usage, like, from the response. It's going to go to the usage object and pull out the actual number of tokens that was used, um, and then, like, the, yeah, the total number of tokens, which is our prompt plus the completion tokens, which is the response. And then it's going to calculate the actual cost. So, and then it's going to print everything. And you'll notice this is much more close to, like, the reality. Um, the actual, the actual cost was the same. It should be the same, like, 25 cents, or not 25 cents, but like 0.25, 25 of a cent, like so. But the estimated cost is more accurate, um, because we, we were, we were more, we were able to like more closely guess what the output cost is going to be, like, from chat GPT, cuz we limited it to 5,000 up from, like, a window of 32,000. Hopefully, this makes sense. We basically told chat GPT, you can't use more than 5,000 tokens in the response. Therefore, I'm going to, I'm just going to assume you're going to use a max of 5,000, and then our estimation should probably, like, always be slightly over. And that's what happened. So, you'll see how much this cost. We used, um, you know, GPT. I think 4.1 nano is what we used. So, we're going to use, like, a more expensive model. We're going to use, like, the most expensive one, which is, at least here, is GPT5. So, I'm going to switch this to GPT5. And then, again, it's going to be the exact same prompt, the exact same, like, the logs that we're sending to GPT. Everything's going to be exactly the same, except for the model is going to be different. And then we're going to be able to, like, compare the price between using GPT5 and using, like, 4.1 nano, for example. So, I'll just, like, rerun this code. And then I don't need to break this. I'm going to, like, remove the breakpoints. And I'm just going to let it go. And you'll notice, like, now, um, the estimated cost previously was, like, like 0.3 cents, but now it's almost 4 cents. It's like 10 times more expensive. And I, I guess that's obvious because you can, you can see that here. It's 10, it's more than 10 times more expensive. Um, so we're just going to say yes. Then we'll let it run. It's like 3 cents for that, um, the log analysis we're doing right now. Let it go. GPT5 takes longer. You know, it's, of course, it's the actual model itself is better. Uh, in my opinion, it's like more accurate and smarter than 4.1 nano, but you see it costs more money, and it likely, you know, it's going to take longer as well. I probably should have put some logic in here to measure the time that takes to complete, but that's okay. We'll just let it go. Cool. And it finished. And you'll notice that the estimated cost was, um, 3.7 cents. The actual cost was 3.4. Estimated tokens was this. And the actual tokens was this, which was slightly under. And then I'll run this one more time. I'm going to set the model to 5 mini. So, we can do this. And then you can get a sense. Remember, this is like exact same logs, exact same everything. So, I'll run this without debugging. You'll notice, like, how fast that was. And this is like what's, what is this? This is like 0.7 cents. It's quite, quite a bit cheaper. This is 3 cents. 0.7 cents. We'll say yes. And that it was like pretty fast, too. Oh, no, that was not the actual run. The actual, asking the model. This should be faster than GPT5, though. That was, that was pretty fast, actually. And you can see, um, instead of 0.7 cents, it ended up being like 0.6 cents, essentially. And then you can see, like, the actual token cost. Um, the token, the tokens going to be the same every, like, almost every single time. Uh, it should be the same every single time, almost, except for, like, the, the, the return tokens. Okay, I'm lying about this. So, we can control, like, the tokens we're sending to GPT is going to be the same every time, but the response from GPT is, like, always different because, you know, it's an LLM, and it, it just responds differently every time. But it's relatively, it's relatively close, like 26,000, um, almost 28,000, uh, 25,000. It, it's relatively, it's relatively close every, every time. 25,000. So, yeah, I might experiment with this a bit more. Um, just get a good sense for it. I just want to give a sense for, like, the model, like, I guess the speed and, like, the token window and, like, the cost and everything like this. Um, I'm going to experiment with this a bit more in the upcoming lesson. Um, we're going to actually, like, combine the log analytics queries with dealing with these models. And then we're going to experiment a bit more with token window and, like, when you send, like, too many, too many logs to GPT, like, what will happen, um, just to get kind of a better sense for that, and then also get a better sense for why it makes, like, how to, like, optimize the, the prompt we send to them when, when threat hunting, and like why that all that is important. So, hopefully this makes sense. Um, is always, like, I, I know this is like getting a bit difficult, but the more you deal with it, and, like, the more you can, like, leverage GPT, um, and you just play with it, hopefully you kind of develop an intuition over time. But if you have questions, uh, as always, go to the community, make a post, tag me. Don't be like nervous or shy to do that, cuz what we're doing is hard, and I want people to like collaborate on it and help each other out. But hopefully this makes enough sense. If it doesn't, let me know if you need any help, and we will see you in the next video.
And one thing I do want to bring attention to really quick is the input and output cost for the different models. It's different for the tokens. So, for example, like input, um, that's basically when you say, like, uh, "Make me a cake recipe," and then the output is the thing that GPT responds with. And the thing with threat hunting is, like, in security operations, usually the input is like massively bigger than the output is. Uh, so that's good. And then we can also control how much GPT is allowed to respond with in the output. So, I just, I just wanted to like talk about that fact that there's like not all tokens cost the same. Like, what you put into chat GPT is cheaper, and what it outputs is more expensive, and you can control the output. So, we'll be able to see that, um, you know, in the code. And let me see really quick, and how you might do that with, you know, the, the chatbot, like, if you're using the web, I might say, like, um, you know, "Give me a cake recipe." And a way to control the output, you can say, like, "Respond, you know, respond with five words or less." This is like a really crude way to control it, like, in the web browser, like, if you're just using it as a normal person. That's funny. Um, but with chat GPT, um, or with the API, you can like really, like, precisely control it. So, for example, just, I'm just going to try one more of these. "Give me a nachos recipe. Limit your response." I'll, I'll speak about it in terms of tokens, to 10 tokens or less, just, just for example, and then I don't know if this is 10 tokens, you know, but just for example.
So, getting into the code, um, you're going to need two files. Uh, I'll put them in the description, or however you want to call that. One of them is `tokens_lesson`, which is like the main code we're going to use, and then the other file is `logs_short.py`. It's literally just a variable, um, with a multi-line string variable with a bunch of logs from the cyber range in it. These are like the device process event logs. And we're just going to use this, um, to build a prompt and do some, like, really basic threat hunting with. But the threat hunting is, like, not the point of this lab. The point is to like explore, um, the different models and, like, different token costs and just build an awareness that different models cost different things, if this makes sense.
So, basically, in plain English, what this code does, um, there's like a bunch of models to select from, and if you notice, like, these are synonymous, not synonymous, but they map to this. So, like, GPT5, you know, the input costs this much, output costs this much, and then the max window, etc., and then GPT5 max window, and then input cost, and then output cost. And then these are like all the same. They should be accurate. So, like, GPT 4.1 nano, the input cost is, uh, 10 cents per million tokens. Output is 40 cents per million tokens. GPT 4.1 nano input cost is 10 cents per mill, per million tokens, 40 cents per million tokens, etc. So, and we're going to use this data to calculate the cost of our, um, prompts and, like, our messages to GPT, just so we can get a sense for, you know, how it works and, like, why it's important and stuff, and it's going to be really important for the next lesson. So, I'll just, like, break this, and then I'll, I'll walk through it, and then try to explain it along the way. This. I realize it's probably kind of small. Okay.
So, I'll just, uh, start debugging, and I'll break it here. Oh, I'm going to fix this by the time you get it. I don't know why that is, but I'll start debugging this again. Okay. And then, um, let me zoom out a bit. Yeah, it's kind of hard. I wanted to like show all the stuff on the screen, but `max_output_tokens`. Um, we, we can use this variable to control how many output tokens GPT is allowed to use. Um, so I'm just, like, setting it here. And then this is the default model. So, I just decided to use 4.1 nano first, cuz it's the cheapest. Step over it. So, we have our current model. That's a GPT 4.1 nano. I'll zoom in a bit. I know it's like a bit hard to read, but we'll step over this. Our models dictionary getting created. And then this is just a function. Um, it just calculates how much a chat is going to cost. We'll basically, when we use this, we're going to, we're going to pass in the number of tokens we're sending, as well as the cost of those tokens. So, it'll be different for, like, when we're estimating the input and output of, um, a chat. And then this function is used to count the number of tokens in a message. Um, it uses, like, some special library and some GPT logic, basically, to do that. So, it will take in, like, a message, and then it will just output the number of tokens that message has. In our API client, so we can communicate with GPT. And then this is really important. This is the prompt that's going to get built. And basically, um, it takes it, it says, "You are a threat hunter. Any, are there any anomalies or potential breaches?" And then it passes, like, the all these logs to it. This is, like, a really crude threat hunting prompt. And when we actually make the the agent, it's going to be, you know, way better than this. But I just wanted to like [snorts] make a prompt with like a substantial amount of stuff in it, um, so we can like observe the cost variation, if this makes sense. So, step over this, and then this constructs the message to send to GPT. So, if you remember, when you're sending, like, a chat to GPT or a prompt, it has to be in this format, like the role, and then, like, the content with the prompt, and, um, it's like a list of these dictionary objects. So, we're just sending a single one with our prompt in here, like our threat hunting prompt. So, this is the message being created, like so, and you can see it over here, prompt message, and you can see it, list of zero or list of one object, role, and then content. And then we can either, oh, so I'm going to step over this, and the estimated, okay, this estimated the number of tokens in our input message. So, it used this function, as well as, uh, the messages to calculate the number of tokens, and it calculated there, it's about 25,000 tokens. And then here, um, we can determine, like, the maximum number or the maximum tokens used in GPT's response. So, we can either do it by, like, hard-coding it here with this variable, which we did. It's like 5,000, or, um, we can just assume that GPT is going to use the, the max number of allowed output tokens. And if you remember, that's just like what this is. So, we're using GPT 4.1 nano. And for this particular model, um, the maximum number of tokens it can output is 32,768. So, we can either, like, just assume it's going to output this many, or we can hard limit it to whatever this is, which we did, which is 5,000.
So, I'll probably actually, I'll run this first. Um, go ahead and comment this out. I'm going to run it first and and calculate the, um, estimate the number of tokens with, like, the theoretical max that it's allowed to do. So, I'll just, like, rerun this. I'll just, uh, break it here. So, I'll just, uh, forward this. [snorts] Okay, so we're back here. So, I'll do this next time. So, we'll step over this, and then we're going to get, um, how much it costs for the model, like, per, this model, um, per million tokens input, and then per million tokens output. So, this just uses the models dictionary with our current model, and then it pulls out the cost per million input and the cost per million output value. So, if we step over this, because we used, um, the model we used was GPT 4.1 nano, the cost per million tokens input is 10 cents, and the cost per million tokens output is, uh, 40 cents. So, that's just from here, GPT4 nano input 10 cents, output 40 cents. So, and then now we're going to estimate, uh, the cost of the input with this function. We're going to pass into it the number of tokens and then the cost per, uh, million tokens. And then it's going to output the estimated input cost. So, it's estimating that we're going to pay, like, 0.22 cents for this input. And then it's going to estimate the output cost. So, again, we're going to pass in `max_tokens_used`, theoretical max by the model, and then how much it costs, like so. So, it's estimating if we indeed use 32,000, um, tokens for the output. This is not likely, but if we do, the estimated output cost is going to be 1.3. And then it's going to estimate the total chat cost by estimating the input cost plus the estimated output cost. So, it's estimating the total chat cost, uh, 1.56 cents, or like, you know, 1.6. And then it's going to notify the user and then ask if we want to proceed. It does. So, we, it's estimating it's going to cost this much. Do you want to proceed? We can say yes. So, if the choice does not equal yes, abort. Choice was yes. So, now it's going to actually, uh, send the message to chat GPT, and, uh, we're going to get a response. So, this is the threat hunt message, like, "You're a threat hunter. Please look at these logs. Is there any problems?" So, that's what's happening right now. I'm going to bring this out a bit, cuz we're going to inspect some stuff over here. So, we got our response, uh, from chat GPT, which is here. It's stored it in this variable, and then there's some special, uh, properties inside of the response that actually show, like, how much everything cost in terms of tokens, or how much, yeah, how many tokens it cost. So, if we expand response and we can go to, like, the `usage` property, we can see, uh, `prompt_tokens`, which is, like, the number of tokens we sent. We actually sent, it was 24,584, and then `completion_tokens` is the total number of tokens that actually chat GPT responded with was only 673. And you'll remember, we kind of, we estimated, um, that it was going to be, you know, the theoretical max, which is 32,000, but it ended up only using 673, for example. So, uh, if we step over this, it's going to pull out the prompt tokens and and store it in here. So, we can see, like, the actual number of tokens that was used in the prompt, and then the actual number of output tokens, or aka completion tokens, and then actual total tokens. I don't think we're going to use this for anything, but anyway, we stored it anyways.
So, now we're going to calculate the actual cost of the input. So, we're going to take, like, how many tokens actually got inputed, and then we're going to, um, input as well, like, how much those cost, and then it's going to calculate the actual cost that it, it's going to cost to do that. So, the actual input cost was, like, 0.2, like, what is this, like, 0.24 cents. It's like not even a quarter of a cent. It's going to do the same thing with output. Output, uh, this is quite cheap as well, like 26 cents, or like, you know, 0.27 cents, essentially. And then it's going to calculate the actual cost. It's just simply adding up the cost of the input plus the cost of the output. The actual [snorts] cost of that message was only, like, 27. And then, um, it's going to do some calculations for us. So, we can actually, like, it's going to calculate and then color them. So, if it's, like, over the estimate, it's going to be red. If it's under the estimate, it's going to be green. So, basically, this is, this is just outputting everything for us. We can see the estimated token count, estimated cost. Then we can see the estim, the actual token count, the actual cost, and then the answer are stored in here. This is, like, the actual, like, threat hunt response that it gave. Uh, I'm not really interested in seeing this for this lesson. If you want to see it, you can, like, remove this thing from here and then run it again. Um, but, you know, if you want to see the threat hunt results, but that's not the point of this lesson, so I'm not going to go over it, but you can see it if you want. But as you can see, um, these are estimates. Our estimated token input, estimated token output, and then the estimated cost was, the estimated cost was, like, actually 1.5, but the reality is that it, it came in, like, way under that. So, the token, estimated token count was, like, pretty close. The input tokens, the output tokens was, like, way the heck off, right? Because we estimated, like, the, it's going to use the total window, the total possible window, but it only needed 600 tokens. And then, as such, the actual chat cost was, like, way, way cheaper. This is, like, significantly cheaper. This is, like, not even 1 cent, where, where this is, like, 1.5 cents. So, you can kind of see an error here. Um, it's not really an error, but it's, we, we didn't limit, um, how can I say, in our estimate, we, we estimated that it was going to use, like, the whole window, like, the whole output window, but it's, that's not really necessary. There's a lot of ways to, like, estimate, like, how much this is going to cost, but one way is that you can just, like, hard limit the output to something, um, so you can get it, like, a closer estimate. So, you see, like, for our intents and purposes, like, the output, it, it didn't even exceed 700. So, um, we can just, like, let this finish, and then when we're going to, like, estimate the output, um, we can, like, hardcode it at, say, like, a thousand, for instance. So, I'll, I'll put the `max_output_tokens` constant variable to a thousand, and then we'll go to the spot in the code where we're actually, like, estimating that. So, which is here. So, instead of, like, `max_tokens_used_in_response`, instead of, like, using the theoretical max from the model, we can use, like, the hardcoded number of, like, a thousand, for example. So, I'll comment this, and then I'll let the program use this. And you have to be careful, cuz sometimes you might need more than a thousand tokens for the output. But for our intents and purposes, we're just going to, like, limit it to a thousand in this case. And then we're going to run the, the same code again with the same model, the same prompt, same everything. And then we're just going to, like, observe that the estimate is more accurate. So, we'll run this again. I'm just going to, I'll just run it without debugging. Um, you can debug your code, by the way. I highly recommend it. And then you can, like, step through it and observe everything. Oh, apparently I debugged it. Okay, so I'm, I'm just going to let it run. And it's the cost is this much. Yes or no? So, I'll say yes. We'll just let it go. And then I'll run this a couple more times with different models. And then we're going to see, like, the cost increase as we use, like, progressively, like, more expensive models. So, now we can see estimated token inputs was 25,485. And this, this is like really, really close, actually, as you can see. And then estimated output token is a thousand, because we hard limited it. And the actual output ended up being 698. It's slightly higher than this one. Like, the, the beautiful thing with LLM is the output is, like, always going to be, you know, slightly different. And then the estimated chat cost was 0.29 cents. It ended up being 0.27 cents. And this is, like, a way more closer estimate because we're able to, like, estimate the output tokens because we, like, we can hard limit them, if that makes sense. Um, so, um, actually, let me just, like, run this one more time. I'm going to limit the output to, like, 100, and see, like, what the model does. So, I'll just, like, this time I'll actually run without debugging. I'll put this back to a thousand later, but I just want to, like, see what it does. We'll say, I'll say yes here. That's so funny. It, it literally gave us, like, exactly a thousand or 100 tokens in the output. So, actually, I'm sorry. I'm just, like, curious of, like, what the output looks like. So, I'm going to, like, um, I'm going to remove this comment, and I'll run this again without debugging. And then we'll be able to actually see the threat hunt results in under a thousand or under 100 tokens. So, I'm just going to, like, say yes. And then it came out again. It, it's almost exactly on on budget. And then this is, like, 100 tokens. And you can see it just, like, truncated the, um, it wanted to say more, but it just truncated the output at exactly 100 tokens. And it, it don't actually tell us, you know, it, the output is, like, too limited, if is what I'm trying to say.
Okay. So, I'm going to, like, I'm going to hide this again. Um, I don't need to see the output every time. And I'm going to reimmit this to,000. So, and then I'm going to use the next model. I'm going to use GPT5 mini. Actually, let me, let me run this, like, one more time. I just want to, like, have all of them on the screen, like, the different models, so we can compare them easily in the end. Also, yes. Okay. And again, this cost with a 4.1 nano, this cost 28 cents. Remarkably cheap. So, I'll take this model, I'll dump it in here. And then we changed our model to GPT5 mini. You remember, um, you can, like, see the cost and everything here. So, and then again, all of that stuff is, like, just in here, you know, if you want to keep going back and looking at that. So, um, I'll just run this. Uh, I won't debug it. You can debug yours. I recommend it. You know, look through and observe what the code is doing to get a good intuition for it. Well, this time it estimated 81 cents. So, we'll run this. And we got an error. Okay. Use `max_completion_tokens` instead. Okay. That's funny. Um, so this is, like, a a good lesson. I, I suppose I'll, like, um, explain what happened. So, this is the, this is the function that we're using to, um, ask chat GPT, like, send our, our prompt to chat GPT. But apparently, like, this model that we used, like, what are we using, like, 5.1 mini, it needs to use, like, `max_completion_tokens` instead of `max_tokens`. `completion_tokens`. `max_tokens` is not supported with this model. Use `max_completion_tokens` instead. So, uh, I'm just going to, like, set that. So, it's just something to keep in mind, like, different models will have, like, different behaviors when it comes to, like, the API and stuff on the back end. So, I'm just going to, like, run this again, I guess. `max_completion_tokens`. Um, yeah, I, I don't want to, like, get too complicated. There's, like, a lot of different ways to handle that. Like, you know, if model is GPT 5.1 mini, then this is the parameter for it, you know, but I won't get into all of that yet. I'm just going to run this. And if you run into some kind of, like, error that's unexpected or, like, different, um, absolutely go to the forum in the community and make a post and tag me. Um, but, okay, this is GPT. Um, was it GPT 5.1 mini? If we remember, uh, GPT was a 4.1 nano, came in at 28 cents, and then GPT 5.1 mini, is that what we're using? Oh, sorry. GPT 5 mini, what am I saying? Came in at 81 cents. So, how much is this more? It's about, like, three times, three times as expensive. 81 cents. And if we look at the cost here, it's a, it's about three times more, you know, in terms of input and output, maybe, like, you know, 2.5 times more, something like this. Um, so that's interesting. So, we'll, we'll do the next model, the next most expensive one, uh, GPT 4.1. We'll set that to this. We'll observe the cost and everything. So, we'll just, like, run this without debugging. What's the? Yes. And feel free to make a guess based on this GPT4.1. I, I'll just, like, make a guess now. Um, so it looks, it should be, like, let's see, input. This is, like, this is, like, eight times more expensive than this. It's exactly, input is eight times more expensive, output is four times more expensive than GPT5. So, I will, I will say, like, uh, what was it, 81 before? So, it should be, like, maybe, like, uh, 6 cents or something like this. I'm going to guess, oh, it's 3 cents. Okay. Uh, so, estimated is pretty close. Oh, it, it used all of the tokens, actually. It used all of the output tokens. That's interesting. And this one ended up costing 3.25 cents, or like, yeah, 3.25 cents. And then last, last one, we're going to use GPT5. This is, I believe, the most expensive one. So, we're going to, going to take a look. Oh, no, it's not actually, it's cheaper. It's cheaper. The input is cheaper than 4.1. So, let's see, see what's going to happen here. Oh my god. I didn't mean to do that. Okay. So, we're going to run this. We'll run without debugging, and we will say, okay, we'll see what, what happened here. Could not automatically map G. Okay. I, I'm certain I know what happened. This is because, um, tick token, like, the thing that counts the tokens, uh, it doesn't know how to, like, do that with GPT5 yet. But we can, there's like a way, I, I know, I know how to fix this because I, I ran into this, like, a different day. Um, you can, like, force it to use, like, a certain, uh, like, a different model. Oh my god, how can I say this? Anyway, there's, there's a way to, like, force it to be able to work. So, let me, like, just do that live. And you can probably copy me, or I'll, I'll maybe I'll fix the code or something so it works when you get to it. But, uh, where is that calculate token? Oh, `count_token_messages`. Okay. So, do this. I'm going to take this. And then I'll go to GPT. And then, by the way, I'll, I'll fix this code probably so, like, this it doesn't break, like, this when you get it. But, uh, just for the lesson, I'm going to say, like, um, "Please fix this code." So, when you pass GPT5 into it, it will hardcode the appropriate thing. Uh, since tick token doesn't recognize the GPT5 model yet, do this so it knows. Probably fix it. Oh, this is what I wanted to say to, uh, hardcode it to use this. I think I believe this is correct. Okay. So, we'll just take this function. I'm, I'm pretty certain this is going to work. And then I'll replace, I'll just replace this. So, I don't, I don't know exactly how this works, to be honest, but let me explain it. This, this function that calculates how many tokens a message uses, um, uses this thing. Um, I guess the different models use, like, a different encoding type, but it's, I don't know. This library didn't get updated to recognize GPT GPT5 yet. So, like, it, it doesn't work. So, you, I just told it to, like, if model is GPT5, just, like, hardcode the encoding to this, otherwise, uh, get the specific encoding for the model. So, this will, this will probably work. So, we'll just, like, run this. I just vibe, vibe coded that on the fly. Oh my god. But it's kind of good for our, our lesson here. So, I'll just say, like, yes. Hopefully, it just, like, works and we don't spend a bunch of time. I think it will work, though. DPT5, I noticed it does, like, take time. Um, I don't know exactly what it's doing, but I, I noticed it produces, like, new results in threat hunting, like, better than 4.1, or it notices more stuff. So, I'm assuming it's, like, using its big brain to do something. Um, but it does tend to take more time. You remember, uh, GPT4, what was the last one we did? 4.1 cost 3.25. And then this one, it came in at, looks like, oh, slightly, slightly more expensive, which was surprising. So, four, that, that query cost 4 cents, and it, it used up all of the tokens, it looks like. Yeah. Hopefully, this makes sense. Um, feel free to, like, adjust the logs if you want, or if you're in the cyber range, right? You can go to log analytics and you can get different logs, right? And you can experiment with this a bit. But for this lesson, I, I just wanted to show, you know, not all tokens are created equally. Like, the input tokens are usually cheaper, output is more expensive. You can limit the number of tokens that get outputed, that get output. Um, this is just our variable, but you can, like, where's the function? You can, you can limit the tokens, like, this, like, how many gets outputed, and then different models cost different amounts of money. So, you might want to consider, like, you know, if I were to just, if someone were holding, like, holding me a weapon to my head and being like, "Just pick a model, pick one, or I'm going to, like, end you," I'll probably, I'll probably go with, like, GPT5 mini, um, because it's, like, you know, new, and it's pretty smart, and it's pretty fast, and it's, like, it's quite cheap, too, right? It's like pretty cheap compared to these ones. So, but you might have a scenario where you, like, really want to make sure something is, like, proper, right? And then you, you would use, like, GPT5, or maybe you have another scenario where you have to, like, feed, like, a huge window, like, a huge [snorts] prompt to GPT, uh, to GPT, and you want it to be, like, relatively accurate. So, in that case, you might want to use, like, GPT 4.1. Um, and there's, of course, there's other models as well. I just kind of picked these. So, hopefully that makes sense. I just wanted to, like, give you an intuition for these things, and then, um, just make you aware of, like, the different models and, like, the differences between them. But, yeah, uh, we'll see you in the next lesson.
Welcome back. In this lesson, we're going to cover, uh, API rate limiting, specific to the OpenAI, um, chat GPT API. So, basically, what this is, um, you're only allowed to send a certain amount of tokens, I guess, to the API endpoint in any given time period. And the higher your quote unquote tier is, the more you're, the more you're allowed to send. So, >> [snorts] >> um, basically, I'll kind of explain what that is, and then we'll look at it in code a bit, and then we'll move to the next lesson. This one should be, like, pretty quick. So, remember, there's like a lot of different models we can use, and these are the ones that we're, like, currently working with. So, if you scroll down a bit, you will see, Oh, did I pass it? No. Oh, there's like rate limits for each one of these. So, for example, um, GPT5 is on the far left. So, if we scroll down, we'll see rate limits, and we see, like, the free tier. Tier one, you can send 30,000 tokens per minute. Tier two, you can send, like, like 450,000 tokens per minute. And if you're wondering, like, how to get to, like, tier one and tier two, um, there's like this rate limits page. I'll put links to both of these, um, either in the lesson or in the actual code. But [snorts] for example, if you have an account and then you spend five bucks on it, um, then that puts you in tier one, uh, apparently. If you spend $50, and, um, there's been seven days since your last successful payment, that puts you into tier two, and then tier three, and then tier four, etc. So, our, our business account probably is, it's probably probably tier five by now, to, to be honest. Um, because $1,000, I don't know if we spent $1,000 yet. Maybe after, like, making all those, like, practice question decks. But, um, the practice account I created with this, I, I think it's like tier one because I only spent, you know, five bucks funding it. I think, I think, yeah, I have like a $4.20 left. So, [snorts] uh, basically, what this means is if we're using, like, um, GPT5, which is this left column, we can't send, like, over, in, like, a single request, we can't send over, uh, 30,000 [snorts] tokens, and in a whole, like, you know, a whole minute, we can't send 30, 30,000 tokens. So, basically, what this looks like, um, go ahead and, like, you can cut this out, Leia or Miho, or whoever is editing this. Okay, you can start, uh, from now. So, basically, I included some, uh, code for this lesson. We have this, like, `logs_long.py` and this `logs_short.py`, and these are just basically logs from the cyber range from the process events, was it device process events table? The, the `logs_short` is just like a short version of this, and the `logs_long` is like a absolutely, like, a humongous, like, thing of logs, basically, it's just a lot of logs. And this, this `logs_long` is over, it's going to be over 30,000 tokens for sure. So, I just want to, like, show a demo with this. Um, this code is, like, really similar to our previous lesson, but I, I changed a bit. So, you can, like, download this code. Download all three of these. This `rate_limit_test.py` and then these two things, like, so. And [snorts] then, um, just make sure your model is set to GPT5. And then we'll scroll down a bit, and then under this, like, `prompt_message`, this is the prompt we're going to send to, uh, GPT. We're going to, we're going to use, like, a, Oh, this should be system. Um, we're [snorts] going to use, like, one system prompt and one user prompt. The system prompt is just, like, giving the model context for what it wants. So, "You're a threat hunter. If you, um, if the user provides logs, analyze them for malicious activity." And then this is our user prompt. We're just going to say, like, "Here are some logs." And then we're going to import this, uh, big logs, `security_logs`. And `big_logs` is just, like, if we scroll up, um, I, I imported, uh, `logs_long`, which is this, as `big_logs`, and that's just, like, this all this, like, huge, like, logs, right? So, the, these are the messages we're going to send. Um, we're going to calculate the tokens and everything like this, and then before we actually, uh, do the API call, we're going to be able to see, like, how many tokens it is. And remember, this, like, account. This particular account is a brand new, basically, and I only spent five bucks on it. So, it should mean that we're, like, only in tier one. So, if we send over 30,000 tokens, um, in theory, it should, like, throw some kind of error, right? So, hopefully that makes sense. So, we'll just, like, run this and start debugging. And we see estimated input tokens is, like, 151,000. Is a lot, right? So, it says, "Press any key to proceed." And then it breaks here. And then, uh, yeah, I'll just step over this. And then this is the function that actually sends the payload, like, the messages to GPT. So, we'll try to do it. And then we have an error. It says, uh, this is the error. Um, [snorts] this is the, uh, exception if we wanted to catch it. Uh, "Request is too large for GPT5 in your organization on tokens per minute. The tokens per minute rate limit is 30,000, and you requested 100, 100,000," essentially. I'm not sure why this number is, like, so far off of this one, cuz it's, like, you know, quite a bit off, but anyway, it's, like, too many. Uh, the input or output tokens must be reduced in order to run successfully. Uh, visit this to learn more about your rate limits." And it's telling us that our limit is 30,000. So, that means, like, you know, we're, we are tier one, essentially. And there's probably some way to see what tier you are with code, um, to, like, prevent this from even happening. So, for example, I might, like, I'm just going to, like, experiment with this a bit. You don't have to copy me. You can just watch this. But I'm going to copy this. I'll go to GPT and I'll say, uh, "How to check the API preemptively to see what, uh, tier we are in?" Something, something like this. I assume that we're able to do this, and I'll just, like, paste this. "You're hitting a rate limit." [clears throat] "The easiest way is to go to dashboard and rate limits. It shows your current tier." Oh, okay. Let me, let me click on this and see if that's true. So, tier, Oh, it's here. "Your organization's usage tier, uh, impacts your blah blah blah. Your current tier is one." Okay, fair enough. "Use the API programmatically." Apparently, you can, like, use the API to do it as well. I'm, I'm not going to, like, try to deal with this, but I just wanted to, like, take a look. So, uh, for example, we know this is too big. So, let's just stop this for now. And then instead of sending, uh, the long logs or `log_longs`, I'm going to send, uh, small logs. This is the other thing we imported. So, if we scroll to the top, we see `big_logs`, `small_logs`. So, `small_logs` um has way less, and it should, it shouldn't hit our limit. So, I will make sure this is broken here. And then I will attempt to run this. Oh my god. Start debugging. And I'll do a few more, like, activities just so we can get a sense about, like, what rate limit is and then maybe how to, like, prevent the program from crashing if we do hit the limit. So, estimated input tokens is 25,000. And that should be within our, um, our rate limit for at least GPT5, which is what this column is, which is what we're using, current model GPT5. [snorts] So, we will, uh, press enter to proceed. Then we'll step over this, and hopefully it works. So, and I have to go to the bathroom. So, you can, you can cut this out. Okay, we're back, and it looks like it ran. I'll just let the program finish. And then we see, um, actual input tokens was 24,000, output tokens was 36. This is under 30,000, and it cost, uh, looks like it costs 6 cents to run. So, that's pretty cool. So, let's, uh, try to do one other thing. I'm not sure how this will go, but let's use, uh, the long logs again. So, I'll use, like, `big_logs` again. This is, like, the huge one. It was, like, over 100k tokens, I think. But, uh, we will use a different model. So, you'll notice that, what are these two models? Looks like for these two, the tier one, like, the total tokens per minute is, like, 200,000 for both of these. So, what is this? GPT5 [snorts] mini and GPT4.1 Nano. GPT5 mini is 25 cents per million. So, I'll try to use GPT5 mini and see if we can process the big logs with it. Remember, this, like, failed last time, um, when we tried to process it with GPT5. So, I will get GPT5 mini, put it here, and I will start debugging this again. Remember, we're using the, the long logs this time, or the big one, the huge logs. Where's our message? Oh, it's right, right here. So, we see, oh, uh, what is our max? What was it? I forgot already. 200k. 200k, and we have 149 estimated input tokens. So, this should technically process. So, let's, uh, see what happens with this. So, we'll step over this and let this go. This thing is, like, taking its time to process that. Okay.
It went. It didn't crash this time. So, that's cool. And I'll just like, uh, run this program. I just broke it down here. And then we see actual input tokens, 143k, output tokens, this many. And that cost 4 cents to run. And I just broke this thing here. Um, just as a reminder, you can, if you're interested in seeing like the actual threat hunt that it did, you can like look at this if you want. Um, again, that's not the point of this lesson. Oh my god. Again, that's not the point of this lesson, but um, you can, that is something you can see if you want. But I just wanted to show that if we even have like a ton of tokens, if we switch the model to something that has like a larger, I guess, rate limit window, like tokens per minute, we can still like process the request and it should be okay.
Um, I mean, maybe you understand what I'm saying. There's always like a business use case for like your model selection. Like, if you know, if if it's like too big and you just have to like process it, you can always like, um, for example, when we make the AI agent, there's always like something we can do in the code that says like, you know, if it's too big or if it, if it freaking crashes, you can use a different model. So I'll, I'll actually like show you what that looks like, um, right here. So, for example, let's, uh, I'll just like end this for now. And then, um, I'll switch back to using, um, GPT5, cuz if you remember, this is, this column is GPT5. The tier one is like 30,000 limits or 30, the limit is 30,000 token tokens per minute, which our big logs request is over 100K. So I'll show you like something that you can do. So for example, we can say, uh, I'm just going to let it crash one more time just so we can like observe the error. So I'll switch this model back to GPT5 and I will start debugging this. I'm going to use like the, um, I'm going to attempt to use the try accept block thing again. So, uh, let me see where is our. Okay, so I'll press enter to continue. [snorts] By the way, you have to like click in the console before pressing enter. Uh, so this thing is going to run. So, I'll just like let it go like so. And I'm going to fix it in like a really crude way. And see, we have like a rate limit error. So, um, I'm going to do, I'm just going to, I'm going to fix it with chat GPT actually. So, I will copy this just so you can like see like what's possible and like how, how developers maybe use chat GPT to save time. So I'll like copy this whole thing and then I will go to GPT and then I will say, um, I got this error message, then I'll say, please, please refactor factor of this code. So that, um, if a rate limit happens, um, if a rate limit, uh, whatever exception occurs, switch to model GP. Oops. Model GP. Oh my god. GPT 5 mini. Is this the correct model? Is that how the name of it? Let me make sure. GBD- Oh, it's not even in here. Hold on. Let me just, I just want to make sure I'm saying the correct model. GPD-5- mini. Okay, that's correct. GPD 5 mini. And then I will like show the code that's like in question. I'm going to press escape to collapse that. And then this is the code that does the request. Okay. And I'll paste this. And then it should, it should create something with like a try accept block. And if it accepts, it should like feed GPT5 mini to the model. I'm assuming it's going to do something, something like this. You know, if it's, well, it's pretty smart, so I think it will. So it says, wrap your thing in a try accept block. And this is the our code that we're trying. And then if we get this like rate limit error, um, which is what happened here. I don't know if we can like see this still. Uh oh. Anyway, if we get, if we get the rate limit error, then print this out and then attempt to make the call again, but use model GPD5 menu. There's like way better way to do this. This is like actually like, um, quite crude, but it, it still will work for our intents and purposes. Like a more like, um, what's, what's the word I'm looking for? Like a more robust way to handle this would be to like, um, you know, if you, if you get rate limited, then do some logic that collects the the models for our tier that will handle that many tokens and display them to the user and like allow the user to pick one that's like big enough. Um, [snorts] but for us, I just wanted to do something like really simple to show like, if, if we get rate limited, just you can switch to a better like a, a model with a larger window or a larger like rate limit and then, uh, the code will proceed. So I'll just like copy this. I need to like import rate limit error, but I can do that. And then if we replace this code here, um, I think we can just do like this, open AI dot. I think we can. Oops. I think we can just do that. I think. Oh no, maybe it needs to be lower case. Hold on. Oh, from opening maybe. Maybe we just do this. Okay. Sorry. I think it needs to be lower case. If it, if it's cor incorrect, it will. Oh, we do from open AI. Hold on. From open AI. Whatever. I'll just, I'll just import this. Um, I'm not trying to deal with this for now. Okay. And then I'll just erase this. Okay. Okay.
So now again, uh, we're going to set our model. Our model is set to GPT5 here. But the GPT5 like rate limit is 30,000. So our logs are too big for it. So when it goes to actually ask chat GPT here, here it will fail. And then it will hit the rate limit error exception. And then if that happens, it's going to say, rate limit hit, falling back to GPT5 mini. It's going to set the model like hardcoded it and then try to like do the request. So we'll just like run this and see what happens. I just want to show you like, you know, it's, it's possible to like have the agent be smart. Like we, we'll do this in the future, um, with our agent. We're going to have it be smart enough to like make a selection or a recommendation like on its own and maybe like get permission [snorts] from the user before going and doing the thing. But you can obviously with Agentic AI, you can just have it do the thing without asking permission. But anyway, that's for like in the future. So, uh, this is obviously too many tokens for our 30,000 limit. So, we'll just say enter here. It's going to try to do this. So I will step through this thing like so and observe the error. An error will happen and we caught the specific error. So you see it didn't like throw up the red thing on the screen. Um, because it, it caught the error and if we hover over this like E, we can see the error type. This is what would have shown if we didn't catch it. The error, the request is too large for this organization. Your, this is your 30k limit. This is the thing we saw last time, right? So instead of erroring out, it went to this block of code and it's executing everything. Rate limit hit, falling back to GPT5 mini. And then it's going to run the request again with the new model like so. Just wait for this. Cool. And actually, it worked. Very good. We'll just like step through this thing some more, you know. And you might be asking like, why even use GPT5? Just use GPT5 Mini. It's just because like, you know, different models have like different use cases. Um, remember, you know, GPT5 Mini, it has like, it's faster, but it has worse reasoning and like, whatever. There's like differences between them. The GPT5 Mini is like way cheaper than GPT5. Um, at least the API. Um, so it just depends on like your use case, right? So, we will let this thing finish. I'll just like run this to the end and then, um, it cost us. That was not cheap. That was like 20 cents down the drain right there. Um, but that's okay. That was like a lot of vlogs, by the way. That's like a ton of vlogs. It's like a book. So, we'll just let this finish and it's done. Yeah. Hopefully that makes sense. And remember, like I just want to like remind you, like these are not, um, these are not the only models available. I'm just like using these models just to, you know, so we don't have to list out like 10. I just want to show you that there's different models and that they have like different properties, like different rate limits, different windows, and like all this stuff. So, um, feel free to like experiment with other models. Um, if you go to the screen, you know, you, again, you can always like add another column like so and then just pick like, in, I don't know if you can use all of these, but there, there's a bunch that you can like check out and you can see the differences between them. Like GPT5 Nano, apparently that's like extremely fast, it looks like, and it's also extremely cheap. It looks like, like 5 cents per million tokens with a huge window. So GPT5 Nano might be like, you know, the best for just doing general coding and stuff. And again, like with the agent, you can have it like default to like the cheapest one. And then you could have it say something like, uh, do you want to do analysis with a a more advanced reasoning model? And if the user says yes, it will just like automatically run the, um, prompt again or whatever with GPT5 or, or something like this. The pretty much, you can literally do like whatever you want, but I just wanted to show what rate limits were and kind of help you get a sense and intuition for those. But yeah, we will see you in the next video. Um, I think the next lesson we're going to look at optimizing KQL queries to like really show the difference between pricing, um, and how it can affect the pricing the more you optimize. So, we will see you in that lesson. [snorts]
Welcome back. Uh, in this lesson, we're going to be covering and trying to build a better intuition for why it is really important to optimize your KQL query and then send as few logs as possible to the model before like having them analyze, cuz spoiler alert, it just gets expensive. So, you want to like really like optimize those, especially if you're like doing a lot of hunting and sending a lot of stuff to your model. You don't want to like send, uh, superfluous or like unneeded logs to it, cuz yeah, just, it's not cheap. Plus, it's, you know, not good for the environment either. Um, but anyway, all you need for this lesson is this file, uh, this optimizing KQL queries file, and I'll prepare it, um, so you know, it matches what I have here. And then just go ahead and download that and then put it in your folder, and then, uh, open your folder inside of VS Code, and then we can start here. So basically, um, I'll just explain what this, I'll walk through this code, but I'll explain what it does really quick. Um, basically, it, we're going to query KQL or we're going to query log analytics for some logs. So for example, like device log on events, and then we're basically going to see like how much each query, like how much the query will cost to process with each model. Like, it's going to loop through all the models and be like, if you use GPT5, it will cost this much. And then we're going to like, uh, prune down our logs, um, like optimize our query, and then observe the new cost and hopefully like get a sense for, you know, why it's important to optimize, um, our queries. So before I like talk too much, I'll like just get into this, I guess. Um, so I will basically, um, so everything like inside of these like, like long dashes of comments, these are basically like our levers that we can pull, but to affect cost. But mostly we're just going to like change these, uh, in this lesson, um, just so we can like, you know, I just want to focus on optimizing the query and seeing how it affects cost. And then also see. And then yours will probably have this, but I'm just going to exit the code. Like, I'm going to, there's like a loop here that's like for model and models and like all the stuff. I'm just going to exit the code like right before it says like, print or press any, press any key to proceed, cuz I don't, I don't necessarily need to process any log or I don't need to send anything to GPT, I guess, in this lesson. I'm just trying to see like, estimate cost based on model and like the log size. So that's, that's pretty much all we're doing. So I'm going to, um, let's see, I'll break the code, maybe I'll just, I'll break it like here. OpenAI client, like after the function definitions, and I'll just kind of explain everything as I go. So go ahead and just start debugging. Then we'll step over this. Our OpenAI client is created, which allows us to interact with GPT. I don't actually think we're going to use that in this lesson. And then our log analytics client gets created. This allows us to query log analytics. To setting the max output tokens, limiting how much the API can respond with to limit the cost. This is a current model selection. Um, actually, we probably won't even like use this. We're going to step through each model, but, um, I just like left it in here. [clears throat] And then hours ago, this is for like how many hours ago we're going to query our table in Log Analytics. And then this is our actual query. We're going to be editing this or like adding stuff onto it to reduce the size, but we'll step through this and then I'll use like step into, actually. This is our log analytics, um, query. It's going to query log analytics with our query, which is just device login events, just the table. So I'll use step into instead of step over, just so I can like go into here and like look at it. So, this is where the query happens. You, you would have. Oh, yeah. And by the way, uh, if you get an error here, I'll just like wait for mine to go. So, if you get an error here, um, you have to open up the command line. So just open up like, click, you know, start and type command, or if you're using Mac, open up terminal and then you have to do like AZ login, like so, because you have to be like logged in in order to query log analytics. So, um, click your account. If you don't have it here, just like type it in. It's your cyber range account. So I'm logged in and then just, you can just pick cyber range one or two, either one. It, this is automatically defaulted to one. So I'll just like press enter and I'm logged in. So if you get an error here, you have to like log in and restart your code. But anyway, I will step over this. And then this is like the table that got returned from our query. So if we look at this table rows, there's 1161 rows. And if we run that query ourself manually, like so, device log events where time generated is greater than or equal to 3 hours ago, we get like 1134 rows there. It seems to be, there's like a slight discrepancy. Um, I don't know why that is, but it's pretty close rows. So we'll just step over this. It's going to count the records. 1161. It's going to do some stuff and then basically change all of those logs into like a big like plain text thing that we can send to GPT for analysis. We're not going to send it again. We're just going to like use this to, um, estimate how much the queries are going to, or rather, how much the chats are going to cost with this query that we did. So now this thing ran and inside of this variable has like all of those logs, um, for like, you know, the last 3 hours from the device login events table, every single field as well. It has like every single column, you can see. So, um, this is going to craft the prompt messages. So there's two messages. I'm going to collapse this a bit. One, uh, oh yeah, the two messages. The first one, this is like the system message for context. You're a threat hunter. If the user provides logs, analyze them for malicious activity. And then a a user message that says, "Here are some logs." And then we pass in that huge thing of logs with some string interpolation. So this is this would be our message that we sent to chat GPT to do the threat hunt. And then we're going to estimate the token count. So we're going to pass the messages, pass the messages into here, and then the model, um, instead of like normally we'd estimate the token count for the all the models individually, but all of the models, I believe that we're using use the same encoding. So we can just do this and the token count is going to be the same for all of them. So if we step over, we get like the estimated token count of about 350,000 logs. So we're going to set the max tokens used in response to 5,000. This is just a constant variable we set up at the top. And then now we're entering a for loop. And this, this is a loop. It's going to loop through each model that we have in models. Like, if we look at this, these are our models that we're dealing with. Um, this is at the top, the top of the code. It's like a dictionary we made. It's going to go through and basically like calculate the cost and output the cost for every single model. Um, assuming, you know, that we actually send this to chat GPT. This is how much it would cost for each model. So, I'm just going to like break this here like so. And then if you click continue, it will just do all of the code and then output it down here as you can see. So, if we send this whole thing to GPT5, it will cost about, about 49, about half a dollar. It's like kind of a lot. If we press continue, it will do all the stuff and it'll show us for GPT4.1, it's about 39. And then if we, if we say like step over, we can see these like individual things. We can see the code executing like, you know, individual line by line. We see it here. So, GPT5 mini, it's about 9 cents. If we say continue again, GPT 4.1 nano is about, um, 3 cents if we send this whole thing. And this is like, uh, a staggering like amount of tokens too, by the way. And I, I do want to say like, if, if we do send this, it's actually going to fail because even though like GPT5 and GPT5 Mini, it says it has a window size of 400,000. So, for example, if we look at the model comparison, we see like GPD5 and 5 Mini has a, it says it has a window of 400,000. And but actually the, the window, or rather the maximum input that you're allowed to send to these is actually like 400K minus this. So, it's like 2772,000. Even if we limit the max output to like 500K, I learned that the max input is actually like this minus this. So, I don't think like any of these models can handle this except for maybe, uh, maybe 4.1 nano can because it has this like absolutely massive window of like a million and max output of only 32K. So, um, this is just like in theory, like if we could send this amount to GPT5, this is how much it would cost. Um, yeah, so that's, that's, that's that. So, if we like continue over this, I put an exit here. So the code, the code will just exit like so. And yeah, that's that. So, oh, that's interesting. Five for. Oh, do I have five models? Hold on. Five 4.1, 5 mini, 4.1 Nano, 5 4.1, 5 mini. Oh, why did it say two five minis? Oh, this is like, oh, something's weird with this. I don't know what happened with that. What? Something weird happened with my. So, I'm going to clear this. Something weird happened with this. I'm just going to like, uh, run this one more time. Actually, let me like delete this terminal and open up a new one. And I'm just going to run this without debugging, just so it can like run all the way through. And then, cuz I want to like have the thing, the output on the screen so I can compare it after we prune the logs down a bit. And then who's ever editing this, they can like remove that thing that where I was just like looking through those a lot. So here's our output, uh, GBD5, 4.1, 5 mini, nano. And you can see like the, the token count is the same, of course, but the price is quite a bit different. This is like 10 times more than this. So that's with our logs. And remember, uh, we actually, let me go to our, this is, this is our KQL query. I just straight up queried device login on events. I didn't filter it down at all. So, if we go to our log analytics, we can actually like, um, use our, our brains to like figure out which logs are most important for our threat hunt. And if you're wondering like, how do I know like which logs are more important? Um, I just recommend you go through like the security operations, um, and threat hunting course. Um, we, we really like dive into that quite a bit, but I'll, I'll kind of explain stuff here as I go. So, basically, like, as things are now, for example, if we say like, get schema and run this query, we can see that there's like, starting at zero, there's a total of like 54 fields in here that we're sending to GPT. And it, it's a lot. We're, we're calculating the tokens on 54 total fields. And we don't need like all of this stuff to do like a proper threat hunt, cuz a lot of the, a lot of the information is, is basically like useless. So, um, we're going to use like the project keyword to, um, select only the fields that we feel are like important. So, like, time generated, this is obviously important because you need it for like, to get a timeline of what, what happened. It, it's basically like the log is useless if it doesn't have a time in it, cuz it could have happened like 10 years ago, you know, it's not useful. And then account domain. This is like questionable whether or not it's useful. I believe this is like the same as device name. Um, I'm not sure to be honest. And it might be worth like dumping these, the schema or the fields into GPT and be like, being like, explain to me what all these mean. Um, because I, I don't know what the difference between account domain and like device name is. It looks the same to me. Um, so I'm, I'm going to skip using account domain and then account name. This is probably important because this is the device log on events table, right? So this is like when somebody tries to log into a server or virtual machine, a log is created. So account name, we want to see like what they're using to log in with. Um, account SID. This is, this is important in real life. Um, it's, it's important to know when you actually find, uh, something may have been compromised and if you have like free money, this is something that you would include, but I'm not going to include it because the field is like, it's quite long, and then this is a lab, so I'm not going to include it. Uh, SID is like, uh, I don't know a good way to explain this. It's like the unique ID for an account. So like, you can have two accounts named like rap, ra, ra, ra, ra, ra, ra, ra, ra, ra, ra, ra, rack, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, pan, for example, but they could have a different SID, and that would indicate that they're a different account. That's my understanding of it. So I'm going to exclude that. Uh, I'm going to include action type, cuz that's like really important, whether or not the account actually was able to log in or not, as someone who was able to log in, I guess. Uh, additional fields, I'm going to like not include that. I'm not going to include device ID, cuz that's like same thing. It's like the unique ID for the device. Like, there could be two devices named this, but if they have a different ID, you can assume that they're two different things. Um, failure reason. I'm not, uh, this would be good to include, but, um, you know, it looks like there's like a lot of like, you know, nulls here, so maybe I'm not going to like include that. What else do we have? There's a lot of stuff in here that we could include, right? Remote IP. This is probably useful. This will provide a lot of context because remote IP, like 10.0.0.8, inside of the cyber range, this is actually the scan engine, like the Tenable scan engine. Um, remote port, this would, you know, probably be useful in real life, but I'm, I'm not going to include that. I'm just going to include like the most basic of stuff so we can get an idea, right? So, time generated, account name, action type, and then the remote IP. That would be good enough for our intent and purposes. So, I'm going to like run this and then we can see it. It's like a really, really slimmed down log. So, like, time generated, account name, action type, and then the remote IP. And we, you know, we should probably include more than this in in real life. But this is like good enough for a lab just to show the difference in log size, um, if we like slim down and optimize our query. So, I'm going to copy this like so. I'll go to here and then this is our, this is our query. So I'll just paste this in here like so. And you remember like we're, oh, I'm not going to include this actually because we're, we're doing that here and it gets handled by the, whatever the log analytics module in a different way. So I'm just going to include the projects here and then I'll, I'll run this one more time and then if you want to debug it, you can break your code somewhere. Um, I guess I'll like here, I'll break mine here and then I'll just like debug it. Oh, actually, actually no, no, no. I'm going, I want to, I want to like observe the [snorts] um, yeah, I want to observe the records returned first. So I'll, I'll break it, uh, right before the query happens. So, if you remember here, um, when we run this for like the last, the last 3 hours, we get about like 1,300 logs. So, if we go to our code, we're going to step into this function and then we're going to step into this, uh, log analytics, uh, workspace is being queried currently. The query finished. So if I step over and then I see this record count. This is 1357. It's pretty close. Oh, it's exactly the same actually. So now it's exactly the same. I think we did it in a close enough time frame. So it's going to create a big dump of plain text with our logs like so. And it will return it. So inside of this logs variable, these are all the logs. And then again, it's going to construct our system message, which is like, you know, giving the model context, and then our user message, which is the command, here are some logs, dumps them in with string interpolation. And then this is important. It's going to estimate the prompt, uh, token count. And you see already, it's, it became 46,000 down from 39 or 390,000. It's probably about, what is this, like a factor of like eight or something. It got, it's like eight times smaller, about. So if we step over this and then I'll just like remove this, uh, break point. I'll just like, you know, let it run and we can see the cost difference. Previously, we can see like, I think our, the command line gets like really messed up, to be honest. I, I think I'm not sure like why this happens, but, um, you can see like GBD5, it costs like 53 cents to process 390,000 tokens, but after the optimization of our query, GBD5 now costs like 10 cents to process 46,000 tokens. This is like, like quite significant. Then GPT5 mini, 2 cents. GPT4.1 nano, less than 1 cent. It's like a bit over half of a cent. And that's why it's like really, really important to optimize your logs, cuz we, we're getting the same amount of logs, but we just like removed a lot of the filters that we quote unquote didn't care about. And it, it is good to have like, you know, the more context you can provide the model, the better, because it can threat hunt better. So, for example, like, you know, if, um, you know, there are two computers named, oh, I didn't include device name in here. That's like a, well, I should probably, probably should do that. Device name. I probably, probably should have done that. But so, for example, if you have like two devices that have the same name, but the device ID is like different, for example. That, that provides like valuable insight into like the threat hunt, right? Cuz maybe you could notice like, if you feed the model, um, a bunch of logs and there's like two devices that have the the same device name, the the model doesn't have any context that they could possibly be different devices, right? So it, you know, it makes sense to be able to like include the device ID, right? It just, you just have to consider it in terms of like how much it costs. So, for example, I'll like run this query, um, where I include the device, maybe, yeah, the device name and the device ID. I'll like, uh, copy this. So I'll copy this project thing. Oh, my bad. And by the way, if you like select like one thing and you say run, it will run only that one thing and it will produce an error. Like, so, like if I only this row, if I run it, it produces an error, right? But if you select all and run it, it will do the query. So, I'll copy this whole, like, this whole thing and I'll go to here and then I wonder if I can like, I'm going to press like, um, Windows shift and take a screenshot of this. I think it went to the desktop, but okay. Oh. Oh, copy to the clipboard. Okay, I just wanted to like keep this open because it, it messes them up. What? For whatever reason, it messes the command line up. So, I have my, my new filter. So, I'm going to like put that here, man. Hold on. Let me try to do that again. I'll try to copy this and then I'm going to add some fields in here. I'll add device name and device ID. And you know, technically it probably would be prudent to add account ID as well. Uh, I'm not going to like do that. But I'll just like run this all the way through without debugging. And then, uh, yeah, I'll just run it. I'll just, I'll just run it. And you notice the new input tokens, um, the previous one, let me see, the previous estimated, uh, the input tokens was 46,000, and then adding device ID and device name basically like, it basically like doubled, right? It doubled the token count and it nearly doubled the cost as well. So it's, it's something to to consider, right? So if we don't want to use like device ID, say we just want to do like a basic hunt or something and we don't want to be all extra, you know, we just want to have like a basic hunt just for the sake of our lab. I'm just going to remove device ID from here. It's going to reduce the tokens by like a, a substantial amount. So let me actually like copy this as well. So command shift S, get this. So this is with device ID and I removed device ID. So we'll see how much it costs without it. So I'll run this and I will, uh, I'll just run without debugging. We have a good sense of how this code works. And then after removing device ID, what do we have? Um, previously with GPT5 it was 17 cents. Removing device ID, it reduced it by 4 cents. This is, it's pretty substantial, like 4 cents, cuz if you do that like enough times, it, it like really adds up. Like 1 cent is like, it's kind of a lot in this context. And then GPT 4.1 nano, previously it was like 1.2 cents, it went down to like 0.8 cents. Um, so that's, this is like, what is this, point? It's, uh, it's not less than half, but it's like getting pretty close, but it's, it's pretty substantial. It's like a, a decent amount of of money, right? Especially if you do these like over and over again. And this is what I would consider like the bare minimum of importance for device log on events. So, let's just like do some more queries. I'll, I'll do a few more with like a different table. So, instead of device log on events, let's look at the tables that we have at our disposal. Security Center free. I, I don't know what's in here. Security alert. Security baseline. Security. You can literally pick anything. Anything that you want. I'm just going to like see what's in here. [clears throat] Uh, okay. Device, device, device process events is like a really big one. I know I use it a lot. You don't have to use it, but it's like really significant. So, device process events, I will say like, you know, where time generated is greater than equal to, I'll just do 3 hours ago again. We'll see. My bad. So I will run this just, just as is, full on, full schema. So I'll take this device process events like so. Oh, and by the way, by the way, we're, we're doing this for like the last only three hours, too, right? And it, this, this grows like substantially. You can, you can imagine if we do like the last 24 hours or something like this. So, I'll do like last 24 hours. This is still device log on events for the last 24 hours. And, you know, basically like when you, when you set the project, like when you filter out, um, when you filter out fields, you're basically making the log like really skinny. But if you're like, like reducing the time, you're making the log like really, really [clears throat] short. And by increasing it from 3 to 24, we increase the logs like length, I guess, or size. It's like really, really tall. There's like more records. But there's like less records in the sense that we filtered them down a lot. So in the last 24 hours, you know, it went from costing, you know, 13 cents up to costing 52, 52 cents. [clears throat] So that's significant and that's something to like keep in mind. But anyway, I'm going to search, uh, device process events, um, all, all of them for the last, uh, 3 hours like so. And it returned 12,000 records. And I'm going to copy this device process events. And if we say like, get schema, for example, get schema. Uh, we can see like how many fields or how many rows there are in here. And there's like a lot, 0 to 72. So that means like 73 rows total in here. So, [snorts] we're going to go back to our code and we're going to say hours ago, we'll say like 3 hours. And then we're going to remove all of these like filters. And then I'll pass, uh, device process events in here. And we'll just like run this without debugging so we can get a sense. Remember, we're not filtering this down. We're going to get all 70, whatever, 73 fields for the last 3 hours. And this is going to [snorts] be a lot because there's like, there's like quite a bit in here. The, the log size is like generally quite large. And I'll show you in just a second while this is going. Actually, I'll go, I'll just go here and show you. So, I'm going to reduce this a bit. I'll collapse this. And we can see we can like do this and it just basically like expands out this. We like, we could scroll to the right like forever, right? It's like really long. Or we can like expand one of these and we can see it like kind of inline like this. It's, it makes more sense and it's easier to look at. So we can see we have like tenant ID, account domain, account name. Oh, by the way, this table, this device process events, this is like whenever somebody opens a file on their virtual machine or they, they run some program or something like PowerShell runs or like some some command line, like some command runs or something, um, like a process starts, essentially, right? So, actually, I'm going to look at one of these that that is like Windows, cuz that might be like more familiar to people. So if we pick one of these where, let me see, the account name is like not root, I guess, or the account name is NT authority or system. Um, I'll just like look at one of these and we can see like the stuff that's in here, like account domain, uh, account name, the account SID, action type, device ID, and there's, there's a lot, right? So the most important stuff for this, I'll like go over those in a bit. Um, but for now, let's just like look at what happened here. This is absurd, right? What is, I don't even know how many records this is or how many tokens. This is 13,100,000 tokens. There's no, there's no model that can even process this, right? It's, it's not possible. Um, the largest model I think can process like a, maybe 1 million tokens, which is, I think it's 4.1 nano. But anyway, theoretically, if we could process all of these by like GPT5, this would cost like 16 bucks to do and 13 bucks, $3 a dollar. A dollar is a lot for like a single request. That's like a significant amount of money. So, for threat hunting, um, I would recommend [clears throat] like of course, like reducing the log size, you know, cuz maybe you, maybe you want to look in 3 hours, right? You need to like reduce the amount of fields you're actually like inspecting with the log. So, for example, let's see what's important. We can just make the distinction or make the, you know, decide what's important on our own where we would project tenant ID is probably not important for us because it's going to be literally the same for every single computer unless we have multiple tenants. Um, account domain could be important, but maybe like device name probably is like more relevant. But account name is important. So, we're going to project, um, definitely the time that it happened. That's important. And then account name is important. This is the account that actually launched the process. Um, device name is really important because, you know, we need to know which device it happened on. And file name. Um, I believe this is like the file that was executed, I suppose, or either that was executed or did the executing. I can't remember. Again, this is like really good use of chat GPT to figure out exactly what all these fields do. File size, um, this is the name of the, or the size of the file that got executed, I guess. So instead of getting file name, might be important, but, initiating, there's a field called like initiating process command line, and I, I believe that's like, um, potentially more important. I think. Oh, maybe it's not. So maybe we need to get file name and then initiating process command line, probably is important. And then there's another one that I remember, initiating process file name. What else is like would be important or pertinent to a threat hunt? And sometimes like, um, some fields are blank in [snorts] some logs. So, let's just like look through these and just, I'm just, by the way, if you're doing like a proper threat hunt and like legit defining the schema and what you want to use and send to the model, you would do more scrutiny than this cuz like, you know, Shaw, all these are important, like Shaw, like the thumbnail, the thumbrint of the thing, um, all those are important, but you have to consider it's like going to get quite expensive if you send like start sending a bunch grids or like, um, IDs like this to the model. It, it's going to get really expensive if you have a lot of logs. So, this is, this is probably, probably good enough [clears throat] for now for for our intents and purposes, cuz you see how like big the log is. Um, let me look at something. Okay. Okay. So, for now, I'm just going to like use these fields, um, just to keep the log a reasonable size. So, I'll take these. I'll go back to here and then I guess I'll take a picture of this. I know this lesson is getting a bit long, but I just want to like help build an intuition for things. So, we'll open this just so we can like have something to compare it with. I don't know why this is like that. Why are you doing that? And then we'll go to device process events and then we'll like, uh, I forget if I copied project. Oh, the. Okay, we'll copy this, project it for the last 3 hours, and then I'll just run this without debugging and we'll see cuz remember without pruning anything, we just got all the fields for the last 3 hours, 16 bucks. We can't obviously query that much because the, there's too many tokens, but anyway. But now it's, it was able to reduce down quite a bit. It's only like, instead of $16, it's still like $19. This is a lot for a single query. And this, this is like too many tokens for any model to process. It's like a, you know, 1.5 million tokens. So for something like, um, device process events, this is not really something that you would do for like all the computers in your environment cuz remember like the cyber range has like 400 computers in here and like I don't know how many of them are like onboarded to defender for endpoint. It just depends on, you know, how many, I guess users are are doing it, but this [snorts] is more so something that you would target like an individual computer for. Um, like I wouldn't target the whole [clears throat] table. So I would filter it down even more. So, for example, like maybe, um, where, you know, uh, device name equals, um, maybe this guy, this person's device, stmm. This is, this is somebody's, I don't know whose it is. I'm just going to run this here and then see. And there's like way less logs. There's like 105 logs for the last 3 hours. You can probably do like, uh, you can pick one on your own or you can probably get like a Windows target one if you're following along. 116, um, Windows target one. This is like the Cybrains like honeypot, I guess. Uh, I'm just going to use this, this person's. Oops. So I'll, I'll get both of these filters. I'll just copy it like so. And I will go to here. And then I'll replace this like so. So we can filter the query down by device name and by, uh, our fields. So I'll just like run this without debugging. Maybe I'll take a picture of this if it lets me. Cool. So, okay. [snorts] So, remember we queried the last 3 hours with device, uh, what's that, device process events for all computers. We ended up still getting like 1.5 million tokens worth of records. But now [snorts] uh, it, we filtered down, filtered it down to look at a specific user's virtual machine and then now it's like way more reasonable. It's only like, uh, 850 records, right? Sorry, I mean 8,520 records and it's still like, you know, 6 cents is like a, a decent chunk of change for like a single query, but it's, it's, you know, way better essentially than at $2, right? This is like 40 times less essentially. Probably like 35 times.
less. Wait, let me. I'm I'm curious about like how accurate I'm being with those. So, what is this? 0. I think it's about 37 times less * 37. Oh, it's slightly less than this. It's probably about like, you know, 33 times less or something like this. But anyway, it's it's way less.
Of course, you have less context. You're like focusing on a single virtual machine, but still, um, it's it's just important to like, you know, it depends on like what you want to do and like what's even possible with the model, right? So hopefully this gives you some kind of a sense of like why it's important to optimize your logs not only for like the time period in which you're which you're querying. We did mostly like 3 hours here. But also the fields in which you're sending to, um, the model, cuz even adding like one field, it's kind of like it's going to increase the the log size or the token size substantially.
So for example, [snorts] this initiating process command line of course, this is like integral to threat hunting in the device process events field because I'll show you like it contains like, you know, what what got executed essentially. It's like really important. But I just want to show you like, um, just like adding this, this is like a substantial amount of token. So if I remove this and I I run this without debugging, GBD5 was like 6 cents and this is like 2 cents. If we just simply removing that field, oh, it's still like it's still like a decent amount. It's still I guess it reduced by only like 1 cent. I I would have expected it that it would reduce it by quite a bit more cuz that field is like that field is like kind of big, right? But, um, anyway, yeah, you can see it makes sense like adding or removing one field, it makes a big difference. Oh, I guess it's only like slightly less because uh the the logs, the amount of logs is like not that many cuz we're only targeting one computer. But anyway, I hope this makes sense.
Um, I encourage Oops. What did I do? I encourage you to like play with this a bit more because remember there's like a lot of there's like a ton of different tables. Um, we just so happen to be only using like a certain select few um in our threat hunt, but there's there's like literally like a lot. So I might, you know, experiment with them here like in inside of log analytics and I might experiment with them here and see like, you know, how much it costs for like different time frames and different logs being projected or different fields being projected. But yeah, that's a lesson on uh optimizing your KQL queries and why it's important and like how it can affect cost long term. So just like imagine scaling these out to like hundreds per day. Obviously, you want you would want to spend like, you know, 1 cent [snorts] instead of like five and a half cents, right? It's it's it's like substantial. Like the more you do it, it it's really can cost a lot. But hope that makes sense.
Um, as always, ask questions in the forum uh if you uh get stuck or something doesn't make sense and tag me. Um, otherwise, we'll see you in the next video, which will probably be the beginning um where we start creating our actual um cyber security AI agent. So, look forward to that and we'll see you soon.
Welcome back and welcome to the first section where we're actually going to start uh building our AI agent out. And pretty much everything we've done up until this point is going to be used in some way, shape, or form in the following lessons. So I also want to say like don't get discouraged. Um cuz what we're doing is it's kind of difficult especially if you haven't done programming before. You're like not used to Python. Um so don't get discouraged. It just takes a lot of repetition and maybe some conversations with chat GBT and then using the community to get like better understanding of everything.
So, um don't get discouraged and don't try not to be in the mindset where you're like um oh like I didn't produce this code so you know I have to get to the level where I need to produce it. I mean, if you want to be able to do that, that's cool. But my intent is to get you to the level where you're able to interpret code and make sense of what's happening and like make sense of what it's doing. If you want to like be able to produce code, that's cool. Um, but that's not my intent with this. And I I don't want people to get like really hung up on that. We're just trying to get a good understanding of what's going on and get an understanding of like the workflow of what an AI cyber security agent might look like and get an understanding of how to use APIs and how to use LLMs and just get an understanding of all that stuff versus trying to like become a full-on software engineer or something like this.
So, just try to focus on understanding and if you get stuck just uh ask in the community and feel free to tag me if you want. And also I want to say um it's really worth going back and doing the previous sections um like even the fundamentals of Python and then the building blocks for sure. Like if you go through this section and you go back and then watch the building block section again that will make a lot more sense and you'll have a lot more context um into what we're doing in this section and then you can like you know watch this section again. I think all that will help a lot. But yeah, uh don't get discouraged. Just try to focus on understanding, focus on debugging and paying attention to what the code is doing and then leverage all of us like the community and and me as resources. And yeah, we'll see you in the next video.
So before we really get started, um I wanted to go through this diagram really fast just to show you at a high level of what the agent is doing. Um you don't have to follow along with this. You can just kind of relax and watch. We're gonna like get into things and do the hands-on stuff in the next video. But basically um I just wanted to show a high level flow. So when you run the agent or you run the program or our baseline agent will first ask the user what they want to do which is denoted by this box and then the yellow boxes are indicating like some kind of interaction from the user. So the user will respond with what they want to do. So I'll just paste this.
And then the next thing the agent is going to look at what the user put and then try to derive the correct areas to search and then the proper metadata to go along uh with their request. So for example, we can step over this. It will decide where to search like is it in the audit logs table or the device log on device process events like where do we need to search to figure out what the user is worried about and then once it finds out it will display the tables it's going to look in as well as the uh justification for it. So if we step over this it figured it out. So it's going to display the tables. So signin logs 48 hours in these fields and then the justification for it user reported tenant level suspicious activity. So I decided to look in signin logs etc. We'll validate the fields. We'll step over this uh fields and tables are validated. And then next it's going to actually query log analytics and collect the logs. So that's what this is doing. So the query is being run against log analytics. Query is finished. About 1,900 records were returned. And then next it's going to construct the prompt to send to the GPT's API endpoint which is like what we're going to thread hunt based off of. The prompt is the prompt consists of the initial user input, what they were worried about, some information about how to threat hunt in those specific tables, which it's going to get here, and then it's going to append those 1,800 logs at the very end. So, what we want, how to threat hunt it, and then the context for like where to search.
So, that's what's happening now. And then the threat hunt system prompt is being built. This gives GPT more context as to what it's supposed to be doing and how it's supposed to behave. So the threat the system prompt is built. The messages are put together. Combine user and system prompts to calculate tokens and estimate cost. So, it's going to combine these two messages and then it's going to count up the tokens. I don't think I put it here. Um, but it it's counting up essentially the length of the message and then it's going to um allow the user to choose an appropriate model and then validate the model afterwards. So, if we step over this, it's a bit hard to see. I'll like expand this a bit. You can see it's giving us a bunch of different options for models. And then this is our current model, the default model. So we can choose a different model or we can continue with this one. I'll just press enter to continue with this model. We'll step validate model. Model is valid. And then the next thing it's going to execute the hunt. So, it's going to take note of the start time to see how long the hunt takes. And then this is where the hunt executes here. So, the threat hunt is being executed by GPT5 Mini. But, funnily enough, oh, that's so funny. The tokens that the token estimate was really close to like the the max for the model. Actually, it's it was probably slightly over this. Um, as you can see, it was over by like 3,000 tokens. So, normally the hunt would have conducted here, [laughter] but uh there was like there's too many tokens like our request was too big. Um, so normally um the results would have been displayed to the user like right here and then the the program would have ended and then future stuff uh for each result consider taking some kind of remediation action. So for example, if the model or the hunt determined that there was a compromise with high high uh confidence, we would like execute some kind of action against it. But that's all I I just wanted to give you an overview of how this um agent hunts in in a graphical context in a sidebyside.
So I'll put a link to this down below in this video as well as the next video um so you can kind of use it if it helps as you're observing the execution of the program. And I'll go ahead and like leave this in here. Uh it's just like a really interesting thing cuz the estimate is it's not exact. It's pretty close. Um but it's not exact. Our estimate was like, you know, 269K, but in reality, the token amount was like 273K, which is just over this. So that was really interesting. Um so I'll leave that in there. But yeah, we will see you in the next lesson.
Welcome back. Uh, in this lesson, we're going to dive right into things and just start doing stuff with the code. So, how this is going to work is I already created a baseline agent that does some basic threat hunting type stuff. It it's missing a lot of functionality and like a few things are wrong with it. Um, but it it basically works and does some generic stuff um pretty well. But we're going to dive into this. So, we're going to see how it works in this lesson. And then the next lesson, we're going to talk about the stuff that's wrong with it and the stuff that's missing. And then the subsequent lessons after that, we're going to do like more of a deep dive into the individual components of it to make sure we really understand how it's working. And then after this, we're going to start adding some functionality to it. So, it's like a true agentic thing where actually goes out and does some kind of remediation.
So, uh go ahead and download this. I'll put a link for the for this below. Um, it's a zip file. So, if you double click it, there'll be like another folder inside called baseline agent or it will just extract if you're using Mac. So, I'm just going to put this on my desktop like so. Like so. And then I'll open VS Code. So, go ahead and open up VS Code. who's ever editing can like cut that out. Um, so if you have a folder open already, go ahead and close it with close folder down here. But, uh, we're going to go to file and then open folder. And then we're going to open that folder we just put on our desktop or wherever you decided to put it. It's the baseline agent. So, we'll select this. And then there's a bunch of stuff in here. We're going to talk about all this eventually. Um, but first thing we need to do, if you go to keys, um, you need to put your own open AI key in here. So, go ahead and control-click this. I put a link in here, uh, for your convenience. And then you can just create a new key if you need to, or paste your key if you remember what it is. So, I just made this key. Uh, so I'm going to use it. So, we'll paste this. and then make sure there's like no syntax error and it's correct. And then the [snorts] next thing we need to do is if you go to model management and then under this current tier, you can probably just leave this as one, but if you know you're a higher tier, go ahead and put your tier in here. This is for like the open AI like API tier tiers. And the lower your tier is, like the more you're going to be limited to how much you can send to the GPT API and then how often you can send stuff. If you want to figure out what your tier is, you can just like click on this or control-click and then you can see your tier here. This is my like I guess alt account, I guess. Um, so most people will be like tier one because you probably probably just made this account for like this lesson. So that should be okay. And then pretty much that's all you need. Um, under keys, of course, um, this is where you'd put like the log analytics workspace ID. So, if you're a Cyber Range member, um, this this is already correct. Um, but if you're not, you just have to put your log analytics workspace ID in there. Um, I don't expect anyone to do this. You should probably just like join the side range if you haven't already and just use this. But, um, we'll go to main and then we're just going to like run things straight away. Um, I'm not going to do like a super heavy deep dive into everything. Um, I'll I'll just kind of explain stuff a bit as we go, but go ahead and um set a breakpoint here uh right before this like log analytics workspace client. So do that. Then go to run and then start debugging and Python debugger. I'm going to close this thing and then we'll let this thing break.
So this log client, this is just used to query our log analytics workspace for the logs. So we'll step over this. The client gets created. This open AAI client is for quering the chat GBT API. So we'll step over this uses um it uses the open AI API key which we just made and then this is where uh the initial model gets set and it's coming from this uh model management uh module we imported. So for example if we click like explorer these two files we see model management here which is this and it's importing default model. So, if we click on model management, we see a bunch of stuff in here. Um, but we can see uh default models right here. And it's set to GPD5 mini. We go back to main and we step over this. We see model. It got set to GPT5 mini. And then this is going to use a function called get user message that's part of the prompt management module. And we see over here prompt management module. And then there's a bunch of stuff in here. I'm just going to collapse it. And we see like get user message. So this thing is about to run. It's going to ask us like what we want to do. So if we step over this, we see it. Aentic stock say your service. What would you like to do? Um, I'm worried someone has logged into our tenant in the last day or so or some other um malicious bad spelling malicious. Is that correct? Malicious has happened.
So, this is our generic message we're sending to um our agent. And then it gets this will format it and store it inside of a message object that is readable by chat GPT. So roll user contact content and then the thing that we just typed and then query context. Um, we'll we'll do like a deep deep dive on this later, but um I'll show you what this object is after it gets created, but basically um it's using GPT as well as what are called tools to figure out exactly like where to look for the stuff that's relevant to our uh query and also like um decides a bunch of other stuff about our query like was it about a specific computer or like a specific user, etc. So, um, we're going to dive into this a lot later, but I'll just step over it for now. And then if we go to, u debug, we see this this unformatted query context got created. And if we look at this, I'll collapse these things. Unformatted query context. You can see that like a a bunch of stuff got uh populated. it it basically did our first query to chat GBT and said like okay the user the user said this um this is context for what we're doing return all this stuff to me and then it decided it's going to look in the signin logs it decided that it's going to look in the last 24 hours because we said the last day or so it decided it's going to look in these spec specific fields in signin logs and then is it about an individual user no is about an individual host no is it about a network security group know cuz we're asking about like um malicious activity against our tenant like the sign-in logs and then the rationale for its decision for GPT's decision for populating all these fields we can read oh that's difficult to read um oh here user reported tenantwide concerns about recent login sign logs contains Azure ADA signin events with IP location etc um last 24 uh 24-hour windows covers quote unquote last day or so. Fields chosen give who what, etc., etc. It it's just giving context as to why it um populated all these things. And we're going to dive into this like much more later, so don't worry about it too much.
Um, this function is sanitizing this thing to make sure that um all the fields are present and if they don't have a value they're just like an empty string. We'll we'll talk about this more later but it's just sanitizing the the object. So we step over this and then this is just going to simply display the query context to the user which it does. Log search parameters finalized. It's telling us, you know, this is the table. These are the fields. If we step over this, it's going to tell the rationale. This is the thing we just talked about. And then this is going to ensure that the table and fields returned by the model are actually allowed to be queried. And this is like what's called a guard rail. So, for example, um if for some reason um GPT came back and it was like, oh, okay, we need to look in like uh the alert info table or something and that's not an allowed table. We don't want to let our agent to do that. So, we have to specify guard rails. And this is just one of the guard rails. It's just making sure that the the table that was selected and then the fields within the table that were selected are okay. And we're going to dive into like all this like a lot eventually. So this is just a highle overview video. We step over this validating table and fields. The fields in the tables have been validated and complied with allowed guidelines. So that's cool. And then this next one um it's going to query our log analytics workspace. I I won't dive into this deeply yet. I'm just going to like go over it and just let it go. And it's querying a log analytics workspace right now. and query finished. It's going to count up the records here. Step over, print 818 records returned, and then if records are zero, it's going to exit. This is like, you know, poor messaging, but it's just one of the things that's wrong with it. And then this is going to actually like create um a big prompt that's going to chat GPT. Um, it's going to combine like the user message which was like I'm worried something's wrong. It's going to provide the table name like where to look as well as the actual full-on records. So, it's going to create this like big prompt. So, if we step over this and then this threat hunt user message, this message was created um by this function. So this is a this is a prompt basically. So threat hunt user message. I'll show you. So if we go to debug here, and by the way, I recommend watching this video like more than once. It's it's just one of those things you have to get a lot of exposure to before it starts to make sense. But I'm going to look what's inside of this threat hunt um threat hunt user message. So here, threat hunt user message. You can see here. And let me see if I can like copy this. I double clicked it. I'll try to copy it. I'll go to like a chatbt and then go ahead and log in if you're not logged in already. And I'll just like paste this in here. And you can see this is our our original request. I'm worried that someone logged in. This is our request right here. And then the thing that got appended based on the table you are threat hunting AI uh analyzing the sign-in logs. And then this is like an a whole other prompt that got added um to the our original request. This whole prompt um we'll look at all this later, but it's just basically saying like you're a sign in you're a threat hunter. You're going to look in the signin logs table XYZ. And then these are like all the actual logs like that huge thing of logs.
So going back going back to our program we step over this. This is the threat hunt system message. So this gives context for how we want chat GBT to be to behave. And when we're using the API, um, this was covered in like the building blocks where there's like a system message and then there's a I think it's called user message. I forget what it's called. Let me see. I think it's user message. Yeah. Where like the role is user and then the system message. The role is system. This gives context for how we want GPT to behave. So if we like copy this for example, threat hunt system message, we can see it here. Content. I'll just like copy this again. And if we go to GPT, I'll just like scroll to the very top of this. I I don't know if this is going to like work, but I just want to like paste it in here to show you what it looks like. This is like the system message. You're a cyber security threat hunting AI blah blah blah. Um, all the context for like what we want it to do and how we want it to do it. So basically we have our system message and we have our user message. And then it's going to combine these into another variable called a threat hunt messages object. So if we step over this, both of these things are in here. We have the system message and we have the user message. And then we're going to actually count up the tokens for this because there's like a limit to how many tokens we can send to chat GPT. If you can recall from like the token lesson and the building blocks, we step over this. Looks like there's about 120,000 tokens, which is like pretty decent amount. And then now based on the number of tokens, it's going to choose a model for us or at least give us the option to do that. So if we step over this, bunch of stuff happened down there. So if we scroll this up a bit, we see like these are the four models that we have defined like in our our guard rails or our our model management and we can see like um this is like the the input limit like how much tokens the model can take and then this is our rate limit based off of our tier. So, for example, um GPT5 mini and 4.1 have a a limit of um I think 200,000 tokens per minute. And then if we choose like GPD5, this theoretically should fail because it only has like three 30,000 tokens per minute, but our single request is like four times that amount. Um so it's showing up in red cuz it's like an an overage on the limit. And we can see the estimated costs here. Um if we use 4.1 nano cost 1 cent, GPT5 mini cost 3 cents and then you know respectively rather GPT5 is 16 cents. And you can kind of make sense of this. And this thing right here it's showing that we're we're current model is GPT5 mini cuz that was the default model. And if we just press enter, GPT5 Mini will will be used to execute this query. And you can see here um these are like the summary for GPT5 mini um where the input limit for the model it's within bounds and then the rate limit is also within bounds. So we can just we can say y even or we can say like enter and it will pick GPT5 mini by default. So I'll just do that and then it's going to validate the model. Make sure GPT5 mini is allowed the model that we selected. Valid. And then it's going to initiate the cognitive hunt. So this line it takes a time stamp of when the hunt started and then the hunt it will execute. So, we'll step over, step over, and then when this happens, it's going to send um so sorry, when this happens, it's going to send like the system prompt as well as the user prompt to chat GBT. uh as well as the model and it's going to do some analysis and it's going to come back to us. So if you remember I started pasting stuff in here. Um this is kind of kind of the equivalent to what's going to happen. So if I just like send this to chat GBT kind of equivalent to what's happening right now. But in our case like this is happening on the back end with the API. This big this big prompt got created and got sent to GPT. So, I'm just like doing it here just to see like, you know, compare the results of dumping it into the browser versus using the actual API. Just as a little side note, the browser itself has a system message already that it uses that we don't have access to, but I just went ahead and dumped our own system message in here anyway, just to see what would happen. So, it's actually doing the analysis and it's going to output um it's going to output the threat findings for us and it will probably look somewhat similar to what gets returned by our actual agent. But we'll see.
So, this thing it finished it looks like. So, if not hunt results, we're going to exit. But, it looks like there was something. So, we'll step over this, step over this, and then we're going to step over this. Cognitive hunt took this many seconds and found four potential threats. Step this says press enter or return to see results. So if we do that say enter and then uh it stepped to the next thing. So we have to actually step over this to see the results. And then it dumped all of the results to the screen. Um, not only did it dump them to the screen, it also recorded them inside of this threats.json L. So these last four right here, um, these were like here already. I think I like accidentally included them, but these last four here are the actual threats that were found. And we can actually see like a more human readable version of this. Um, if we scroll up a bit on the command line. little threat number one. I'm not going to like go into these too deeply because your yours are very like for sure they're going to be different because your thing used different logs and LLMs are different like etc. But we can just kind of look through these. Uh impossible travel likely session token reuse um cuz somebody logged in from like Perth in Australia and then Toronto within 5 minutes somehow. These are real by the way. Impossible travel mixed location and short time short time period. Seattle and Taipei. Um, I can guess actually probably who this was. But, uh, repeated invalid password failures followed by success. So, this may be potential brute forcing happening against the tenant and then multiple rapid authentication failures for a service account. Oh, that's interesting. Actually, I don't know what this is, but these are all real real findings. So, if you're curious, we can go back and look at um GPT. This is interesting because it's still like doing analysis. This is why I I think like the GPT maybe GPT5 is like gone by the time you're watching this. like I don't know but this it's possible that I feel like GPT5 or rather when you use GPT in the browser it's like switching models and stuff on the back end like doing something weird and trying to figure figure out like which model is best to use cuz this is taking like way too long to be honest. But I'm just going to like click on this. I I assume this is still going. I'm just going to like let it go. So, whoever's editing this, um, go ahead and like obviously speed this up or cut it out. taking like quite some time. Anyway, this is taking forever. I I'm assuming it's like not going to work. Uh so anyway, that's that that's the thing. Uh I'll I'll go ahead and like run this through one more time, but I'm not going to debug it. You can spend a lot of time doing this if you want, like debugging it and everything. I'm just going to do it like one more time. this time. See, I'll run without debugging. So, aentic sock analyst at your service, what would you like to do? Um, so this time I'm actually going to query rather I'm going to look at some like brute force login against the virtual machine, but I'm going to see like which VM has kind of the most activity in the last day or so. So I'm going to go to like this is like the log analytics workspace for the cyber brain. So I'll go to device lo on events and I'll say like um I'll say count equal and I'll say what am I what am I doing summarize count equals count by uh be device name order by account descending. I just want to see like which computers I guess have the most u activity. So, looks like this person's this person's virtual machine has like a lot of login attempts. So, I'll like copy this and I'll go back here and I'll say um I'm a bit worried one of our workstations has been compromised. It has been exposed to the internet for the past few days. This is the workstation ID. Uh well, no workstation name. And good thing I put that at the end because it's just like X. there's like a return character and it executed right away. So, oh, this is actually like not what I wanted. So, this is like this is a problem. Um, I wanted to look in the device loon events table, but you notice it like chose device network events. This is like an issue with um somewhere in prompt management in Yeah, it's an issue with prompt management. we have to like provide enough context in our environment for the agent to know like where to look properly. So I'm just going to like stop this and I'm going to like uh control C it and I'll I'll do it again. But this is something we have to like fix later. So I'll say start debugging. I'll just debug it and I want to I'll try to word it better this time. Uh I'm going to kill that. Say continue. talking at your service. What What would you like to do? I'm going to say um I think Oh my god. I think someone may have logged into one of our workstations um illegally like a hacker a hacker or something. This is the workstation name. I don't know when it happened. Maybe at least a day or so ago. A lot of typos in here, but that's okay.
So, I I kind of had to like handhold it a bit with my prompt to let it know that oh, I'm talking about device loans. So, see now it picked device loon events. This is what I wanted. um before it should have been able to derive it before, but it's because our our prompt and stuff is like not quite good enough. It chose the wrong table basically. There's a lot of problems with this, but we're going to like observe those and like fix try to fix a lot of them. So, take a look at what it did. Um fields and tables were verified. This is the table it chose, which is kind of what I wanted. And there's a lot of records. Uh 2100 records. And then this is like our stuff. So this query will cost 3 cents if we let it go. And then it's within bounds GPT5 mini. So we can say I'll just say yes this time and say enter. Notice it's taking like quite a bit of time cuz we sent like 100,000 tokens to it. It just takes time. Took a minute. Um GPT4.1 is quite a bit faster, I believe, but it's like not as good. Well, it's pretty good, but okay. I'll say enter. And then it's going to dump all the findings to the screen. I I won't go through these in too much depth. Um maybe I'll just like scroll through them a bit so you can see them if you want to. Let me do this to see. Years are no doubt going to be different. Of course, different time frame, different logs. And I do want to try something. Um I want to try to do an overage. See what happens. So I'll show you what I mean by that. So I'll run this code. Uh I'll just Yeah, I have no break points, but I'll debug it and then I'll use the same prompt. So let me go and get that. Here's the prompt. So, I'll copy this. God, can I do that? Yes. So, I'll paste [music] this. So, and then when it gets to the part where it's asking about the model, I'm going to try to choose one of the models um where the rate limit is like way too low for the amount of tokens we're sending to it. and just to kind of observe what happens. And I'll show you like one more thing um after that and then we'll we'll end this lesson. So it's collecting the logs, it's quering log analytics. So oh these are these are all over. Oh interesting. Okay. Okay. Let's see like what why that happened actually. Okay, this is like another problem. You see like um even though even though I specified the device name, it it failed to like insert it in here. Um this is again a problem with the prompting. Um like last time, you know, LLM will like return something different to you every time. the prompt is like not like the system prompt that we used to like uh help it decide what to make the KQL query be it it was like too it was too weak I guess um so this time it it couldn't derive the device name even though we specified it here I'm pretty sure I I'm pretty sure I specified it let me see let me make Oh, something happened to the prompt. That's why that's why it failed to do that. Um, but anyway, for you, okay, for you, for example, let me like stop this. I want to make sure that like the thing gets um tries to get too many logs for us to query. So, let's let's do this. Um, actually, that's probably fine. I'm I'm just going to like start debugging this again. I'm likely going to cut a lot of this out. So, just like, you know, do your best and I'll put it in frame and I'll say where to cut it out. But, okay. So, we're going to say like um I think Oh my god. I think someone has been logging into some of our VMs illegally in the last day or so. Can you take a look and see what you can find? Lots of typos. But notice I didn't specify a virtual machine name in here. I just said someone's been like, you know, logging into our virtual machines. And so the model um it's going to use its like brain um and a lot of the context we've provided it. We haven't really talked about that too much, but it's going to decide like where to look based on our prompt. And it basically decided to look in the device login events table, but it this is like really sloppy prompt, really sloppy KQL on my part, but it's one of the things that's wrong with it. But basically you notice that um it basically you notice it's saying like all computers like something that starts with empty string. This means all computers. So it basically looked like all virtual machines like login failures in the last 24 hours which is a substantial amount of records. As you can see like 68,000 almost 7,000 records were returned. um which ended up being like 300 like 341,000 tokens, right? So for GPT5 Mini, this is actually perfect. Um so the the token window maximum input for GBT5 mini is 272,000. It's obviously over and then the rate [snorts] limit of 20,000 or 200K. It's obviously over that as well. So I'll try to run this um just to like see what happens rather I'll try to run it with like GPT 4.1 because the input limit is within range um but the rate limit is like 10 times over. So when it's asking like which model I want to use um I'm just going to say like GPT um I'll just say GPT 4.1 this one. So, I'll say enter. And it warned me. It's like over the limit. Continue. We can say enter to continue. And then it's just going to like do its best. Input max GPT4.1's tokens per minute rate limit. I should probably like have better messaging here, but it's trying to do the threat hunt. Um I'll be surprised this token limit um the rate limit is like really like wishy-washy cuz sometimes it will just like let you do it for some reason if it's a single query but sometimes it like won't. But we'll see like what happens but the the actual model input limit is like really strict. See, it like let us do it anyway, even though the token limit is like Okay, so it found five. It found five threats. We'll say enter. I'll let these dump to the screen. I'm not going to like look at them, but I'll run this one more time. Start debugging. Someone logged into some VMs in our environment in the last day or so. I'm not sure which VM. Can you check things out? See if you find any IOC's. So this time I'm going to it's going to return too many logs and I'm going to choose a model where the actual like input can't can't take that many tokens. So GPT5 mini it's failing on the input limit and it's also failing on the rate limit as well. So um we're just gonna like let it go. This is some bad messaging. I need to fix that. So, I'll say enter. Okay. And then we got an error. Uh an un I think no this error was caught, but it just printed to the screen. Um input tokens exceeded the configure limit of you know 272,000 message resulted in 342. Please reduce the length of the message and it just like exits. So this is another problem like letting it attempt to query something or letting it attempt to send too many pro tokens is okay but you know the program just like crashed like this in the end and it just like finished and then now our command line is red. So this is like another another issue. So I just wanted to like show show you this. We didn't dive like too deep into anything. Oh yeah, I'm going to actually let me run this one more time. I'm just going to show you something really quick. So, we'll start debugging again and then I'll I'll break this uh maybe here. I just want to show you that you can like step into the function. So, if you want to like we didn't do like a really deep dive into like what all this stuff is doing yet. We're going to do those in subsequent lessons, but if you want to do it like ahead of time, we've just been stepping over everything. But if you like uh step into for example actually let me let me rebre this here. So if you want to step into things on your own and see what they're doing. So for example I broke this I broke the code here. If we say step into instead of step over it will actually go into this module and you can see like the stuff it's doing. So step into oh I guess I guess it only does that for functions. So for example for this one if we say step into it actually goes into the prompt management uh module and then you can step into like so you can observe each line of code someone logged into something they weren't supposed to. And you can do like so you can see it's building the prompt. It's returning it. And then instead of stepping over, you can step into with get log query from agent. You can step into and you can see like all the stuff that's happening. So I'm not going to explain stuff. I'm just like showing you that you can do it. So, and then if again if you want to step over it, you can say step over and it will just do it will just do that stuff in the background and go to the next one. But if you want to like step into it, you know, display query context, uh, that dumps the thing to the screen. So, I'll step over this one. You can see it just dumps it. Display query context rationale. If you want to actually like step into this and see what the function is doing, you can do that. So, like so. So, yeah, I'm going to end this. Yeah, that's the introduction to our our baseline agent. You saw some issues with it. Um the next video um before we like do like deep dive into into the individual components, I'm going to talk about some of like the main things that are like I'm saying like too much. So the next video I'm going to talk about some of the main things that are really wrong with this. We saw a few of them already in this. Um but I'm going to like point a lot of them out and then we'll probably end up fixing a lot of those along the way. Uh but yeah, look forward to that and we will see you in the next video. Oh yeah, as always, if you get stuck, have questions, I know this is a lot. I recommend re-watching this many times and stepping through it and just doing your best to understand it. Um, but yeah, if you get stuck, go to the community, make a post, tag me, and we will see you in the next lesson. Cool.
Welcome back. Uh, this lesson is going to be somewhat complex and maybe even a bit long, so just do your best to pay attention. I I definitely recommend watching this more than once. Um, it's probably one of the more difficult lessons um I I would guess. But if you get stuck, just go to the forum um to the community, leave a post, tag me, um set the category as uh you know, cyber security AI and we'll we'll like get through it eventually. But basically uh in this lesson, we're going to cover a specific part of the Agentic AI workflow. Specifically um we're going to figure out how to take this um you know when the agent starts it's like what I'm
At your service. What would you like to do?
And then you, you give it this human-readable thing, like, "I'm worried that somebody logged into Windows Target One." So, basically, the whole point of this lesson is we're going to figure out, like, how to go from this human-readable thing into having the agent output this structured data that we can use to actually query Log Analytics and do some kind of agentic remediation in the end. So, basically, we're figuring out how to go from this input, like, "I'm worried about Windows Target One," to getting this structured output around it.
So, the idea is we tell the agent this, it does something with GPT, and then it derives all of this information about it. So, based on this query, for example, it decided to, "Okay, I need to look in the device login events table. Okay, I need to look in the last 72, 72 hours because the user said 'last few days.' Okay, I need to look in these fields, um, specifically for this device because they mentioned it here. And then, okay, it's like not about, uh, a user specifically. It is about a host. It's not necessarily about a network security group." And then this is all the rationale for this structured data that the model came up with.
And as a reminder, we, this is like the, the flow of the agent, right? Like, one full, like, run-through when we tell it what we want, all the way down to when it outputs all the threats it found. So, we basically, I know this is hard to read, but it, it's okay. Um, you don't have to read it, but basically, in one full flow, we interact with ChatGPT or like the, I guess, the ChatGPT API two times. The first time is to actually figure out what the user wants and figure out, like, how to derive structured data from their human English sentence. So, the first time we feed ChatGPT, like, their English sentence, and it dumps out a bunch of stuff, like the table, the fields, um, is it a user, like, etc., all those, like, structured data it dumps out. And then we use that to query Log Analytics workspace and we get all of the logs that we then use to threat hunt down here. And then the results are displayed, and then we can go on to do, like, a remediation in the future. So, GPT is interacted with twice. First time to, like, get those structured data. Second time to actually do the threat hunt after the logs are gathered.
So, in this lesson, again, we're just going to cover getting the user data and then how it gets transformed into this structured data. And then we're going to, we're going to basically stop there. Uh, and then we're going to, um, you know, figure, we're going to deep dive on other parts of the agentic workflow later. So, that's what we're covering in this lesson.
So, I'm, I'm going to include some source code for this. Um, I just want to make sure we're all using the same code all the time. So, go ahead and download it. Uh, I'll put a link in the description below. Uh, it's going to look something like this. So, just download it and then just say whether or not you're using Mac or whatever, just extract it and unzip it to your desktop. And then we will open it up. So, I'll actually close this and reopen it so you can see it. Oops.
So, if your folder is closed, you can go to Explorer. You can say "Open Folder" and then go to, you know, wherever you unzipped it. Mine is on the desktop, and then this is mine. So, we'll open it. And then before we run this, let's, um, make sure that you have your API key. So, if my API key is in here, like, don't try to use it because I probably deleted it. Um, so just go ahead and make sure your key is in here. So, you can get your own API key from here. I put, like, a link here. So, I will paste mine.
And then also, before we get started, um, you want to make sure that you're logged into a login as well. So, go ahead and open a command line. So, click the Start menu, or if you're on Mac, go to Terminal. And then `cmd` and then a space `login` and then you will, like, select your account and enter your password if you need to. You might be already logged in, but I just want to make sure. Press Enter to select the subscription, and we should be good to go.
Okay, so now, uh, go ahead and open up `main.py`, and we're going to step through this one time, uh, at kind of a high level, and then we're going to do more of a deep dive and see exactly what everything is. So, we will, uh, I'll break this here, um, on this unformatted query context where we're actually, like, getting the query context. That's, like, the main thing that we're doing in this lesson. And then I'll, I'll break it again here where, where we display the query context. And then I'll break, I'll break it again here before we actually query Log Analytics. Um, because I, I don't, I don't want to do that for this lesson. We're just, again, we're just figuring out how to go from this to this, like, how that works. Cool.
And again, it's going to be a bit complicated. Um, just watch all the way through, re-watch it, and do our best. So, I'm going to break this, and I'll say "Run and Debug Python File." And I'm actually going to use this query. Um, I recommend you do it, too, just so we can kind of have something similar going on. So, I'll copy this right here. "I'm worried. My god, I'm worried. Windows Target One," etc. So, I'll just paste this here. Windows Target One. Uh, this is a Cyberrange virtual machine. It's always on, and it's always getting attacked, just FYI. So, I'll say Enter.
And you can see the code broke again right away. So, I will, um, I'll step into this. We can examine that function. And by the way, this, it broke here, and this `get_query_context` function, this function is inside of the `executor` module. So, if we go to Explorer here, you can see the `executor` module here. You double-click it, and then you see this `get_query_context` function in here. So, this is what's running, and this function, this is what produces this, or it gathers this data, and that's this point right here, `get_query_context`. So, we got the message from the user, "I'm worried about Windows Target One," and this is about to execute.
So, if we step into, and then we'll, we'll explain this in depth in just a moment, but it's retrieving the system prompt from the `prompt_management` module over here, which is this. We'll talk about that in a second. So, it retrieved the prompt, and then now it's going to, um, do the API call to the ChatGPT API. It's going to pass in the GPT-5 mini model, the system message, the user message, which is "I'm worried about Windows Target One." Um, this thing is what is actually responsible for making this structured data, but we'll talk about that in a second. And then `tool_choice`, we'll talk about that soon. So, I'll just let, let this execute for now. I'm just going to let this run, right? So, this, this is happening right now. It's asking GPT, which is why it's taking...
So, the call finished. So, we can step into, step, step return. So, it retrieved the query context. It's going to clean it up, so we can step over. And then this is where it will dump it to the screen. So, I'll bring this up. I'll step over this, and we see it dumped all of those metadata and query context to the screen. So, we said, "I'm worried about, I'm worried about Windows Target One. I think someone logged into it in the last few days." And then it decided, "Okay, device login events table, time range 72 hours, which is 3 days because we said 'last few days,' picked it, picked out the device name from here. It decided it was not about a user. It decided it was about a host. It decided it wasn't necessarily about an NSG." And then this is the whole rationale for everything else up here that it, that it chose. And then the script, um, is just, we'll check the guardrails, and then the Log Analytics workspace will be queried, um, with the metadata that was retrieved. But I'm just going to stop this for now.
So, we're going to run this one more time. Um, but we're going to dive a bit deeper into this section here where it's actually querying GPT, and we're going to figure out, like, what the system prompt is and what the tools are, because these two things are what actually make, make it able to extract all of this particular metadata simply based on our, our easy, you know, one-liner up here.
So, go back to `main`, and we'll run and we'll start debugging one more time. I'm going to use the same query. "I'm a bit worried about Windows Target One." I'll copy this. "Agent SOC Analyst at your service. What do you want to do?" I'll paste this. Say Enter. Broke here. I'm going to, uh, step into this. And then this is where the magic is happening, I guess we can say. We step into, and then the first thing we're going to look at, because remember, um, so this right here is this first part. We're interacting with GPT where we're trying to figure out, we're trying to derive the table, uh, the fields, etc., based on the user's request. So, that's what this is. It's important.
So, we're going to send, like, a system message and a user message as well inside of the `messages` parameter, um, as well as `tools` quote-unquote tools. We haven't learned that yet. And then the `tool_choice` required. So, first things first, it's going to retrieve the system prompt `tool_selection` variable. And we're going to use that as a system message. So, this system prompt `tool_selection` variable, I'll copy this. It's inside the `prompt_management` module. So, if we go to Explorer and then the `prompt_management` module and then it's right here, `tools_selection`. So, this is basically just a prompt. Um, so if you recall when you, I'm going to go back to the `executor`, when you interact with ChatGPT, you have the option to send it what's called a system message and a user message. And you'll remember we talked about this a couple times before. The system message is just giving ChatGPT context for what you want it to do and like how you want it to act. Like, this would be like, "You're a baker, you know, speak like you're living in France as a French baker or something." Something like this. And then the actual user message is what you want it to do. So, this would be like, uh, "Tell me how to bake the best cake for a 10-year-old's birthday party." Something like this.
So, in our case, our system message is this: "You're part of a, you're part of a tools function call. Your purpose is to take actual, your purpose is to take natural threat hunt-related human language from a human SOC analyst and figure out which tables to investigate, as well as figure out, uh, what the request concern is about. Is it user account related, device host related, firewall NSG related, etc.? You will need to be prepared to provide a rationale for your assessment as well." I can just, like, for fun, I'll add this as well.
And then "Tool usage contract. This is important. You may call exactly, uh, one tool. This will require, um, a lot of explaining, but you can actually have, um, you can actually have multiple tools, but we only have one. I'll, I'll show you what that is in a second. You must return a JSON object that includes every parameter defined by the tool schema, which will be provided later. When a value is unknown or not applicable, set it to an empty string, false for booleans, or empty, or an empty array for arrays. Never omit parameters. Only request fields only request fields listed for each table in the tool description."
Okay, so this is, like, this might not make that much sense yet, but it will make more sense when we actually see what the tools are. So, this is the system prompt `tool_selection`. So, back in the `executor`, we step, we have our system message. Now, here, this is how the system message is structured. It's just a JSON object that looks like this: `{"system": {"content": "..."}}`. And then that, that big thing we just read. And then this is the, the function that actually calls, that makes the API call to ChatGPT. And then to try to get the structured data, it, we're passing it, or we're using, like, the, the `model` parameter, the `messages` parameter, `tools` parameter, and `tool_choice`.
So, the `model` parameter, we're using ChatGPT-5 mini. The `messages`, we're using the system message, that thing that we just read inside of the `prompt_management`, as well as the user message, which is, you know, our original message. And then we're using this, this thing is what actually makes all of the structured data and tells it, lets ChatGPT know, like, what to return and what a bunch of stuff is. It just gives it a bunch of context and allows it to return stuff that makes sense. So, this is inside the `prompt_management` module, which is here, inside of the `tools` variable. So, we double-click `prompt_management`. There will be a `tools` variable here. And it's a bit complicated, but I'll try to, um, maybe explain this in reverse. It might make more sense.
So, let me, I'm going to collapse, uh, `properties` and I will collapse `description` as well. And so, basically, this, this `tools` thing, we're giving this to ChatGPT, and basically, you can, you can kind of think about it, you can kind of think about this as we're giving ChatGPT, uh, an empty, a form, like a piece of paper, you know, a form, and then it has, like, some blank areas to fill in. It has, like, `table_name`, `device_name`, uh, `time_range_hours`, `field_caller`, etc. And it's required to put something in every one of these, uh, fields, I guess we can say. Or if you imagine a piece of paper, you know, a form where you fill something in, it's required to put something in each one of these, right? It, it has to put something in each one of these. And then this `properties` one, it gives it some kind of, like, information about which, each field means. So, for example, `table_name`, like, um, "Log Analytics table to query," for example, `device_process_events`, etc. And then in the `device_name` field, this is going to be a string, and this was, like, the name of the device to filter, for example, `user_pc1`, the `caller`, etc., etc. And then, for example, they all, they all correspond to stuff here.
So, for example, this `about_individual_user`, which is here, this is just whether or not the query was about an individual user account, and it's a boolean. So, that means that GPT needs to either say, like, true or false for this. This `about_individual_host`, um, this means, like, the query is about an individual host, server, or client, and you need to put either true or false for here. And same thing with this one, `about_nsg`, you put true or false. And then `rationale`, this is a string. "Your rationale for choosing the properties that you did." Basically, it just means "explain yourself," essentially.
And if we scroll up, um, if we look in this `description`, this is more, the description just gives GPT more context for the, the different fields and properties and stuff that we're working with and what we want it to do. So, if we expand this, so, for example, if you remember our query is, "I'm a bit worried that Windows Target One might have been maliciously logged into in the last few days." It, it will give GPT context for, um, which tables exist and then what the different stuff the tables have in them. So, for example, if I, if I just make things easier for us and jump straight to here, this one has, like, "Login activity against one or more servers or workstations." So, when GPT looks at this, it's, it's like, "Oh, okay, um, for, for `table_name`, this one makes the most sense because the user query was like, 'somebody logged in last few days,' they're worried. This table contains login activity, so this must be the one that I need." And then when deciding which fields to return, we gave it context. And by the way, this object here is just something I, I built and put it together. It takes some time to do, but this is how you give GPT or your agent context into what your environment is like.
So, these `fields`, this tells the agent, like, which fields to select based on the table that was selected. So, `device_login_events`, these are the fields that it should be returning, etc. And it's, I just added a bit more stuff here to give it some context to help it out. I won't read all of these in depth, but basically, like, um, if a username is mentioned, like, in the, the user prompt, assume this is `user_principal_name`, which is a field in one of the, the tables. If the query belongs to the `device_signin` table or the, the `signin` logs table. If a network, if network activity is being questioned for a specific host, this is likely to be found in the `device_network_events` table. So, if I said something like, "I'm worried about malicious network activity coming from Windows Target One," probably, uh, this table would have been selected instead. So, this, this is just a bunch more context to help GPT decide, uh, which table to pick, which fields to pick, etc.
And then these `parameters`/`properties`, this is more context for it because we remember we're telling GPT, "You need to return all of this stuff simply based on this." Oh my god, what the heck? Simply based on this, you need to return this information. And then it learns, like, what this information is from the `properties` here. And then this `description` here provides, provides even more context. So, that's what `tools` is.
So, if we go back to `executor`, we're telling, um, we're giving it a bunch of context, like the system message, like how to behave. We're giving it a bunch of context. So, the system message, like how to behave. The user message, what we want to, what we, what we're worried about, right? And then the `tools`, which is exactly, like, it's basically that blank form, like, "You need to fill in this form. You need to put something for a device, put something for a table, etc." We're giving it the `tools`, um, so it can fill those out and return it to us. And then if we say `tool_choice: "auto"`, I believe it will, it won't return all of them or something like this. Or it, it won't. Okay. It, it won't, um, if we say something weird to it that's like not related to threat hunting or something. Oh my gosh.
So, if we, if we say something that it's not related to threat hunting, it, it won't return anything. Um, because you're, you're allowed to have, like, more than one thing in here. So, you'll notice this `tools` thing. This is actually an array or like a list, and there's like a single function inside of here. We only have one. So, basically, the `tool_choice`, it, there's only one tool to choose from in our instance. Like, so far, we're probably going to add a new one in the future, but there's only one to choose from. So, if we say `required`, it will always choose this, this thing here. Um, but if we say, like, `tool_choice: "auto"`, we can say `auto`. Um, and if we say, if the prompt is something like, um, "What is the best, like, what is the best handbag for my girlfriend or something like this?" It's going to look at these tools and it's going to, it's going to read the description and it's not going to see anything about, like, handbags or girlfriends, and then it's just going to return, like, nothing, right? Um, but for our intents and purposes, I'm just going to, like, force it to return something, or I'm going to force it to use, um, this, this tool/this function. So, that's what that is.
So, this is basically just a bunch of context, the model we want to use, a bunch of context for what we want to do and what we want it to return, and then giving it the ability to decide whether or not to use one of the functions. So, I'll just step through this as usual, and it returned a bunch of stuff. And by the way, you can always, like, click on this debug thing and expand this and then collapse these things, and you can see this stuff over here. So, for example, this, like, `args`, now it has, like, it has all the stuff that got returned from ChatGPT, the tool call. You can see it. We step, step, and I'll step over this, and then it's going to display our query context, all the stuff that got returned from GPT using the tools, like so.
So, I will, um, uh, I will end this and I'll do one more query. So, I will, let me see here. I'm going to open the, I think I can, I'm going to get my particular username. I think I can just, like, copy this. Can I? Am I, like, not allowed to? I, I want to copy my username so I can, like, use it. Okay. So, I'll copy this. I'm not sure, like, if how well this will work, but I'm just going to, like, try it anyway. So, I'll go back here and I'm going to run this. I'll go to `main` and I'll run this one more time. Start debugging, and I will say, "I'm a, Oh my god, I'm a bit worried that one of our users, uh, is working remote illegally using a VPN or something from another country. Uh, their username is, uh, I, I'll just use my normal, uh, no, I'll use this at loginific.com." Wait.
Okay, I'm not, I'm not sure how well this will work because our, our agent is like not really fine-tuned, but I'm just going to, like, see what happens, right? So, um, yeah, I'll just let this go. I'll just step, step. I'll step out. I, I'll let it go and see what happens. I'm, I'm slightly worried because that name is like really long and obscure, and but maybe, maybe it works. We'll see. It should. We'll step over this query context. Display query context.
Oh, interesting. So, um, it, it decided to look in `signinlogs`, which is correct. And for the time range, it chose a week because I don't think I actually specified anything about it. And by the way, you can control this. Like, I didn't say to, like, look in the last 3 days. I didn't say anything about the time, but it chose a week by default. But this is where you could go. You can go into, like, um, um, `prompt_management`. And you can go into, I think it is, this is the system prompt for the tools call. And you can say something in here like, um, "If, if no time frame is specified specified by the user, choose 4 days, 96 hours." You can do something like this. This is giving context and kind of guiding it to do what you want, for example.
Um, but, um, it chose `signinlogs`, chose the tables, it decided that it, it was user-related, um, not host-related, not NSG-related, and then this is the rationale for it, or the rationale that was, um, that it provided. So, let me see the query context. Oh, I, I need to, like, edit this so it actually prints the user principal name because you notice it's not printing the name out because I didn't, like, let it to do that actually. So, um, I'll, I'll fix that now actually. Let me stop this. And by the time you get this code, it should be fixed. So, I think this is in the `utilities` module, and it is. So, we can say `device_name`. Okay. `caller`. So, I'm, I'm just going to copy this and I'll leave this in here because it's like good practice. I think if, if I think user, I think it's this `user_principal_name`, not `blink`. `user`. Think I can do this. Leave. Nope. Let me just, like, try to run this one more time. If this breaks, I'll, like, have my editor, like, cut it out.
So, I'm going to, I'm just going to, I'm going to use the same prompt again. So, you can use, you, you can use your own, uh, what's it called? Your own username if you want. Just make sure you're typing it correct. And remember, this chose a week because I didn't specify any kind of time range. But I, I actually changed the, uh, system prompt to say 4 days if no time range is specified. So, I'll try that out now actually and see if that works. And what is this thing doing? I'm going to stop this and I will run it. Go back to `main` and run this one more time.
"What would you like to do?" "A bit worried that this person," etc. So, I will, what is going on? Okay. Okay. I'll step over this. I might have to adjust, um, the query context a bit. It might be, like, out of line, but we'll, we'll see. Query context, step, display query context.
Okay, it did. So, here I need to bring this, uh, forward by, let's see, one, two, two. Okay, user. Okay, I need to bring it forward by two. So, I'll go to `utilities`. Okay. So, we can see I'm going to collapse this a bit. And actually, this is like really good. Um, you can see `signinlogs`, and you can see this, the time range is now 96 hours because of this. And then, uh, we see the, the fields it decided, `signinlogs`, which is correct. Um, the user, which is correct, it pulled it from my prompt. Oh, what the heck is this? I didn't even do the whole prompt. I just put this, and it, it was smart enough to pick this out. That's that's interesting. Um, that's interesting. So, it did, it did decide that it was user-related. Wow. Um, host-related? No. NSG-related? No.
Let me, let me actually, like, run this one more time. That was really bizarre. I, I guess I miscopied that. Copy this, and then I will restart this because I, I straightened up the, um, the output of that thing. So, I just want to make sure it's straight. See how this is like not straight? Um, I tried to straighten it up in the last edit. So, "What do you want to do?" "I'm a bit worried about this user." So, we [snorts] will, uh, step over this and we'll let the query go. I'm actually going to let this threat hunt go all the way through so we can see, uh, you know, what it comes up with, and then we'll end the lesson. Uh, I'm going to talk a bit more. Um, but yeah, so query context. Got it. Display it and see how these are now in line. `caller`, `username`, `caller`. The `caller` is the same as the `username` depending on the table that you're working with. Um, you, you can look inside of the, the `prompt_management` inside of the `tools` to, to kind of see more about that. So, for example, `caller`, I think I talk about it in here a bit. I give it context for, like, what `caller` is. Bam. Guardrails. I, I'll just, like, let this go. I'll, like, play this. Continue.
And 16 records are returned, um, for my specific user in the last 4 days. This is the KQL query it came up with. Only 16 records. Really, really minimal. Really extremely cheap analysis on this one. Way under the limit. So, we can say Enter, doing the threat hunt. I don't know if it's going to actually find anything. I don't use that account that much, but there might be some impossible travel potentially, but I'm not, I'm not sure. We'll see if it, what it comes up with, though. Found two potential threats after 45 seconds. Let's take a look. I don't think there'll be a red one. I don't sus Oh, there is. Uh, no evidence. So, this is, this is interesting. Um, no evidence for foreign VPN sign-ins. All activity from single use, uh, location, which is, this is the virtual machine's IP address, in confidence level high. So, this is actually, this is interesting. Um, this, the actual, um, threat hunt prompt needs to be adjusted. This is outside of the scope for this lesson, but you'll see it says, like, "Confidence level high," but this, these are supposed to be threats, but it's actually saying, like, um, that everything is okay, I believe. It's saying everything is okay. Confidence level high, but this, this might be, like, kind of perceived as a threat. So, a better user experience would not, would be to, like, not have this show up in here, and then maybe have the agent come back and return something like, "Oh, there was, like, no findings," or something like this, because this, this appears as if a threat happened, and it's, like, really high confidence level. But I don't think that's the case. There are multiple successful logins from the same IP. But this is, like, a good thing, right? It means the, the user is, like, not abroad. And then indicators of compromise. These are, like, not actually compromised. These are just, like, evidence that the user is, you know, where they're supposed to be, etc. But it, it found something, and it was able to do analysis nonetheless. So, I mean, that's kind of cool. And then what's this medium one? Um, I'm not going to read this. This is a lot of, like, text, but you can, you can read it if you want. No doubt yours is, yours is going to be different than this obviously because, you know, you're going to be running this at a different time against a different user. But, um, that's pretty much all I wanted to show. Um, you can, you can really, like, control the way the agent behaves and what kind of information is returned, etc., um, based on this `tools` prompt. So, you can try based on both, both the `tools` prompt as well as the system prompt that's being used for the initial, for the initial, like, what am I saying, for this, when we're trying to derive the metadata and those structured data from the user query. So, if you, if you want, I would recommend you kind of, like, adjust this system prompt `tool_selection` prompt a bit, like, the, the content section of it. You can say, like, all kind of ridiculous stuff in here. I don't want to mess it up too much because I'm going to, like, actually package this code and let you use it in the lesson. But I would recommend, um, playing with this a bit, like, the system prompt as well as the `tools`, because you'll notice, like, you'll notice, uh, for example, there's a bunch of tables up here, for instance, but the `device_registry`, like, `device_registry_events` table, but I actually didn't, um, I didn't actually specify the fields for the registry events to be returned. And there's also, well, there's, I don't want to get ahead of myself, like, too much, but basically, there, there's a lot you can, you can do in here, and I didn't include all of the tables, and I, I didn't include all the fields for all the tables, and I gave it, like, all kinds of, like, hints and, like, tips and stuff, like how to, um, like, hints for how to structure and return the data. So, I would just recommend playing with this a bit and trying to get a good understanding and a good intuition for, um, how this works, and just try to make it make sense and help it to be more intuitive.
But yeah, that's, uh, I don't even know what to call this lesson to be honest. I forget what I called it. Um, what is this? Query context, I think, like, "Get, getting query context." But yeah, that's, that's using, uh, tools, uh, in the with the GPT API endpoint. And again, as a recap, basically, we ask GPT a question. We interact with, or sorry, we ask the agent a question, and then the agent will interact with ChatGPT to get more context about what the user actually wants to do and what to query. It will respond. We'll take that information. We'll query Log Analytics workspace with a structured KQL query. We'll get a bunch of logs, and then that's what we use to actually do the threat hunt. But in this lesson, we just got the input from the user. We, and we derived that structured data, um, based off those plain English from the user. And I know this is, like, a bit complicated, and I don't even know, like, what to call some of this stuff to be honest, because it's, like, kind of new to me. But if you get stuck, or if it doesn't make sense, or you find some mistake or something I, I did, definitely go to the community and make a post, uh, let us know. Uh, try to get my attention. I'll do my best, and then we will see you in the next lesson.
Welcome back. In this lesson, we're going to cover, uh, guardrails, or what are called guardrails for agentic AI. And guardrails, um, they're just basically rules and safety checks that guide AI systems to act responsibly, ensure their decisions stay aligned with human goals, values, and safety limits, including, uh, cost. So, it's just basically that something, something that's put in place to make sure the agent doesn't do something like really wild that causes a lot of damage or causes you to lose a lot of money for some reason.
And basically, um, the way the agent, I'm going to cover this, like, diagram, like, really quick, and then we're going to dive into the code and and talk about the guardrails that we have in place a bit more. But I just want to talk about this a bit. So, currently, we're, we're basically, like, running this code, the agentic AI agent code, on our local computer or our VM or whatever the case may be for you. Um, so we, we can, like, go to the code and directly change it because we're the engineer, like, we're the one who's developing the agent, right? We can just interact with it directly. But in a normal situation, or the real world, the, the user of the agent is probably going to be, like, some L1 SOC analyst who didn't engineer the agent and who doesn't have direct access to the code to do stuff. So, normally, maybe the, the agent is going to be, like, at their house or something like this, and they're just going to be, or sorry, normally the SOC, the SOC analyst, or, you know, the human, is going to be at their house or in the office or something like this, and they're going to be using the agent through some kind of interface. It might be, like, a web app, or it might be, it could be the command line, but it, it might be they might be using it remotely or something. It's not like they're going to have the raw Python on their computer where they can edit the code and stuff.
So, why this is related to guardrails, like, the guardrails are are built into the back end and, like, built into the code. So, when the user is interacting with it, um, they can't just, like, edit the guardrails and, like, get around them or whatever. They're going to be, like, put in place in a way that's not accessible to the user, and then the user will be interacting with the agent, and then the agent will be able to, like, do stuff on its own. Um, but there'll be guardrails, uh, in place that prevent it from doing certain things. And it, again, it's not like the scenario where you can just go and, like, change the guardrails because it's, it's protected on the back end in some way, shape, or form. We're just running the code locally on our computer, and we can, like, change it and, like, manipulate the guardrails at will. So, it doesn't seem that safe, but that's because we're the ones, like, having the code in our hands, if that makes sense.
So, the guardrails, they're just in place. We're going to show, I'm going to show you exactly, like, what they are and some guardrails that are missing, but they're just in place to prevent the agent from, like, running wild and spending a lot of money or doing something that it's not supposed to do. So, talking about guardrails a bit, um, that we actually have in our code. We're going to run the code and inspect them, but we basically have, uh, a table allow list. So, when you're querying, uh, Log Analytics for, like, `device_network_events`, `device_login_events`, etc., we have an allowed table list. So, if the agent tries to query another table for whatever reason, it won't be allowed to. We also have a field allow list. So, for example, uh, all the tables, let's see if I can, one moment. You can just, like, edit this out. I, I'll, like, tell you when to start recording again. I should have opened this ahead of time. Damn.
And then we also have a field allow list. So, for example, uh, this is the `device_login_events` table, right? And then these are all the different fields in the table. So, if the agent tries to return some random field that's not defined in our, uh, guardrail, it, it won't let it. It will, like, throw an error, or it'll, it will end the call, or, like, end of the program, or something, something like this. So, so say in our guardrail, we only allow, like, `time_generated`, `account_name`, `action_type`, and `device_id`, but if the agent tries to return, like, `device_name` or `failure_reason`, um, it won't be allowed to do it because these are, like, outside of the guardrails, for example. I'll show you, like, exactly, like, what this is, um, in the code.
And then we also have a model allow list, like, only certain ChatGPT models that the agent is allowed to use. And if the, if somehow the user is able to inject some, uh, model to use that's not on the allow list in the guardrails, the agent won't be able to actually use that model. That's, like, the point of it. Maybe, like, the, the user wants to use a really expensive model that the company doesn't want to pay for, for example.
And then these are some guardrails that, that might be missing from our code. Um, so, like, a time window enforcement. So, currently, um, when you go to query, or when you go to, like, ask the agentic AI, like, "I'm worried about Windows Target One, blah, blah, blah, please look, uh, in the last, like, 500 days or something like this." There should be some kind of, like, guardrail that prevents people from looking that far in the past because it's going to, like, regardless of if the model can handle that many records, the Log Analytics will, will still, the agent will go and try to query Log Analytics, and that's, like, um, a waste of money because whenever you query Log Analytics, it, it costs money, right? And if you're allowed to retrieve, like, 500 days worth of logs, even if the model can't process it, it's just a waste of resources. So, we might want to make guardrails for, like, the time limit, right? And then row/byte caps before the LLM. This is pretty much the same thing. Um, this would be, like, if the amount of rows returned from, um, Log Analytics workspace is obviously, like, too much to fit inside of the token window. Um, we can, we can not even allow it to attempt to contact, like, the ChatGPT API because it's obviously, like, too many. And this would be, like, um, privacy stuff. So, PII redaction before the model. So, we could, we could have some kind of, uh, maybe we can have some kind of middleware, uh, in between the model and, like, before it sends stuff to ChatGPT for analysis, that, like, either removes or redacts any kind of personally identifiable information that got discovered. And then when we start doing, like, actual, like, remediation stuff, there's probably going to be, uh, more considerations we need for guardrails here as well. Yeah.
So, we can hop into the code. Um, I'll provide you with, uh, code as always for this lesson. So, just go ahead and download it and extract it. Um, I put mine on my desktop. Uh, it's called `Guardrails`. It's probably going to be named something like this. So, just make sure you open that folder up, uh, inside of Visual Studio Code. And then we will close all this, and I'll open up `main`. And then let me see. I'll put a breakpoint here before this guardrails, before we validate the tables and fields. And I'll put a breakpoint here before the validation of the model.
So, um, I'll just run this program through once, uh, normally, so we can, you know, get an idea for how it works. I'm sure you probably have an idea for it already, but I'm going to use this sample, um, prompt query prompt/query again. So, I'll start debugging this Python debugger. Python file. Analyst, what would you like to do? I'm worried about Windows Target One. And by the way, you can use a different, uh, you know, prompt for this if you want. I'm just using this because it's, it's really simple. Cool.
If we bring this up, we can see all the stuff that happened so far. Um, it got the query context. It decided to look in `device_login_events` table for this. It's host-related rationale. And then next, it's going to validate, it's going to call the `validate_tables_and_fields` function, which is part of the `guardrails` module. So, if we look in Explorer over here, there's the `guardrails` module, and it's going to call this `validate_tables_and_fields` function, and it's going to have `tables` and `fields`. So, it's going to pass in the table name from the query context. So, if we look at, if we look at this debugger, and we look at, scroll down, let me collapse this and this, we see our query context, and we see `query_context["table_name"]`. So, `table_name` is `device_login_events`. So, it's going to pass `device_login_events` here, and then `query_context["fields"]`. It's going to pass in these fields: `time_generated`, `account_name`, `device_name`, etc.
So, we're going to step into this. You see it goes into the `guardrails` module, inside of the `validate_tables_and_fields` function, and we see the table `device_login_events` and fields. And then we step into, it's going to print "Validating tables and fields..." and then it's going to check if `table`, which is `device_login_events`, is not in `allowed_tables`. So, `allowed_tables`, this is a variable inside of this `guardrails` module. So, if we scroll up, we see this `allowed_tables`. It has the table that's allowed, as well as the associated fields that are allowed. The table that's allowed, as well as the associated fields that are allowed. And so, that, that's what this is. So, it's basically going to check to see if the table that got passed, `device_login_events`, is actually in here or not. And if it's not, it's going to print an error and exit.
So, if we step into this, it skipped over it because the table that we passed, `device_login_events`, is in `allowed_tables`. You can see here, `device_login_events`. So, this line of code, uh, splits up the fields into an actual list. So, if we step, step into this, we see `fields`. Now it got turned into a list. And then now it's going to look through all of the fields in here one at a time. And it's going to see if the field is not in the `allowed_tables` appropriate table. If the field is not in there. So, for example, it's going to look in this `allowed_tables` event, or sorry, it's going to look in this `allowed_tables` uh, this is a dictionary, and it's, it's going to pass the table name that we're working with, which is `device_login_events`. So, it's going to return, it's going to return basically this list of fields that are part of `device_login_events`, and it's going to check, like, each field that got passed into the function if it's, if it's in here or not. And if it finds one that's not in here, it's going to have an error.
So, for `field` in `fields`, if `field` is not in `allowed_tables[table]`. This sounds a bit confusing, but, uh, just that's how it works. So, if `field`, so, for example, `time_generated` is not an `allowed_tables[table]`. So, `allowed_tables[table]` is `device_login_events`. So, it's going to return, like, this. If the field is not in here, throw an error. We can look, and then it's checking each one. And you can see this `field` gets updated every iteration. So, it's checking `remote_ip`. It was okay. It's checking `remote_device`. It's okay. And then all the tables and fields are validated because.
Everyone, and it's going to validate all of these, um, because they were all, um, part of the allowed tables and fields. And we say next. And we see that it printed out they were within guidelines. And then next, uh, I'm just going to let this go. Let the agent run as usual. Cool.
So, continue with chat dbt5 mini. So if we say enter, the next it's going to actually validate the model. So we chose chat dbt5 mini for the model, and then the guardrail is going to actually validate the model to make sure that that model is allowed to be used. So if the, you know, in theory, if the user somehow like injected another model that's not on the allow list, for example. So if we step into this, it's going to go into the guardrails. Validate model. Validate model. And then it's a really similar function. If the model is not in allowed models, then throw an error. If not, say that it's okay. So allowed allowed models, that's just another variable inside of the guardrails, uh, module. So allowed models: GPD5, GPT5 mini, 4.1, 4.1 nano. And our model that got passed is GPT5 mini. And if we look in allowed models, we see it here. So it's here. So it prints "selected model is valid" or it will. So, and it does. And then from this point on, the threat hunt is actually going to, it's going to do the threat hunt and then, um, find all the the threats and print them to the screen. But I don't need to do this. So, I'm just going to stop it. So, hopefully that gives some kind of ideas for guardrails.
And then next, we're going to actually, um, inject some stuff that's not allowed so we can observe the guardrail stopping the agent from doing something. Okay. Uh, I came back. I had to leave the hotel and I came back and my nose is like more stuffed than ever, somehow. Um, but now we're going to run this code again and we're going to actually, uh, stop it at the guardrail and we're going to, uh, inject something, for example, for the table or something for the fields to make it try to do some action that's outside of what's allowed or something that's like outside the guardrails. Um, and just so we can observe what happens, right? So if you remember, this is easy for us to do because we, we actually own the code, um, and we're, we can run it directly. But normally, this would be a bit more difficult to do because the code, or rather the agent, would be controlled by a remote user just issuing like simply issuing commands to it. So instead of, um, like issuing commands normally, we're going to like debug the code and then we're going to like either adjust the guardrails or we're going to, uh, change the variable values like in the middle of our code running to show you what it, to show you what happens if the agent tries to do something that's outside of the parameters or that's like outside of the guardrails or tries to do something that the guardrail, the guardrail will block. So this will make a lot more sense once we like actually do it. But, uh, the first one, I will, let's see, we have a our guardrails that will validate the table and the fields in our query. So I'm just going to run this again. I'm going to do the same easy query. Feel free to deviate from this and do like a different query if you want. So I'm going to debug. I'll, I'll just keep doing this. Like, I'm worried that Windows Target One might have been maliciously logged into. It's easy to like wrap our heads around that. So, what do you want? I'll say this, and then it's going to do the whole thing. It's going to get the query context. It's going to build that whole like object that gives context to like which tables to query or which table to query, which fields, like is it about a user, etc. Remember this thing? So it went out and decided all this stuff. It decided we're going to look in the device login events table. It decided these are the fields, etc. And so now the next thing it's going to do is it's going to attempt to, um, validate the table that it decided here, and it's going to attempt, or here, and then it's going to attempt to validate the fields. And the function that does this is inside the guardrails, uh, module. So if I say step into, like, so this table variable got assigned the device login events, and this fields variable got assigned these fields. Um, these are what the, these are what the agent decided it's going to use to query. And this is the validation function to make sure the table and the fields are allowed to be queried. So the first thing that happens, it's going to check if this device login events, um, table is, is in the allowed tables. And we can see that it is, like, right here, device login events. But if you remember, we can actually, like, if we're debugging like this, we can actually edit the variables value live. So I'm going to use a different table. I'm going to assign a different, uh, table name. So let me think here. In allow tables, um, so there's a table called audit logs that's in Azure, for example. I'll show you. Hey, so this, this is an actual table, as you can see, there is stuff in it. So I'm, I'm actually going to change this table value, this variable, the value I'm going to change it to audit logs because this is a real table, but it's not actually in our allowed tables list, as you can see. As you can see, there's no audit logs in here. So if we say step into, it's going to evaluate. If we hover over a table now, it's now audit logs because we changed it. It's going to look to see if it's inside of here. And if it's not in here, this stuff is going to happen. So, it's not, it wasn't in there. So it printed "error: table audit logs is not in allowed list. Exiting." We can say step into, and then it throws an error. Uh, it exits with error code one, which means like something bad happened. If we step again, the program closes. So this is like, kind of a quote unquote problem. We, we should have some kind of logging available that will log when something like this happens. For example, this would log to either like a local file or like a, a database or something. Um, and then instead of exiting the program, maybe this should return like false, for example. And then the agent can have the opportunity to correct itself or something like this. But for now, the program just exits.
So I'll run this again. Say start debugging. And I'm going to use the same prompt just because it makes things easy. Copy this. What would you like to do? Same thing. It's going to get the query context as usual. It got all of this stuff. Um, we are going to, uh, uh, I'll actually, okay, let me stop this actually. Um, instead of editing the variables like live, I'm going to go to the guardrails and then I'm going to change one of the guardrails. So, uh, because I'm using the same prompt, um, it's going to try to validate the table and then it's going to validate the fields for that table. So instead of time generated, let me see. Uh, I'm going to actually, like, remove the time generated field from device login events. So to make it not allowed. So now time generated is no longer an allowed field for the device login events table. And then we can see like what happens with this. So I will run this again. Start debugging. I will paste this. I'm worried. It's going to get the query context and then it's going to, the code is going to break here right before it validates the tables and the fields. So we will step into this, and it will step into the table and field validation function. So this is a table, device login events, and then the fields. You can see it's trying to validate if these fields are allowed, like time generated, account name, etc. So if we step into, it's going to, it's going to validate the table. So device login events, in that, is here. It's inside of allowed tables, device login events. So if we step, should step over. And then it's going to, um, turn the fields. This is basically a string. It's going, this code turns this raw string into a list. So we see this now, it's a list. And then now it's going to look through every single field and then check if that field is in the, um, allowed fields list, which is inside this allowed tables variable. So this is a dictionary. This allowed tables is a dictionary, and we're passing it the device login events key. So what that means, it's going to look in allowed tables and then the device login events key, and then it's going to return this list of, uh, this list of properties or fields. And then it's going to try to check if this, if our, for each field in fields, it's going to check each one of these and see if it's in the allowed fields list for this allowed tables dictionary. So if we say next, first thing it's going to check is time generated. Is time generated inside of allowed tables under device login events? It's, it's not here. So we say step into, and then it immediately starts printing out the error because it, a table or a field is trying to be processed that doesn't actually exist in our guardrail. Says "error: the field time generated is not in the allowed fields list for table device login events." And then it's exiting. We can say next, next, and then it exits. So that's because we actually removed it from device login events. So I'll put this back. So, and we can do this like another way too, like we can, like change the name of one. So when it tries to validate account name, it's account name is not in, it's not here because account name X is here, and it will fail. So I'll just put these back.
And then the next thing we're going to validate is the actual model, which is here. Or I'm going to break it. I'm going to inject a model that is not in the allowed list. So I'm going to run this one more time. I'm going to use this. I'll paste. I'm going to let it validate the tables. So I'll just step over this because it will validate. Good to go. Fields and tables have been validated and comply with allowed guidelines. And then now the query is going to run, uh, against log analytics. It's going to gather up all and any and all logs found. 300. Uh, and then at this point, this is where we say the model that we want to use. So I'll show you something interesting here. Um, continue with GPT5 mini. Um, we can either like type a model name or a list the allowed models. So I'll say, for example, I'll try to use like GBT, uh, 40 for instance, because this is a legit model. It's just not in our list. So I'll say GBT40. And then it says, uh, "press enter to continue. Type a valid model name." Okay. So this, this is like not, it's not allowed, like it's not letting me to do it. Yeah. So I'll say, I'll say GPT5 mini. Press okay. So I'll say I'll press, uh, enter to continue with this model. And then now the guardrail is going to start, um, rather the, the agent is going to check if it's allowed to do that. And it, the guardrails are going to stop it if we injected, or rather, if we're trying to use a model that's not allowed. So this guardrail, again, this is a guardrail module, which is here, and then it's going to use the validate model function. So guardrails, and then there's a validate model function here. It's here. So if we go back to this and we step into this, we can see that it's trying to validate GPT5 mini and it's going to check if GPT5 mini is in allowed models, which it is. If it, sorry, if it's not in there, it's going to print an error message. But if it is in there, it's going to say, "oh, okay, it's valid," and then it will let the program continue. So right now, model is currently set to GPT5 mini. So if I like directly change this, if I go to debug, right, I can change this to GPT40 instead of GPT5 mini, like so. And then now, if I say step into, the model is now GBT40. And that means it is not in allowed models because we don't see 40 in here. So it's just going to print the error message and then it's going to exit, like so. "Model GBT4 is not allowed." I can say next and then finish.
So, that's it for guardrails. Um, of course, there's a lot more stuff that you can do. You can put guardrails around pretty much anything. Um, again, like the, the personally identifiable information, like we can make some kind of some functionality that prevents that stuff from being submitted to the model. Um, or we can do something that, uh, prevents the user from querying too many logs, like too far back in history, like, you know, uh, if we try to say like one month or three months back or something, because we know that, well, most of the time that's going to be too many logs to feed to the, the agent or the model, right? And it's going to waste money by querying log analytics. So there's a lot of other stuff we can do. Um, but hopefully that gives you some kind of idea, um, what guardrails are. It's just something in place to prevent the agent from doing something that you deemed it's not supposed to do. Whether that's keeping the user physically safe or preventing the company from using too much money, etc. So, I might encourage you to, um, mess around with this guardrails module. And then if you, if you want to get like adventurous, um, you can add models into here. So, for example, let me see if I can find this. OpenAI model comparison, for example. I think it's here. So there's like, there's a, a ton of, ton of models, right, that you can do, that you can use. So, for example, I think GPT5 Nano, we're not using it. So you can get GPT5 Nano, and then you can actually, let me put this, I'll put this link in the code for you. If you wanted to, you could add another entry in here for GPT5 Nano, and then you can experiment with that a bit. So you do like, you know, comma, enter, and basically just like, actually just paste another one of these, essentially. So, and then get rid of the last comma. And then you, you just want to like make sure to fill in all this stuff so it's appropriate, um, and it's like the correct data and everything. I'm, I'm going to erase this. I just wanted to like show that. For example, you could do that, or you could add, for example, you could add, um, the audit logs table, and then the allowed fields. Then you, you have to adjust like the, the tools variable that we worked with in the previous lesson and stuff, but I just, I don't know. I'll just look through this and then try to mess with the guardrails just to get better intuition for it. And yes, uh, again, it's, I know it's like getting a bit complicated. So if you run into issues or you have questions, absolutely go to the community and ask anything you want. But yeah, we will see you in the next lesson.
Welcome back. In this lesson, we're going to focus, uh, very heavily on prompt engineering, specifically for the prompt that's used to actually execute the threat hunt, like dig through the logs and then build the actual threat hunt report that comes out. And previously, um, we hovered up to about, uh, here, where we took the normal input from the user. We, uh, derived a bunch of structured data from it, and then we're able to query log analytics workspace with that data. And then from this lesson, we're going to take the logs from log analytics workspace, um, that the query returned. And then we're going to spend quite a bit of time, uh, showing how the actual prompt is built that's used to do the threat hunt. So, we're going to go over how the user prompt is built. We're going to go over the actual system prompt that's used for threat hunting. And then, uh, we're actually going to execute the hunt in this lesson. Then, we'll, we'll kind of end it from there. But mostly, like the majority of this lesson and like the, I guess the priority of this video is to cover like how this, um, user prompt is actually built because it's a bit, it's not complicated, but there's like a bunch of moving parts in it. So before we actually get into the code, I'll just kind of explain it a bit here. Um, so as always, not always, but most of the time when we send a prompt to chat GPT, we have the system message and then the user message. And then I'm going to explain this again because maybe it's like good to hear it. But basically, the system message is, um, how we want chat GPT to behave and giving it context for what it's supposed to be doing. And then the user message is like the specific instructions that we want, uh, chat GPT to do or the stuff, yeah, the instructions or like the stuff we want it to reference when it's trying to do the thing that we're asking it. So system message, we'll cover all of this in code, but the system message, it's basically we're saying, "You're a cybersecurity threat hunting AI, trained to support SOC analysts by identifying bad stuff, um, in log data from Defender for Endpoint, Azure Active Directory, Azure Resource Logs. You're expected to blah blah blah." And there's a, there's a bunch of stuff in here, but we'll look at that in the code in a bit. So that's the system message. We're just giving the, the model context for how we want it to behave and like what, what we want it to do. And then the user message is, this is the kind of quote unquote complicated part. You see there's like a bunch of different parts in here, uh, that's kind of representative of this. But basically, there's four parts. Uh, the first part is the request. Um, this is the thing that the human SOC analyst says to the agent. For example, like, "I'm worried that Windows Target 1 might have been maliciously logged into," or "I'm worried that our Active Directory tenant may have been compromised in the last week," or something like this. Those human instructions. And then this table specific instructions. These are, uh, specific threat hunting instructions for whatever table that, uh, the logs are in and whatever table that was decided to use to be used for hunting, like specific instructions on how to hunt with that table. And then this section is how we want it to format the data when it outputs the answer to us. Like when it outputs the threat hunt information, the stuff it discovered. This is like the, the schema or the format of the data. And then the fourth part of this prompt is the actual logs, um, that came back from a log analytics workspace, like the device login events logs, device process events logs, or whatever those happen to be. And these two, like huge things together, the system message and then the user message. This will be combined into a list and then sent to the model. And then this is the thing, um, where the tokens can be like too big. Basically, in the previous lessons when we're checking like the, the quota and like the token size and stuff, this, this prompt is ginormous, basically, or it can be ginormous depending on like what you're querying. But yeah, that's, that's what we're going to be doing. I think it's not aligned. Cool.
So, as always, I'm going to include code for this. So, just, um, unzip it and put it on your desktop or wherever you want to. I put mine on the desktop. Um, it's going to be called prompt engineering or something really similar to this. So if you are, if you have something open in here already, you can say close folder. This is VS code, and then we'll go file and then open folder, and then mine is on the desktop, and then it's the prompt engineering one. Then, as always, make sure that you have your keys in here, your, uh, API key. If you don't, or it expired, you can always get another one from here. And then, as always, uh, and then, as always, just make sure you're logged into a login. So, open terminal if you're on Mac, or command prompt or command line if you're on Windows. And we'll say a login just to make sure that we are logged in. And you'll log in with your, uh, cyber range ID. Take the subscription, and we should be good to go.
Okay, so just to recap, um, we're going to focus mostly on like when we retrieve the logs, and then we're going to dive into the, uh, part of the code that builds the prompts and then sends the, uh, prompts to GPT. So, we'll go to main. Go ahead and open up main. And then see where the prompts are built. So, I'll just stop it here. This is like, right after the logs have been retrieved from log analytics workspace. So, I'll just stop it here. Put a breakpoint here. And then we'll run and then debug. Python debugger. By the file. And then I'm going to scroll up and then I'm going to keep using this prompt. Um, you can use your own virtual machine for this prompt instead of Windows Target One. I'm just using this for the sake of ease and to, I'm more interested in understanding like the workflow and understanding the code behind the agent. So, I'm not putting a whole bunch of different prompts. I'm just using this one because it, it tends to make sense to most people, but you can use a different one if you want. So, I'll just run this, and then it should break around here. It broke. And then I'll just take a look at this, uh, query context and metadata. Uh, four days, 96 hours. This stuff rationale. And this is the KQL query it built. And then we're a number of records. So I'll step over this. Step over this. Step over this. And then this part, this code right here is this. And this as well. It's the same thing. So this is actually this threat hunt user message. This, uh, this module has this function in it. So build threat hunt prompt as part of the prompt management module. And then after this function, oh my gosh, and then after this function runs, oh my god, thing is me off. Just like remove that edit or edit that out. Who's ever editing this? So after this function runs, the whole like, this whole user prompt, this green part is going to be assigned to this variable after the function runs. So, um, instead of stepping into or instead of stepping over, we're going to step into and then let's just like take a look at what's happening here, like really fast. So this function, um, takes three arguments. So the user prompt argument, the table name, and then log data. And then this, uh, user prompt, we can look at what it is. I'm worried about Windows Target One. This is just basically the message from the user. The query context table name. This is the table that, um, GPT decided we needed to query. And then this log results, log query results, records. This is all of the log data. So this is going to be like a humongous string inside of here. Like a humongous string of like all the logs that were found if we, it's, it's just a lot of log data. So we can say step into, step into, step into, and then one more time. And then now you noticed if we click explore, we moved to the prompt management. I'll double click this, the prompt management module, and then we're inside the build threat hunt prompt. So if we step, we scroll down, building threat hunt prompt instructions. So the first thing, um, it's going to grab the instructions, and these are threat hunting instructions specific to the table that was used. So, it's going to look in this threat hunt prompts variable and grab, um, the specific instructions for this table name, device login events. So, threat hunt prompt instructions, it's just a member of this prompt management, uh, module. So we can find it somewhere in here. Let me find it. Prompts. I'm going to copy this. Okay, so it's here, and this is one big dictionary. It doesn't really look like it, but it's because this is the key, and then this is the value, and the value is huge. That's why. So I will collapse this, and then the, the one we're going to be querying is the device login events, or the table that we're using. So I can like collapse these, uh, key value pairs, and then we're going to look at the device login events instructions. So this is the key, actually, for device login events, the threat hunting instructions, and then this is the value. It's just happens to be really big, like a multi-line string. So these, these are the specific threat hunting instructions that we're going to be sending to chat GPT in our case. So you can kind of read it. Um, "You're an expert threat hunting AI analyzing the MDE device login events specifically." And then it says like, "focus on abnormal authentication behavior and lateral movement." So we, we could add more stuff in here because this, this is what makes, um, gives GPT context for what we want it to do. And this is like a bit limited. This could be way bigger, to be honest. This prompt, um, because these are, as you know, like, these are not the only things that can happen inside the device login events table, but these are like, I guess the quote unquote main or general things that can happen. Detect unusual login types, um, local logon from remote users, repeated fails, etc. So, it's just giving GPT context for what to do. So if we go back to, I'll say, step into. So our instructions now have this, the instructions specifically for the device login events table. And then this right here, um, this is building the actual full prompt for, um, our threat hunt. So this variable, it, it's going to contain this stuff. So the user, it, it's basically just building a big prompt. So it's getting the user request, and then it's, whatever this user prompt is, "I'm worried that Windows Target One," and then threat hunt instructions. It's going to use these instructions here. These are the specific, uh, table specific threat hunting instructions. And then the formatting instructions is here. This is just, um, how we want GPT to, um, format or structure the data that gets returned. So if we click on this formatting instructions, I'll copy this. This is just another variable inside of this module. So I'll search formatting instructions, and we can see it here. Um, these are instructions to GPT: "Return your findings in the following format." And this is a dictionary. This is a key, and then the value is an array of findings or a list of findings. And we're telling it if there are no findings, return an empty array like this. And then, um, this is important, like here's the schema that you are to use. Schema just means like the structure of data. So you can change this to be in any way that you want. But this is how I, I just came up with to format the threats that I found. So findings, right? And then this is, uh, the beginning of the list. And then this is like the first finding. Then we have like a title, description, MITRE information, like the MITRE ATT&CK framework. So it will list out the tactics, techniques, sub-techniques, etc. And then these are the, the specific line, like log lines that GPT found that considered, um, that were like relevant to this threat. And then confidence rating, we can say like low, medium, high. And we can, we can add something in here too, like a, um, for example, extremely low, extremely low. And then I can say like, you know, I can, I'm, I'm just showing you that it's like, um, really flexible, or it's, it's, it's an LLM, right? So you can put literally anything in here that you want. Um, you don't have to do this. I'm just like adding it just, just to see like what happens. And then recommendations. These are the recommendations, um, for it to come up with. I like hardcoded them in here. So if you want to like add another recommendation if it's like too low, you know, we can say like, ignore. Oh, it's already here. That's so funny. Um, I can like add something, for example, something like this. And then indicators of compromise. These are like the actual IoCs that the model found. So this could be like a, a certain log, a certain log line, or something like this, or some, something that triggered it to thinking that this is the thing that caused the compromise, or this is like, um, the malicious activity. It could be like a log or something, or a series of logs. And then relevant tags. We can add more stuff in here. And then any notes, uh, that any notes that it, it wants to include. So this is just the schema for how the data is to be output by chat GPT, and you can, you can change this again. And then over here. So if we say step into, it's all this is doing is putting a big string together. So, for example, it's just putting, oh, this thing is like out of whack because I added, oh my god, let me undo that. It like messes up the lines. So, it, um, so this is the actual prompt, like the user prompt. This whole big thing here is this green part. So if we say step, it's going to return it. We say step, and then that whole thing got returned to, um, this threat hunt user message. It's, it's just got formatted in the like quote unquote message format that's sent to chat GPT. So it says like role user, and then the content. And this is our, our huge, uh, prompt that was made. And then next, the, uh, system prompt is going to be created. The system prompt is simply this. It's pretty straightforward. So if we look in prompt management module, and then the system prompt threat hunt, uh, so we can double click prompt management and then we can search for that. It's just this, um, to give chat GPT context for how we want to behave and what it is. So you can take the time to read this if you like. "Your cybersecurity threat hunting AI." "You're expected to to do this stuff." "Your tone should be this." "Avoid the following." And then you, you are assisting skilled analysts, not end users. And it's just giving it context for how we want it to behave. So we go back to main. We say next. Step into this. Now the system, the system prompt is stored in here. And then this threat hunt messages is going to be like a, just a combination of the two. So it's like a list with the system message and the, uh, user message. So we can say next. And then the rest of this stuff, this is going to like, um, count up the tokens and then select the model and all of that stuff. So I'm wondering, should I, I'll just like let this hunt finish. But before that, um, I want to actually run this in chat GPT, like the actual browser one, so we can observe it. So, for example, uh, click this debug and then go to, collapse this, collapse this, and what was made, this threat hunt. So I'm going to get the system message and then the, the user message, and I'm going to actually put them inside of the browser version of GPT just to kind of show you what's like actually happening on the back end. So, threat hunt, threat hunt system message is here, and then I'm going to get the content. So you can double click this and copy it, and then I'm, I'm going to go to chat GPT and then paste it, though I'm going to erase the beginning and end quotes. So this whole thing is the system message. Um, and again, when you use the web version of chat GPT, there's already a system message on the background being used. I'm just pasting this here for extra context. And then I'm going to get the actual user message, like the, the long one, which is here. So, threat hunt user message, and then the content is here. Now, I'm going to copy this, go back, and I will paste it and remove the quotes, and you can see what it is. So remember, we're, I just pasted these things, the system message and then the user message, and then the user message is comprised of like the initial prompt, the table specific instructions, how we want it to be formatted, and then the actual logs. And we can see those reflected in here. So this is the, this is the system prompt here. System prompt. And then this is the user message, uh, here. And then this is the threat hunt instructions. This is table specific instructions. And then this is the, there should be like the format. Oh, here we go. Here's the formatting instructions, which is here. And then the last thing is the logs, which is, you can clearly see they start from here, logs below. So I'm going to copy this from GPT and then I'm going to paste it in Claude as well. So I'm just going to like run this, and I'll run this, and then while this is going, I'll go back to our code and I'll just resume the code. So, all this, all this thing did is it just created a, a big prompt to be put into chat GPT, but it's all happening programmatically on the back end. So I'm going to press enter to let it select that, let it select that, uh, model. So this, this cognitive hunt is going. It's the hunt is happening. So if I'm going to go back to like our browser version and see what's happening. Um, GPT browser is still analyzing attack patterns. We can click on this, probably, and see, you see what it's thinking. And then Claude, Claude is doing something very interesting. So this finished. It found three results. And we can say enter. And then maybe in the future lesson, um, I'll cover like how the threats are actually formatted. So, but for now, I'll just like say enter and let them get dumped to the screen. We scroll up and we can see the, uh, we can see the potential threats. And then I'm not going to, well, I won't spend time to like really look at these, but you can scroll through yours a bit. I'll scroll through them and you can take the time to look at it. Um, and you can see actually, if you remember, sorry for jumping all over the place, um, go to prompt management really quick and then search formatting. So if you see these formatting instructions where we told it like how, how we want the schema to be, the structure of the threats, this is the object that gets created on the back end. But the thing that gets dumped to the screen is formatted in a more user-friendly way, which we're going to deal with in, uh, a future lesson. But I want to show you something. So this is the format of the threat, right? The data. So if we go to our explorer, this threats.jsonl actually contains all of the, the threats that have been found like in our previous hunts. And this, the formatting of this data here, these JSON objects, this, this will be in line with these formatting instructions. This threats.jsonl, um, it's a bit hard to see like this, but you can just like trust me, I guess, it's just a big JSON object formatted in the way that we specified. So if we go back, um, we can look at our GPT, and this thing is still going. I wonder if it's actually literally still doing something. It looks like it is. And this is GPT's output. It looks like it only found, it only found one. I don't know if it's because like the browser version of chat GPT is like doing something weird. I'm not really sure, but it looks like it found one. Um, and it just dumped it to the screen like this. And you can kind of look at it. It's probably similar to what was found inside of here. And then you can see the log lines, specific log lines that was talking about indicators of compromise, like these are the bad IP addresses it found, um, accounts being targeted, device action type. And then if we look at Claude, it formatted it a bit better for us. Oh, it's still going. That's really interesting. But yeah, my point with this is I just want to show you that actually like the thing that GPT, our agent rather, is doing, it's just, it's just constructing a big prompt like this. It's just constructing this prompt with like the system message for context, and it's providing as much context as possible with like what the user wants, uh, how to hunt in that specific table, how to format the output, and then actual logs for more context. It's just creating one giant prompt and then dumping it into GPT. And then GPT will diligently, uh, analyze the logs based on our prompts and then output the data based on our schema or our format that we provided. Yeah, you don't, you don't have to like use Claude, by the way. I just wanted to like show you, I just wanted to show you that. Um, but if you want to, I, I would recommend doing this. Um, there's a lot of stuff that was used in this prompt management thing to actually formulate those prompts. So, for example, the general threat hunting prompts, like the device network events, all of these can be refined and and made better, right? So, for example, um, we can copy this, for instance, and then we can open a new instance of chat GPT and we can say something like, uh, "Can this prompt be made better or comprehensive in any way? I want to make sure I'm not limiting the LLM in any way, shape, or form." Just for example, like any of these can be can be improved. Did I grab the right one? No, this is not. Whoops. Let me get to device login events is what I wanted to get. I mean, I guess it doesn't matter, but we're, we're typically using this one a lot because it's easy to understand. Let me, device login events. Okay, so we can, we can do this, for example. But again, the problem is like, the more verbose and robust your prompt is, like, in theory, the better the output will be. But you just have to strike a balance between, you know, using too many tokens and like, uh, I guess, I guess verbosity and succinctness. If it's more verbose, you can tell it more stuff to do, but it's going to use up more tokens. Uh, but if the prompt is like really, like tight and succinct, it will use less tokens, but of course, you know, it may not be as comprehensive, I suppose. So, it's an absolutely great start. Here's a stronger, more comprehensive, paste-ready prompt. Blah, blah, blah, upgraded to drop-in prompt. So pretty much, uh, I guess we can copy this. Um, this, this is like not really good because it's trying to specify time frames and stuff, which is not really, well, the time frame is like handled outside of this prompt, I think, right, when we're gathering the logs in the first place. So you might want to like refine this a bit. So, well, anyway, in output format, of course, so like, we don't need to like, um, specify output format because we are, we already doing that somewhere else. So, just to be like, I guess cognizant of what you're pasting into your, your threat hunting instructions, but I'm just going to, just for the sake of, you know, having a good time, I'm just going to copy this and I will go inside of here and I'll just like paste this just for the heck of it. And then I'll run this again just to see if like anything is like slightly different, and then we'll, we'll end the lesson. So, I'll do this. Well, I'll, I'll look at a couple more things before ending it, but hope hopefully that makes sense. Um, like, like this specifically is how to threat hunt, like the device login events table. This is how to threat hunt device network events table, etc. And you know, the better your prompt is, the better the, um, GPT or the model is going to be at actually doing what you want it to do. So I'll just like let this finish. That will say enter. Should be threat hunting the device login table. I think it is. Yeah, it is. So, it's using our, it's using our new prompt. Uh, let me do like one more after this, actually. While this is going, I'm going to check what Claude came up with. See here. Still like doing something. Findings title, log lines two. It found a second one. Found a third one. Found a fourth one. Thought is like going to work. Damn. Taking forever. Taking forever though. I'll say enter. This is, this is with our new, um, device login events table prompt, I guess, and we could take time to like compare and contrast these logs and like fine-tune it and everything, but hopefully you get the idea. Um, right. Each one, each table we're hunting, the way we, the way I engineered this, I guess it's not the best, but the way I engineered it is each table has like specific hunting instructions. And then let's like edit the system prompt a bit. So, I'll add something like ridiculous in here. For example, I'll say, "When outputting anything at all to the user, please speak like, uh, a late 90s valley girl." I just want to see like if it respects this and actually does it. So I'll do like, uh, one more. I'll do one more threat hunt. So basically, to give you an idea, um, I changed this right here to, you know, talk like a, a late, late 90s valley girl. I just put that in the system prompt. So it should, uh, it should output, you know, something that sounds like a late 90s valley girl. But, you know, we'll see when, when the actual, uh, threat hunt is completed, like when it's dumping the threat information, that's when it should be talking like a, a valley girl. So, we'll see what happens. I'll use the same prompt. I'm going to remove the breakpoints. They enter to pick that model. It's running the threat hunt. Great. It finished. Oh, wow. It worked. All right. Okay. So potential threat one description. Oh my gosh. Like, this is definitely noisy. Windows Target One saw a concentrated burst of login failed. Login failed against events. Uh, tons of blah, blah, blah, automated attempts. Okay. It kind of like gave up, I guess. Talking like a valley girl. Notes like. So listen, confidence numeric. This is so funny. But anyway, hopefully like that makes sense and you get the idea. I would just like spend some time like looking at this and understand what the system, the system message is, or the system prompt, as well as like the user message and like what each part of it is for and what, what they do. It's, it's basically just one giant like context. Uh, it's, it's one giant prompt maker, right? It's like giving as much context to chat GPT as possible and then telling it how to behave. So I would go through, you know, just to get like a better sense, uh, and maybe increase your understanding. I might like go through and then adjust like the individual threat hunt prompts, or at least like one other one, for example, um, like try to see if you can make the, the sign-in logs table one better, or something like this. This is the one that keeps track of when people like try to log into Azure or like enter ID, aka Azure Active Directory. Like these are, this is currently how I'm having it like threat hunt, but this can definitely be made better. It's like quite short, as you can see. Um, and just, you just have to use like GPT to like give it more context of like what you want to do. Like you want to refine it, but you don't want it to like try to constrain things for time because we're handling time somewhere else. Uh, etc. But yeah, let me know if you have any questions about this. Um, just, as always, post in the community and tag me. Um, I will get to it, or my staff will get to it, or someone else will see it before we get to it. But yeah, hopefully this helps. I know it's like a bit, a bit complicated, but, um, the more you practice with it, the more the better your intuition.
should increase over time. But yes, uh thanks for watching and we will see you in the next lesson.
Welcome back. In this lesson, we're going to cover VM isolation. That is, uh, if threats are found on a virtual machine and the confidence is high, we're going to be able to implement agentic isolation of the virtual machine to have it isolated in, uh, Defender for Endpoint. And again, it's pretty important that you went through the SecOps course before this one, otherwise some of the stuff won't make sense. But I'll just, uh, get right into it.
Um, so go ahead and in the lesson, um, if you go down and then download the zip file as usual, this contains the updated code. So just download it and then extract it and then put it on your, your desktop or wherever you want to put it. I just extracted mine on the desktop. It's called, it looks like this, VM isolation. And then go ahead and open up that folder in VS Code. So, as usual, you know, if you, you can close everything that's open, like close folder and then open folder. And then I just went to desktop and I opened, uh, this folder right here. And that's what this is, this main.py.
So to do this lab, um, you can either create your own virtual machine and open up the NSG and the Windows firewall so it gets discovered on the internet. And then we want a lot of people to be trying to brute force your virtual machine or trying to get into it. Um, alternatively, you can use Windows Target One or Linux Target One to do this lab 'cause those are likely on already and they're getting brute forced. And technically speaking, you can use, you can use other people's virtual machines as well. But, um, this lab, we're going to be isolating the VMs. So just bear that in mind, like don't, don't isolate other people's virtual machines and then forget to remove them from isolation or something like this, because if you, if you isolate a virtual machine, you, you can't, I don't believe you can un-isolate it until it gets turned on again, and you, you're not allowed to turn other people's virtual machines on, I don't believe. Um, so for example, if a virtual machine is off, you can isolate it, and then when the virtual machine comes back online, it'll automatically get isolated, and then you can't undo it unless the virtual machine is on. So in my opinion, or not my opinion, I, you, you should focus on using your own virtual machines or, or these two VMs. So, um, if you want to, you can pause this and set up your own virtual machine, make it live and all that. Um, otherwise, you can use Windows Target One and Linux Target One.
So in this code, we're going to, uh, add three new functions in the executor module, and then we'll step through these, um, when the code is running, but I'll show you them now and like talk about them a bit. So there's just like a get bearer token, uh, bearer token. Oh, so this is just a function that gets like a, a login key, aka bearer token from Azure. It's basically like a, you can think about it like a password, and this bearer token/pass is going to be used when we're calling the API that isolates the virtual machine. So this is function get bearer token. Actually, I'll show it to you. So if you open up the project files or the project file, you go to executor, it's right here, get bearer token.
And the next function, the one that got added to the executor module is get MDE workstation ID from name. So this function basically, it will, it will look up the machine's ID inside of Defender for Endpoint given the host name. And this is necessary because when we call the, like isolate or quarantine virtual machine function, it requires the ID of the virtual machine, not the name. So for example, if we go to, uh, this is Defender for Endpoint portal. So like security.microsoft.com and I search like Windows Target One for example, and I open up this virtual machine, there should be like an ID somewhere in here. Oh, I think it's this device ID. So the function will take the, the name and then it will use this name to look up the device ID, and then this device ID will be used to isolate the device. This is all happening programmatically in the code. So get MDE workstation ID from name, that's here. This function, it takes the bearer token, which is like the password, and it will take the device name, for example, Windows Target One, and you will make an API call to the Defender for Endpoint API. Some stuff will happen, stuff will get returned, and then the machine ID will be taken out of this object and then returned.
And then the third function, this is the quarantine virtual machine function. It will take the, uh, virtual machine ID or the, yeah, the machine ID, and then it will quarantine it inside of Defender for Endpoint. And that's simply right here. Uses the bearer token, uses the machine ID, it creates an API request, some objects for an API request, sends the API request to Defender for Endpoint. Then if status code is 2011 or 200, it means the machine was successfully isolated, otherwise it wasn't. That's that.
And then we also added some logic, um, in the main script after we display, uh, the threats. So if you remember at the end of the script, all, all of the threats would be displayed. We added some more logic here to make some decisions about whether or not we want to isolate the virtual machine. So if you go to the main script, you go to the very end. So this is previously where the, the script ended. It would dump all the threats to the screen. And then now for this part, for this particular code, we added this stuff to get our bearer token from our, uh, login, like session. We set some variables here. We set some more variables about the query context. If the initial query is about an individual host or if the initial query was about an individual user, etc. We, uh, initialize machines isolated to false. And then basically, we're going to look through every threat that was in the results. And then we're going to say, we're going to get the, um, we're going to determine if the confidence of the threat was high. We, we will run through this in a second, but I'm just kind of explaining it now. For each threat, we're going to determine if the confidence of the threat is high via this. And we'll store that in a variable. And then we're going to say, if the query is about an individual host, it means it has the potential to be isolated. And then we're going to say, like, if the confidence of the particular threat is high and the machine is not already isolated, it's going to notify, it's going to notify the user. Okay, a high confidence threat was detected. This is the threat. Would you like, would you like to isolate the host? Yes or no. And then basically, if the user says yes, the isolation process is going to start.
So if the user says yes, they want to isolate it, this function is going to run, uh, to get the work, get the workstation ID first. So the workstation ID is going to be retrieved and stored here. And then this function is going to run the quarantine virtual machine and it's going to pass the token and the machine ID, and then the machine is going to be isolated if everything goes as it should. And then if it, if it does get isolated, we're going to print to the screen, okay, the machine was isolated, and then a reminder to, like, please release the VM from isolation, and then we, we show the link here to where you can go to, like, release isolation, etc.
And then this script is not perfect. Um, a lot can go wrong with it, but I might leave this for like an intern activity to fix. So, here's a few things that are wrong. So for example, there's like not really any error handling in the new, um, the new functions that were added in case the token is bad or like some other problem happened. So, and also validation, like if, if the user types like, uh, for example, would you like to isolate this VM now, if you type the word yeet for example, or like yellow, because it starts with Y, it will get isolated. So I mean, that's not, you know, should be better. And again, there's no logging or anything. And, you know, these are just like stuff. It, we remind the user to isolate the virtual machine, but in, in reality, we should have some kind of like mechanism to, like, you know, press I to like, or press U to un-isolate, you know, something like this, press R for release. And the script is generally just incomplete, but, uh, it will work for what we want it to do, assuming everything is set up okay.
So again, uh, we'll just go ahead and run this. Um, I'm going to use this prompt just for the sake of ease. Um, if you want to use your own virtual machine, you can do that. But I'm going to copy this prompt. I'll go to run and I'll say, actually, before I debug this, I want to break this toward the end. Oh, I'll break here, um, right before the new code starts happening, and I will run and I'll debug. Paste. I'm a bit worried about Windows Target One. Sounds good. We will say yes for this model. Cool. And the threat finished. We can press enter. It will dump all of the threats to the screen. Found it. Found three threats. This one's high confidence. This one's medium. This one's high. Yours are going to look different, no doubt. Right. Um, you can, you can pause this and like read it if you want, but you can see our script got paused here.
So, next, it's going, we're going to get the bearer token. So, if we say step into, it's going to step into the executor. So, if I go to file explorer, it's going to step into the executor module and then start executing the get bearer function token. Trophy step into, we step, step, and we can see our token. It's here with the expiration date and the bearer token, like the actual token string. So if we step, step, then now we have our token, like so. And we're going to initialize these VM, uh, machine isolated and user account is disabled. Um, we're not using this currently, the user account one, that's for the next future module. And then we're going to set these variables based on the stuff that's inside of our query context. And you remember the query context is all of those, like metadata that was, uh, generated based on the initial user request. So remember we said, um, I'm worried that somebody logged into Windows Target One, and then this stuff was derived from it, like the table name to look in, the device name to look in, the time frame defaulted to 96, and whether or not the query was about an individual user is false, about a host, which is true, because we said we're worried about Windows Target One, etc. We can step over these. These are all just assigning to these variables to be used later. Machine is isolated. Oh, this is like a duplicate. I didn't need to like have this here. So, we can say step.
And then now this is a giant loop. It's going to loop through all of the threats that were found. So, if we say step into, and then this is going to evaluate if threat confidence. This is the, this is the, these are all the threats, right? And then this is the first threat in the, in the group or in the list of threats. So threat confidence is high. So if confidence equals high, this is going to be set to true. So if we step over this, this is set to true. So if I go to debug over here, these that confidence is high. And then if the query is about an individual host. So remember this is from here, we got it from the query context, and the query is about an individual host. So now we're going to think about whether or not we want to, um, isolate the virtual machine. So if we step, we're going to say, if confidence is high, which is true, and machine is not isolated. So machine is isolated is false. So not false is going to, this whole thing is going to evaluate to true. So we, this, which means this will evaluate to true. So we step, and then now it's going to print some stuff for us to the screen. So if we scroll down here, high confidence threat detected on Windows Target One. High volume credential spray brute force attempts from single IP. So that's this is the title of the threat that happened. So oops. If we scroll up here to threat number one, we see it here. High volume credential spray brute force attempts from single IP. So that's the threat that's in question, and it's high confidence.
So if we step, says, would you like to isolate this VM? We can say Y for yes or N for no. So I'm just going to say like, I'll just say like no for this one. And then it's going to say, if the answer starts with Y, it's going to do the isolation stuff. Otherwise, it's going to say it skipped. So we step, we said no. So it skips down to here, and then it says that it skipped, and then it moves on to the next threat, like so.
So we're going to check the threat confidence of the next threat. So threat confidence is medium. So [snorts] medium does not equal high. Medium does not equal high. So this, this is going to get set to false. Like so, false. If the query is about a host, it is. So we're going to go inside. So if threat confidence is high and machine is not isolated, threat confidence is not high. So this, this whole thing is going to get evaluated to false, and it just skips to the next threat. So we go next. We're going to check the next threat. Threat confidence. This one's high. So this will evaluate to true. Like so, is true. Query is about an individual host. This is true. If threat confidence is high and the machine is not isolated, it's not. So this, this will evaluate to true, and then it's going to go into the isolation logic. So would you like to isolate this VM? I just want to show you for example, it just has to start with Y, and this [snorts] will, this will like, you know, erroneously evaluate to yes, but it's okay. I want to isolate, but I'm just like showing you the fact. If confirm starts with Y, which it does now, uh, it's going to use the, it's going to go into the executor module and then use the, uh, get MDE workstation ID from name function.
So if we step into here, we are inside of executor, and then we're inside of the get MDE, uh, workstation ID. It's going to build the request header. This, um, I forget what this does actually, but there was like a, there's a problem with like Windows, for example, like the Linux computers will have some like crazy long name in them, and I had to like somehow account for it with this. I forget, I forget what this code actually does, but let me like step it and see. Oh, right. Um, I, I believe. Okay. So, um, the URL that's used for the API request, um, it, it needs some like filter or whatever to help it retrieve the virtual machine that we're talking about, or the, the machine that we're talking about. So this, this line of code just, uh, formats our computer name in a way that turns into a filter for the URL. So I'll show you if we step over this. This is not something I, I memorized like at all, to be honest, obviously by the way I'm talking about it. So if we look at this, like URL, it's over here actually. So I think I can copy this value. I don't know what this is going to do, but, um, it basically made this, uh, this URL is used to find the Windows Target One virtual machine inside of Defender for Endpoint. Um, I don't think anything will happen if I just like click on this. Um, but it, for some reason, it needs to be like formatted like this. Um, it's just part of the rules for the API. I think I found it in like the API documentation or something, but we have our URL built and the headers built.
So, we're going to send an API request to the, um, Defender for Endpoint API. And we got our response back, and then it's going to pull the value out of the response. I believe it's like in this text somewhere. See this value is here. It's going to pull this. This is the machine ID. This B18 blah blah blah D4 at the end. So for example, if we go here, we see B18 blah blah blah, and then D4 at the end. That's the machine ID for Windows Target One. So we're getting that out. Oh, and then if no virtual machine is found, this will run. But it found a VM. Going to pull up machines from machines, uh, element zero, and then the ID, which is a Windows Target One ID, and then it's going to return it. So we're back to the main function. And then we got our machine ID here, B18, etc. And then now we're going to call the, uh, inside of the executor module, we're going to call the quarantine of virtual machine function, passing in our token, which we got earlier, as well as the machine ID, which we just got.
So if we step into this, step, step, we're in the executor module again, inside of the quarantine virtual machine function. And then again, it's going to build an API request, uh, header as well as the payload. So the header, this is the bearer token. And then the payload, this is just like a comment that's going to appear in the Defender for Endpoint portal. And then this is like the, uh, URL and the header and the payload. And then this is where the API is getting called. So if we step, step, step, and then here's where the API gets called, and then the machine should be isolating right now, you know, unless something happened. Response code is 2011, which means the isolation should have taken effect. So if I go back to Defender for Endpoint, this is Windows Target One, right? If I click here, we can see like this isolate device is like still active. But if I, if I refresh the page and I click here, you can see it turned to release device from isolation or release from isolation because this thing got isolated. We, we can see it here too. They got isolated on the back end with the API, like with this code that's running right now.
So if we say stay next, we can say, if the machine is isolated, um, this will be true if the, uh, quarantine virtual machine returns true. So this is true. If machine is isolated, we're going to like say some stuff to the user. VM successfully isolated. Reminder, please release the VM from isolation when appropriate at this URL. So you can like control or command-click this, whatever, if you're using Mac or PC. We say next, and then the threats are done looping, and then our, uh, program has finished, and then the machine got isolated.
So, always please remember to like, go back and remove this from isolation, 'cause I, I can't be just like isolating a bunch of virtual machines, 'cause this is one of those things where you have like enough power to like mess up the environment for people. And like, I didn't have to like include this, but I wanted it to be realistic, work, you know, 'cause at work, you can, you can do all kinds of stuff that's, you know, that's not good, right? So just remember to release it from isolation, especially if you isolate somebody else's virtual machine. So, so I will re, and by the way, if the virtual machine is off, um, these isolation and remove isolation, um, commands, it won't execute, of course, until the virtual machine is manually turned on again. So I'm going to refresh this page. Make sure it's no longer isolated. It's not. You can see it here. Also here. Isolate device means it's not isolated.
So I'll go back here, and then we will run this one more time. But I will show you something if I can. Hopefully it works correctly. So copy this, or not works correctly. I want to show you like what happens if you isolate the virtual machine and then, um, it continues to evaluate the threats and finds another high threat. So I will start debugging this. Say enter for this. I'm just going to start. Go ahead, it's done. Say enter. And let's see. It found one high. Found another high. And three highs. Great. This is what I wanted. So I'll scroll this to the bottom, and then I will remove this breakpoint and I'll just add a breakpoint to, let's see, I'll add one maybe here. I'll say continue. So queries about an individual host, true. So I'll say continue. So threat confidence is high and machine is not isolated. So it's going to do the isolation logic. So I will step through this, and I will say yes initially. Isolation [snorts] logic begins. And I, I'll say step over this because I don't need to like look through this whole function again. We know it's getting the machine ID. I'll say step over. And then this is where the machine is going to be isolated. So I'll step over this. And then machine is isolated. So Windows Target One is now isolated. So we'll step over these. Successfully isolated. And then it's going to go to the next threat in the list. So you remember there was three highs here. So we'll say step into. This is the next threat. The confidence is high 'cause they were all high. So we'll say step. Query is about an individual host. It is. So this is the interesting part. If the threat confidence is high and the machine is not isolated, but the machine is isolated because it already got isolated. So now this, this whole logic is going to be skipped, and then it just goes to the next threat. Same thing if the confidence is high, which it is, and the machine is not already isolated, which it is, 'cause it already got isolated, it skips, and then there's no more threats, and then the program ends.
So again, there's like a lot of stuff that can be, um, improved in this. I just, I'm just creating like a barebones MVP, like minimum viable product, um, because I want people to think about how to improve it and like use ChatGPT and stuff like this to make it better. Um, but I'll cover, I'll kind of cover this more, like probably at the end of this when we get into like how to earn internship credit. But make sure you like go and like, uh, remove the virtual machine from isolation, whichever virtual machine you've been isolating, isolated. So we will remove this, like so. [snorts] Yeah, that is the virtual machine agentic isolation, and we can, we can have it be like, you know, truly agentic in the sense that, um, it doesn't confirm with the user whether or not to isolate it. Like if it's not isolated and the confidence is high, we can automatically isolate. So for example, this, like we would just like remove this, remove this, and then like, oops, and then like bring this in one, and then boom, we have like, oh yeah, this is not necessary either, and then boom, like we have true agentic isolation. But it's always good to like, especially in the beginning when you're creating something like this, it's pretty much a good idea to let this, you know, let the script prompt the user for what if they want to do something potentially catastrophic or not. But when your processes are like really ironed out and the, the logic is good, and you know, you know, for certainty that it's going to do what you want, then maybe you can like, you know, have it be truly agentic. Um, because, well, I don't, I don't want to put like a bad, any ideas into anyone's head, but I think if anyone's watching this this far, they're probably not going to do this, but in theory, you could create a script that like goes through and loops through like all of the machines like in the device inventory and just isolate all of them. That's, that's a possible thing that you can do. Um, and the, I guess the foundation for doing that is in here already. You just need to figure out like a way to get a, the full list of virtual machines inside of Defender for Endpoint, 'cause it's possible to do it. It's possible to do that kind of damage here and at work. Um, so don't do it here and try not to do it at work. Um, but hopefully this makes sense. If you have any questions or anything, um, of course, let me know in the forums. Otherwise, we will see you in the next lesson.
So, no pressure obviously, but if you're serious about getting into cybersecurity or you just want real non-sandbox hands-on experience with actual enterprise tools in a live shared network, you can get all of that in the Cyber Range. In the past year, we've done about 100 employment verifications. That is like real employers reaching out to us to confirm experience for people in the community that have actually landed jobs. When you onboard into the community, you'll get issued credentials for access to our company's actual network, which is a real live corporate environment with over 200 users and fully licensed enterprise security stack with platforms like Tenable Vulnerability Management, Microsoft Defender for Endpoint, and Microsoft Sentinel. And just like at a real security job, we'll provide training covering everything that you'll encounter from enterprise vulnerability management to threat hunting to general security operations as well. And you'll get experience and training better than if you were hired as a corporate junior SOC analyst. Every week, we also have a cybersecurity threat hunt and capture the flag challenge where you can compete for cash prizes while building legit resume experience at the same time. And this isn't a simulation. It's like real infrastructure with real users, real attacks, and organic logs that you'll have hands-on access to. So, if you're interested, check out the link in the description, and we'll see you in the next video. Bye-bye.