Building Applications with ChatGPT O1-preview

Adal walks through building three applications with ChatGPT O1-preview: an HTML Snake game, a stock-price visualizer with technical indicators in Python, and a financial-news sentiment analyzer using the FinHub API. O1 outperforms GPT-4o on math, coding, and science benchmarks, but costs more and runs slower, so it's best for complex reasoning tasks.
Chapters
All right, all right, all right. I think we can go live. Hello. Hello everyone. I am so excited for this code along today or prompt along as we say. Given that we're going to be using ChatGPT01 to build some applications today. I am so excited for this one. Everyone do let us know where you're joining from in the chat and what you're looking to get out of today's code along. I've designed the code along in a way that we're able to, you know, use a Google Colab notebook to, to be able, able to kind of build a bit of a, a useful web app that lets us look at stock data. Right. And I'm going to get to that shortly. But if you have any other ideas that you'd like us to design in the Google collab today, let us know as well. Maybe we'll have time for it as well. I'm going to share screens and I'll get started. But already seeing here folks joining in, letting us know they're joining see Lydia. Hello Lydia. Where are you joining from? Indu. Same thing everyone do. Let us know where you're joining from. I'd love to show on stage like this one for example. So yeah, Artsam as well. Hello, great to see you. So I'll get started and I'll be keep a lookout on the chat to make sure that we, you know, showcase all the wonderful people that have joined here from all over the world. Really, really excited for this one and really appreciate everyone's time. So let's get started. So we're going to build applications today with preview and what I mean by applications. We're not going to be building mobile applications but we're going to be building useful, a useful tool for us that can be applied in a work context. So I'll get started here. People are joining in from all over the world. I see. So we have Bruno from Brazil, Margo from Canada, Confidence from Nigeria, Long from England. Lydia's joining up from Paris. Bonjour. Lydia lived in Paris for a few years actually. Indu from India, Raul from Cambridge. Oh wow. People are joining in from all over the world. Ken from Sweden, Chapel from South Africa. I think we're covering most of the continents by this time, so we have definitely Asia, Europe, the United, North America, South America. Right. Africa here as well. Zimbabwe. Rigid. Great to see you. We have Anita from Romania, Bunaziwa. Ayub. Bonjour for Tulmond, which means Good morning everyone. Great to see here. Amazing. We have people from all over the world. It's great, great to see again. It's truly a pleasure. And we have Sahil here from Australia and I think we're rounding out Constitution is joining from Antarctica. This could be a first but this could also be a troll so I don't know but awesome to see people from all over the world. Amjad from Egypt, Marhaba Amjad, great to see see you and yeah, amazing people from all over the world. It's amazing to see and very excited for this particular session today. So we're going to be talking about how to build applications with GPT01 with ChatGPT01, which is the OpenAI01 model. First, I'll give you a bit of an introduction about myself. My name is Adal, I'm VP of Media at datacamp. I host the Data Frame podcast. I help co organize a lot of these webinars and code alongs. I have the privilege to be able to work with such an amazing team here in the Meet the team to be able to create these experiences for you. And yeah, I'd love your feedback over how we can make them even better throughout the session. So what are we going to talk about today? I'm going to give a bit of an overview of why ChatGPT01 is a bit different than your usual ChatGPT, why the one model is a bit different than the usual GPT models. And a lot of ways it's in the name, right? You know, OpenAI created the 01 model. It's not GPT5, it's a different model. I'm going to show a few examples of coding use cases from ChatGPT01 and we're going to try out one in actually in production. Right? Right here we're going to build a snake game with chatgpt1 directly in HTML and then we're going to have a bit of time for questions. So if you have any questions before we start the prompt along, do make sure to ask them. And then what we're going to do because you know Data Camp, we're really focused on data skills here, right. I would like to build a web app in a notebook environment that lets you analyze financial data. Right. And what we're going to build is three elements of a web app. One that shows a price sticker, a kind of a price chart that we can edit and play around with for a few different stocks. Then we're going to go even beyond that and show a few additional measures, financial measures for a particular stock. Right. And then we're Going to build a pipeline that takes financial news data and analyzes sentiment for that data. And the outcome is just a data frame. A data frame, sorry, with a title and the sentiment of that article. And it's going to shows here to illustrate what is the art of the possible with tools like ChatGPT01. And then we're going to have a bit of a discussion on when to use 01 versus other models, right? And then we're going to have some closing notes in Q and A. Now this is. Someone just asked this. Constitution just asked this as well. To be able to prompt along. You do need to go on chat.OpenAI.com right? To sign up, sign in. I think most people should have a ChatGPT account, but given that we will be using O1 Preview today, you will indeed need ChatGPT plus or Teams or Enterprise to be able to access the O1 model. Right? If you don't have Zero1, that's okay. There's still a lot of value here for you. You can probably try a lot of these prompts as well. And GPT4O. Right. And then see how it performs as well for you. And I'd love to see your experience as well. Do you get the same results? Is 01 overhyped here? So with that said, let's get started. What is different about ChatGPT01 preview? So here it's in preview because it's still in a relatively beta model. But what is different about the O1 models? The OH1 family of models in general? So first I'll give some introduction and some background on how ChatGPT works in general in like large language models. I'm not going to go deep into the math one because I am not a machine learning PhD and to because I'd rather give the intuition here rather than go deep into the math. So ChatGPT and large language models in general are based off of something called the transformer architecture. In a nutshell, the transformer architecture is a type of model within deep learning, which is a type of artificial intelligence, machine learning, and generally at a highly intuitive level. There's a lot more that goes on in a transformer architecture, but there is three parts, three kind of ingredients to the transformer architecture. One is the encoder, the decoder and the attention mechanism. So the encoder, what it does is that it takes an input. So here for example, we're giving a use case of translation, right? You know, a sentence in English, it processes it and transforms it into a way the model is able to understand like a representation of language in a way. The model is able to understand, right? And it tries to capture the meaning of the input sequence. The decoder takes what the. The output of the encoder, right? Which is the representation of the sentence here, how are you? And turns it into the desired output, for example, translating the sentence into French or Spanish, right? And what the attention mechanism does, which. Right. Which is kind of the secret sauce of the transformer model helps the model understand the relationships between words and allows it to focus on different parts of both the input and output to be able to make really coherent and statistically likely meaning in the output. So here, for example, the input was how are you? The output was the Spanish translation of Como estas? Right? And then if you think about it, how it works in action when you work with ChatGPT, right? The model's already pre trained, right? So those encoded decoded relationships are already computed between the different data that the model has been trained upon, right? You prompt it. So here the input would be to the model and you know, can you translate this sentence into English, into French or Spanish, right? The model then looks at the relationships between the input and the output, given the desired output, and then produces that output, right? And a lot of ways, GPT stands for generative pre trained transform. I'm trying here to give a very intuitive explanation. So when you say something like translate hello into Spanish and you come out hola, for example, or where you say, write an essay on data science in the style of Shakespeare, right? Or transform this pandas code into R, right? The model is finding relationships between the input and output and giving you the most statistically likely answer here. So you can say in a lot of ways is that LLMs are next token prediction machines, right? They're not necessarily very good reasoning. So what they try to do is, is they take the input and produce, which is the prompt, and produce the output that is most statistically likely relevant to that input, right? Which is why in a lot of ways, large language models are not really effective at reasoning or agentic workflows yet. So, you know, big kind of release over the past year is the kind of tool called the Devin, right? Which was, you know, touted as an automated software engineer. It's able to decompose a problem into a small one and it's able to build, you know, a solution for an application, right? And this is not me trying to dunk on Devin, right? This is just a sign that the technology is not yet there, according to many experts. And People, right, Who have tried and reviewed this tool, right? And you know, you can see it because the underlying model that powered them or the underlying generation of models at the time also did not have strong reasoning skills, right? So you know, here you see that there's, you know, it's cut off. It's cut off for a reason. Because I'm coming to the next line, right? A GPT4.0, which is the best model available on the planet before 01 at the time, right? Or one of the best models, right? Between Cloud 3.5 and Llama 3 and all these things, right? You know, had a 13.4% accuracy on a math competition, right. 11% accuracy on a coding competition, right. And did 56.1% compared to a human expert that did 70% in answering PhD level science questions, right? And this shows you that LLMs are not necessarily great at reasoning, but they're just great at producing the most statistically likely answer given the input that you give it, which makes it prone for hallucination and wrong, wrong answers, right? It also, you know, who's noticed before when you ask ChatGPT to code something, it sometimes doesn't give you the most efficient way to solve a particular solution, right? So that's also, you know, a symptom of them. Now what O1 does is that it combines the power of transformers with something called reinforcement learning, right? To push us on that frontier forward of LLMs that can reason. Now, I'm not saying that we have cracked intelligence, but Owen does exhibit better capabilities to decompose problems into smaller ones and, and to be able to find the most effective solution for a given problem better than the previous generation of models. So reinforcement learning, what is this kind of to explain the intuition behind it as well? It's a paradigm in machine learning that allows to achieve, and allows an agent to achieve an objective in a given reward in a given environment to maximize a certain reward. A great example here would be like a chess playing AI, right? You have an agent which is essentially the software, right? It needs to solve, it needs to win a game of chess. It's trying to maximize its score given the environment and the move limitations it's in, right? And you know, in a lot of ways, for those who are, you know, more aware of this, the model that, the model that is responsible for, the model that is responsible for a deep mind winning the game of Go, right, is, is a reinforcement learning model. Now, the second aspect that makes O1 successful here is chain of thought reasoning, right? It's a technique that Breaks down complex problems into smaller, more manageable components. Right? And then they're able to use both reinforcement learning to be able to identify what are the most effective solutions given a problem. And then chain of thought reasoning which lets the model decompose big problems, small problems to effectively solve more open ended issues. Right. And then finally compute allocation. Right. So traditionally LLMs have been primarily focused on massive pre training data sets. So a lot of the compute goes to pre training, right? But O1 shifts the emphasis here towards the inference and training phases, right. So a lot of the compute allocation goes to actually producing the answer, right. Which is here train time. We see it here in the, the graph on the right, right. Shows the more compute given, the better the accuracy given at these phases. What that looks like in action for OH one is that if you say you give it a very famous puzzle like the Monty hall problem, what it will do is that it will think and it will try to break down the problem into multiple problems. And we'll see that in action shortly. Now, given that we've just discussed that OH1 is pretty good at reasoning, what that means is that it's much better at code, right? So we saw the earlier slide, what I had hidden here, these, these bars, right. On the math competition, right? GPT4O did 13.4%. O1 preview, which is the model we're going to use today, did around, did around 56.7%. Right. And then O1, which is the model that is not yet released, right? That's not the Preview version is 83.3%. Apparently on code competition, GPT4O did 1101 preview 62 and 0189%. Right. And the crazy one here is PhD level science questions, right? O1 preview did better than a human expert on PhD level questions, right. And weirdly did a bit better than OH one, which is interesting. That said, I feel like with these benchmarks there needs to be a, you know, a bit of a rigorous as well examination of how these benchmarks are done because we don't know if these models have been trained on the questions in these benchmarks because if it's trained then it will likely do very well. Now giving you a bit more here benchmarks compared to a lot other kind of areas as well when it comes to reasoning. Right. So 01 does quite a bit better on like math benchmarks, for example, right. As you can see here on the left hand side, right. Even does better on, you know, mentioned the PhD level science questions. It did a lot better on physics than Biology, for example, and then even on like calculus exams, the lsat, so on and so forth. A lot better as well, right? And you can see that mathematics is where you see the biggest gains compared to something like public relations or facts, right? For example, it shows kind of that reasoning aspect here as well. And so what I'm going to show, I'm trying to illustrate here some of those use cases. Everyone who doesn't have access to 01, maybe try this out as well in your own, you know, your model as well, see if it works, right? Maybe we'll be able to like kind of contrast and compare what works and doesn't work, right? But the first example I'm going to use here is I'm going to create an implementation of the Snake game, right? So my prompt here is, can you create an implementation of the Snake game? It needs to be an HTML and I need to be able to copy, copy it into a single file and run it on my personal machine. Don't use any remote assets. So here, what I'm trying to tell the model is that assume that there's no assets that are uploaded to the cloud that you can take advantage of, like images or something along those lines. And after opening the HTML, I need to be able to hit space to start or restart the game and provide me instructions on how I can run it on my own local machine. So I'm just going to copy this prompt here and what I'm going to do just to make it easy for everyone. I have this online tool just I Googled HTML editor online, right? That lets me render HTML on lunch so I can show everyone, so I just don't have to go through kind of downloading it and all these things, right? So I'm going to go to 01 preview right now, right? So this is it. If you want to access it on your own machine. Pick between these models. Again, you need ChatGPT plus to be able to access O1 Preview, right? But usually what you'll have is GPT4O. You can go to 4. I'm going to use 01 Preview for the remainder of the session, right? But there's also Meanie, which is a bit faster but less performant than OM Preview. And then there's other legacy models here that you see. So on Preview, I'm just gonna paste this right here. Can you create an implementation of the Snake game? Needs to be in HTML and I need. So let me just remove myself here from. Let's try to see. Yeah, yeah, that's great. Don't use any remote assets after opening the HTML it needs to be. I need to be able to hit space to start or restart the game and provide me instructions on how can I run it in my own local machine. So I'll just press it here. It's thinking and we can see here. So decomposing the problem. Right. Crafting the Snake game for local play in one HTML file. Blah blah. So I'm setting the rules for the HTML5 must be browser compatible and seal creator of any copyrighted material exceeding 70 characters. Crafting the Snake game okay, Constructing the framework. Coding the Snake game. Mapping out the game. I'm working through the map and initiating the Snake game. The player controls the Snake's direction with the arrow keys, so it should be directable with the arrow keys and start the game with the spacebar. And here is the completed code. I don't know HTML, so I'm not going to be able to review this very well. But what I'll do is I'll copy the code and we'll see if it works. So here, select all the code and above. And then here is giving me instructions on how to do it on my own personal machine. But given that I showed you that editor here. So all I need to do is just delete this section here and then paste the code. And then we see here we have a file with a score. So I press here. I'm going to press space. So it doesn't seem like it's doing what it's supposed to do here because I can't control it with the arrows. So here I'll just say I can't seem to be able to control it. Can you debug? Okay, So let's see what it did is that your collect is the arrow keys. The problem is likely due to the use of the Ekey code function which is deprecated in modern browsers. Instead we should use E key or eco detect key presses. Let's see if that works. So I'll copy the game again and I go back to my HTML editor. Seems like, huh, that is odd. Still not. Just make sure that's pasted in. Okay, I'll try it one more time. But then I want to make sure that we move on to the next set of questions. I have to say OM preview is not really impressing here. The arrows. The game needs to be playable. Okay. It's trying to test another issue here, See if it works. So what changed? Okay, Add game over flag improved reset function. Okay, now let's try again. I go Back here. Gonna refresh this page just in case there's any caching. See press space to start. It seems like there is. Seems that the issue is related to how ChatGPT here is coding in the state of the game, which is leading into bug. That said, we can definitely like solve this, but I want to make sure that we have time to build our application. Right. Funnily enough, it did work when I tried this exact same prompt 30 minutes before the code along. Another example that I'll show here of a tool is from someone on Twitter, for example, who used the cursor, AI, ID and 01 to essentially build in Swift, a weather app. Right. So essentially using only natural language of editing code and creating code. Right. This individual reached a point where he has a pretty stylish weather app, as you can see here. So while there is debugging that needs to happen here, right. The. The code being like the possibilities of prototyping applications is very, very interesting here. So here someone is saying tell it that it's doing that behavior upon trying it. The game stops each time I press space. Sarah Dawan is telling me to try. Okay, Let's see here if what we have changed. So. Still having the same issue. So we need to hear. You know, if I was an HTML expert, I'd be able to debug it myself. But this is the power actually the very good illustration as well of the importance of that it is breaking down here. Cool. So with that said, let's continue on with the actual prompt along. Any questions? Maybe first before we actually go along to the prompt along where we try to build a financial new financial analysis web app here using 01. Seeing some comments. So from mj, I think to make the app we need to use HTML, CSS and js. That is true. Trying to simplify as much as possible to be able to run it on HTML. And then yeah, I think we definitely like for this use case of the Snake game, someone's commenting here that it often happens that you need to like update like, you know, continuously have narrative loop. Definitely agree. We just need to be able to be mindful of time. So with that said, let's jump in to, you know, the meat of today's discussion, which is on building a financial analysis tool. Now we have two notebooks for you here. One of them already, you know, I've tried the same prompts and you can see all of the code right. That we built. So all you need to do is just run this notebook to be able to see the code that Came out with a one the what we're going to try to do is also do it from scratch. And here we're going to. If we ever have bugs, we're going to try to debug the. The. The code to be able to code along as well. What you need to do, you'll have access to this notebook. You to be able to press file and save a copy in drive and that way you'll be able to code along yourself. Right. We will be using an API public API for something called FinHub. I'll make sure there's instructions at the bottom how to use the API as well. So once we reach that point though, we'll get to it. Now that said, the first thing that I want to do is a stock price visualization tool, right? So what we're gonna. The prompt that I'm gonna use is. So maybe I'll first show it here. I would like to build a stock price visualization visualization tool using Python. The outcome of the application needs to be an interactive visualization that is embedded in a Google Colab where there are two dropdowns, one for a given stock and one for different time horizons. So 1 month, 3 months, 6 months, etc use matplotlib and seaborn for the visualization and Yahoo Finance to access the data. Please provide me detailed instructions on how I can paste the code into a Google Colab. So I'm going to go here to a new ChatGPT prompt, a new chap chat going to open preview. I'm going to paste in that prompt and then we'll see what we get out of it. So here it's going to create an interactive spot for app to tie using matloclib and Seaborn embedded in Google Colab with a dropdown for stocks and Time Horizon. I'm detailing how to establish a Google Colab environment import libraries. It's going to utilize IPY widgets for interactivity which is great for a notebook environment and fetch stock data from Yahoo Finance and then plot using matplotlib and Seaborn and employee widgets for selecting stock and Time Horizon. I'm organizing a step by step guide for for how to open the project in Google Colab. And what I want to illustrate by this is that by asking it to do a step by step guide here on how you can use Google Colab Even if you've never used a notebook, you can suddenly have a tool that helps you guide you along the way, which is really great. So first thing, open Google Colab file new notebook we already have a new notebook and then we need to install our library. So I need to install Yahoo Finance, I need to import MATLAB, Lib, Seaborn, SNS, Pandas, SPD, DateTime, IPython display and IPY widgets, right? So here it's helping me define a few stock symbols. So that's step three. So my stock options are Apple, Microsoft, Google, Amazon and Tesla. And then we have a one month, three months, six months, one year and two year time horizon, right? So here it's giving me instructions that I'm pasting this code into a new song, running it, right? Then it's helping me create a drop down widget. So here with IPY widgets, so I have widgets dot dropdown, we have the stock options which are in this list and the value is the default value is Apple. And then we have the time horizon dropdown, which is the same thing here. And it's using the keys, right? And then here what it's doing, it's defining functions. So it's defining a function to fetch and plot the data. So first thing is plot the stock data. The inputs are the stock symbol and the time period, right? So the end date is always today and the time between difference the delta days is the time period input, right? And then start date equals end date minus time delta, okay? Then it's fetching the stock data, it's resetting the index of the data and then it's plotting that data and then it's creating an interactive output. Okay and then it gives me the entire code here to be able to copy. So I'm going to copy this entire code. From a high level it seems like this first set makes sense in Python, but we'll see if we get any errors, but we'll be able to troubleshoot it. So we'll go back here, I'm going to use code, right? And I'm going to put in a few blocks of code here, right? So first thing I'm just going to install any relevant libraries. So first thing I'm going to run this, it's running in quiet mode so it shouldn't get a lot of output. To be able to run a cell, just hit shift enter or press run on. Here. Ah, this display button here that you see. That's right. And then here I'm going to import the libraries, right? So I'm going to also put this in another code cell just for the cleanliness of it all because if I run it over and over again it doesn't need to be rerun. So all of my libraries have been imported correctly. Then I have the list of stock symbols here and I have the dictionary of time horizons. We created the drop down widgets, we created the timed object widgets, right? And then I'll put this as well in another code block. So here it's like we're defining kind of the inputs, like kind of the, the base, the building blocks of this code. Then here we have this function that we've defined that lets us fetch data and visualize it. And here we're just displaying our interactive plot. So let's see if it works out and how it ends up looking. Actually it works relatively perfectly. So I have Microsoft here that's also changing, right? So let me zoom out a bit so everyone could see it. I go back three months, six months. So you can see here one year, correct. In two years, what a good time to hold Microsoft stock, Google as well to your horizon. So here a question from atia. The visualization will be as good as the one generated by Power bi. If so, can it replace POWER bi? So I think the two questions here, we always have the capabilities to update the visualization. So one thing I can do here right now is try to update only the plotstock function, right. To set a better style. And I'll actually ask ChatGPT to do that. But then can it replace Power BI? Well, here it's also a question of usability and the stack that you have within your organization. So here we're working on publicly available data, right? But if you're working with your own data connections within your own organization, right. Then probably like connecting it to POWER bi is easier in this context. If you already have data models. And then I think Power BI will, you know, it already has copilot, but it will get better over time as well. And you'll be able to build these visualizations with natural language like I just did encode, but using POWER bi. So what I'm going to do here though, to answer your first question on can we improve the visualization? So I'm just going to say a great job. The visualization worked. But I would like to improve the aesthetics of the line chart and the following function. Can you make it a bit more aesthetic by so what are ways that we can make this visualization a bit more aesthetic? Removing grid lines, making the line chart a bit thicker. And adding a label. So here we have closing price and day and then and aligning the the title of the chart on the left hand side of the visual. Question here from Violo. Does Google Colab and Jupyter Notebook work the same way. Generally, yes, you may have to install some stuff on your Google Colab. So here it updated the function. So hopefully if I just update this, the entire code should remain the same. So here we just updated some formatting, right? So what it's done, it set the style to white, remove the grid lines, made the line thicker, align the title to the left, and then let's see. Okay. Yeah, you see it here, right? Gold stock price, so on and so forth. Right. You know, the possibilities are endless here. You can give it your own color scheme, you can give it your own font potentially. Right? There's, there's a lot that you can do here. Now the next thing that I want to do is I want to refine this visualization tool to also include some useful measures that a finance team would use here, right? Like simple moving average, for example. So here what it does, calculates the average of selected range of prices, right. And then. Or exponential moving average or Bollinger bands definition. Right. So I'm not a finance expert. If there's a finance expert here, please do point out if my definitions are wrong. Right. So exponential moving average gives more weight to recent prices, for example. And then Bollinger bands are essentially two outer bands that set two standard deviation above and below the price. Right. And they measure market volatility. Right. So what I will do, I will now say. So if I go here to ChatGPT, so I won't actually include the definitions of these measures. I'll just say, can you help me update the script by adding date pickers for custom data ranges. For custom data ranges, sorry. And the drop down for different indicators to visualize, please provide a simple moving average, exponential moving average, and Bollinger band. So I'm not only adding additional measures, I'm adding custom date ranges. So I'm able to. Want to be able to do it from one day to another, choose my dates as well. So let's see how it does. So adding date pickers here. And a drop down for sma, EMA and Bollinger bands. Updating the strip to swap the time horizon with date pickers. Okay. Okay, Let's see how we're doing. First step, we already have all of our packages, so I'll just also start building the code here. I'll come back to the ChatGPT. I just want to make sure that we. Okay, so we already have Y Finance installed. I'll just paste the library imports. I think all of our libraries are still there minus as well. I think what we're missing is I'll just keep them as is. But usually what you want is to consolidate all your library imports from the beginning. Then we have the stock picker. Okay, so same thing here as we did. Stop, drop down. Now we have the start date picker and the end date picker. So and you can see there are widgets, date picker. Right. So these are specific widgets. Now we have indicator drop down. So closing price, simple moving average. And there is a drop down here. Now what it does is updates the plot function, right? If start date above end date, start date must be. It returns an error. So I already caught that. And then if data is empty, then no data available for the selected date range. And then if the indicator is SMA, then you do a rolling window 20 on the close price of with a mean, right? Then if the data indicator is exponential moving average. And then we have the AWM function that we're using and we're using mean. And then if it's Bollinger bands, we calculate the simple moving average, we calculate the standard deviation, and then we define the upper band and lower band. So it does seem like statistically speaking, like, like the finite. Like from on the fundamentals we are doing this correctly. And then we do line plots here depending on the indicator, and then return title labels, so on and so forth. So what we'll do here. So it seems like what only things that have been updated are the. Actually I'll just paste the entire code here if it's easier. So this is the full updated code, right? And what I'm hoping that I'm able to show with this process or kind of this workflow that I'm using is that I'm building a V1 and I'm improving on the V1, and then if I can further choose to improve on that V2 that I built. Right? So here, stock dropdown, date pickers, then indicator widgets. So these are the widgets all defined here. Then my function is here and then my displayer is here. So let's import the packages. Most of them have already been imported already. Now I'm defining the stock dropdown, the date and the start date and end date picker and which indicator I'm using. And then I'm plotting my data with these functions, right? And now I'm displaying the visual. Okay, so now we have closing price. So what stock I'm using, what is the start date? Okay, it seems like the first error was maybe due to the same dates being used. And Then I'm changing my measure. Simple moving average. You can see it here, right? Exponential moving average. Moving here, Bollinger bands, you can see upper band, lower band. I just want to ask the group here, if you are doing this in Excel, how much time would this take you, right? It would take quite a bit. Now I want to try to build something new here. I'm going to deviate away from my, from the use case that I'm building and I'm going to actually look at another source of information that I would, you know, that hedge funds usually use, which is, you know, what is the sentiment of financial news about a given stock? And we're going to use a free API, and when it's free, it means it's not going to be fit for purpose, right? We're going to use something called FinHub. To get the FinHub API, all you need to go is, oops, sorry, not this link, but Finhub IO. Just go to Finhub IO, then get free API key and then put your email and you'll get an API key, right? And then you'll be able, you'll be prompted to ask your name, email and password, right? Then you copy the API key that you get. Then you come back to the Google collab, right? You'll press, on this key button, you input the name of your API key. So here I'm calling it FinHub API. And then the API key, you paste it into here and then make sure that provide notebook access, right? And then to be able to get your API key, you just use this function here. I'll show you how to. I'm defining it as FinHub underscore API equals user data get. And what I'm going to do is get. You know, the free API allows us to only return one stock and five news stories about that stock. And given that we're only looking at titles, not the content of the articles, sometimes we may get, you know, titles that are not necessarily related to the stock, but the content of the articles may be related, right? So I'm building something very simple here. It's not going to be necessarily extremely useful, but it also shows the illustration here that I'm trying to do. So I want to build a simple financial news sentiment analysis bot that analyzes headlines from financial news articles using the FinHub API. The outcome needs to be a data frame with four columns. The stock, the date, the title of the article, and the sentiment. So I'm just gonna paste. Copy this prompt. Okay? I'm gonna Paste it here. Right. I'll remove the the link here just to not create confusion. And let's see how it performs. Okay, So it's going to use nltk, okay. Which has like out of the box functions for sentiment analysis. So here it's really interesting, right? I'm piecing together a strategy to verify code accuracy and reliability, particularly for factual correctness and avoid avoiding hallucinations. This approach boosts the quality and reliability of the assistant's output. So it is the assistant. Okay, so it's telling me what I need to do. Go to finhype IO login. So I need to make sure that I have requests installed. That's my first step. Now I'm importing my libraries. So here it's telling me put your API key equals your finhub API key. Right? I'm just going to paste here this code from google colab. User data. Finhub API equals user data. Get finhub API. So here fetch news about the stock symbol from the last 30 days till today. The URL comes from the stock symbol. News from day to day token equals API key. That seems to make sense. Get the response URL. If else fetched failed to fetch news, then we do another function to analyzing sentiment. So if I go back, So if you notice something, I'm going to do a bit of an edit here, right Here it says API key, right? I just need to replace this FinHub API API key. And now it should work. Function to analyze sentiment. So this function here, what it does, creates a sentiment intensity analyzer, gives a score for a headline and then provides the compound score. So here this gets the. Creates the data frame. So what I'm using here, so I fetch news for the stock symbol. So for Apple, let's say and then for any article in the list here that is generated, we get the time date, we get the title, we get the sentiment, whereby analyzing the sentiment and then we append the stock symbol date and then we return it as a data frame. This does make sense. And then let's test it out. Let's test this entire system out. Stock symbol equals Apple. I'm getting the new sentiment for the Apple stock and I'm going to show the first five rows. Actually I'm going to show all of it because it's all going to be five rows, I think. Okay. Actually no, I'm getting 223 rows. Amazing. So. You can see it here. So just do it. Brand name. Let's pull up, pull this up. Just do it. Brand name Lessons From Nike's troubles. So Nike's troubles Sent them in 0.5 According to FinHub, this is somehow associated with the Apple stock because if you look at the the URL it has company news symbol equals stock symbol. So we're only filtering for the Apple symbol and we're this news seems to be tagged based on Apple, right? Then why Apple stock is trading lower today? Negative sentiment, right. Apple falls as analysts debate iPhone demand trends Negative sentiment. So in just two minutes we were able to build a sentiment analysis spot that gives relatively not bad signal to noise ratio. Right. Where we're able to get Apple news that is relatively useful from a financial services perspective. Right. And this really shows here the powerful of the power of kind of using a copilot like that for a coding use case. Now someone do ask as much questions. We're going to have questions at the end. We're probably going to be running a few minutes late. Someone asked is it necessary to use Google color? Is it better to run a local environment? So it really depends. I'm using Google Colab just to get be able to give you access to your machine and then Viola. Does Google Colab and Jupyter Notebook work the same way? I feel like Colab has a few additional functionality like because it's cloud based and on your local machine you probably have a lot more control over how you install things, what you install. So maybe some stuff doesn't work out from today because of like installation or versions. Okay. And with that we built right. A system in less than 30 minutes, a tool in less than 30 minutes that visualizes gives our stakeholders the ability to visualize stock data and price data across different measures. Right. And then gives us an overview over sentiment of Apple stock. Right. And what I want you to think about here, if you are able to use your own organizational data or your team's data in this context and provide visibility, create a web app that is useful for your team. Think about what is possible here. And with that said we can transition to the next section which is when to use O1 versus other models, right. I think there are some important consideration, right. So latency, how fast do you want the responses to be generated? Right. So for example, if you're building a chat bot that answers simple questions like what is one plus one? Long latency is probably bad user experience here, right? Complexity like how complex is the problem if you're using. If you're just writing a draft for an email, don't use a one here, right. And then quality of response of Responses, you know, how accurate is the model? Like, is 80% of the time good enough or should it be 99% of the time? Right. And then just to note here, all models hallucinate. You saw, and the kind of we start off on a bit of a bad foot with 01 didn't work out with the Snake game. Right. And then this is specifically for the API, right? But also, you know, you saw here to be able to access someone, you need a team, a subscription. Especially if you're using the API to build a, you know, a system, right. O1 can be extremely expensive compared to other models. So use O1 if you care about high quality responses. The tasks are pretty complex and open ended. You don't have inference consideration, so you can wait a few seconds on a response and you can afford it for your application. If this is API based, use 4o or below. If you can settle for high but not the highest quality responses. Your tasks are relatively simple, you need the answers fast and you care about being cost effective. This is an API focused consideration. Okay. And with that, some closing notes in Q and A. You know, I showed this with the Snake game, right? I showed this while looking at the API key and fixing it. Even as models get better and you need to edit less, never forget the importance of a human in the loop. It's extremely important to edit and own the outcomes from the the model. And then as we look at generative AI and the future of work, right, there's always, you know, big chatter about, you know, how AI is growing to be more of an existential threat to the species. Right. And while I don't think that we have reached that yet. Right. I think it's also really important to think about what the future of AI looks like and how we can work with AI effectively. You know, there are two visions that are being painted here. The first vision is that of existential risks and terminators destroying the world. And the other one here of a useful robot helping a construction worker. And if you look at what we've done today, we worked with an automated system to build something we want built. Right? What was automated was the task of coding, not the outcome or the benefits or how we can approach the problem here. Right. And our own guidance is also extremely important. And so when we think about the real risks of AI, especially the real short term risks, it's something like scalable misinformation, right? You know, here's a picture of former President Donald Trump being arrested by a bunch of police officers. That did not happen or you know, scalable bias perpetuation here and this is a very early version, I think ChatGPT 3.5 here, where someone asked ChatGPT to write a function to predict seniority in a role based on race and gender and you can guess what was the response. If someone is a person of color and they're female, returns junior if it's a person of color and male mid level if it's white and female mid level if it's white and male senior right? Else return junior. Right. So what are the implicit biases that can be encoded in the solutions that we're building depending on the use case, Right? Maybe if you're building a financial news analysis tool, there's no room for bias, right? You're analyzing stocks if you're working with healthcare data, if you're working with demographic data. These are all important aspects here. And then scalable secure cybersecurity risks and threats, right? So for example, if you ask ChatGPT to write you an email from a Microsoft account services asking for a password reset, it can do that. So that's something to think about here as risks of these systems. And with that some principles for success in this time of innovation. Embrace change, use it for your own advantage, right? Beware of the real risks and become a more digitally engaged citizen. And tools like ChatGPT and generative AI can really augment the roles of today and will transform them for the future. And with that I'll be super happy to take some Q A. I really appreciate those who are sticking extra and totally appreciate if you have to leave now, we make sure to send over the recording and I hope you were you found it useful. So another question that we had here from Atiya. The visualization will be as good as the one generated by Power bi? If so, we already answered that question. But then here, if I have a choice with which one I should go for, should it be ChatGPT or Power BI? Well, it depends on how you want to share it, right? Do you want to share a dashboard with your stakeholders that everyone can access? Right. I think here Power BI is useful. Then John, is it necessary to use Google Colab or is it better to run it on local environment? It's really as you wish. I used Google Colab just to be able to show you and share the code. All that is Copilot a separate feature compared to ChatGPT1 preview it is. Copilot is from Microsoft on the Windows machine. ChatGPT is owned by OpenAI and Copilot can be used also for Power BI and something along those lines. So different companies but using the same technology. Bruno Vansen what sentiment. So sentiment is like whether, you know, if you look at here whether the title shows a positive sentiment or a negative sentiment. So if Apple for example is trading low today, that's a negative sentiment. So and you see here it's minus 0.296, right? So for example Apple iPhone 16 availability suggests weak demand by Barclays. So that's a minus 0.5. So I think it's from minus 1 to 1. Minus 1 being the most negative, 1 being the high, the most positive. How does O1 compare to Claude's AI model? So I think on O1 on raw reasoning tasks is better than than Claude if I'm not mistaken. But what I do love about Claude's the artifacts feature. For those who are not aware of that, highly recommend that you check out this article that we have. So I'm just going to Google it. Data Cam Cloud 3.5 artifacts. Yeah, Cloud artifacts 101. So really beautiful. So actually I'll share my screens here. Really beautiful feature in my opinion that really kind of transforms the user experience of a chatbot. And what artifacts are essentially are is you know, you're coding here, you're chatting and chat and Claude and then it lets you render an application in real time. So you saw what I did with the Snake game. I copied it, put in HTML. Claude has its own HTML rendering engine and like React rendering engine. So for example here someone said, you know, can you create. Yeah, so that's here, create a presentation with the information above. It's able to create a slide deck, right? Using React, can you create a visual and it's able to create like an interactive visualization, right? Can you create an SVG graphic? Right. Can you create a website? You're able to browse the website. So it's a really beautiful in my opinion feature and it would be crazy if OpenAI doesn't build something like that. Another question here, in which domains you recommend to use 01 instead of ChatGPT4? Here said 04. I would say that anything that requires like complex coding I would use 01 for it. Am I working on any personal projects using O1 at the moment? Anything you'd be willing to share? Actually I'm not. I'd love to, but my full time job takes. Takes all of my time. But that said, what I use 01 for a lot is to build a lot of our own internal reporting on the media team. So whether we've created a lot of internal dashboards using Python that connect our own data that have really changed the game with how we make decisions and create a visibility over things we haven't had before. So here how good is Collabs option for us to use generate AI to code for us? So I think it's using Gemini and Google Colab for example Data Camp Data Lab is we also have a tool similar to Google Colab here and we use GPT4O I think pretty solid performance but you're not going to see that same level of like breaking down tool complex code into multiple problems and you know, the way that O1 approached it. Another set of questions here. Can you suggest a few other use cases for A1? I would recommend using A1 as well for areas that you're not necessarily used to such as, you know, building maybe applications or learning how to build swift applications for iOS, right? Because what's really impressive about O1 is that if you tell it I am a noob, give me detailed instructions over how to deploy it, how to like run it, what should I install, what should I not install? It will actually be very helpful here and I think this wraps up today's session. I'm really sorry we went 10 minutes over time. That pesky Snake game took a lot of time to debug and we still haven't debugged it. But I want to say a huge thanks for everyone who attended today's session. It's been an honor, a privilege, really, really appreciate it. On to the next one and I'm very excited about what we're ahead. We announced datacamp Radar Forward Edition today. Make sure to register for that one. I'm also very excited for the upcoming set of code alongs and webinars we have, so stay tuned for those. And with that I'll give everyone.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







