
In this video, I demonstrate on how you can quickly set up and integrate custom api endpoints as GPT Action's within OpenAI's new GPT interface which allows you to create custom chat bots. In this example I will show you how to get up and running by setting up an example as a rudimentary financial analyst by giving it access to an endpoint of 3 months of financial data. I will be using Polygon.io in the example as well as ngrok to help with local development. Repo coming soon... Links: https://openai.com/blog/introducing-gpts https://ngrok.com/docs/http/ https://polygon.io/ Support the channel: Patreon: Support me on Patreon at patreon.com/DevelopersDigest Buy Me A Coffee: You can buy me a coffee at buymeacoffee.com/developersdigest Website: Check out my website at developersdigest.tech Github: Follow me on GitHub at github.com/developersdigest Twitter: Follow me on Twitter at twitter.com/dev__digest
--- type: transcript date: 2023-12-01 youtube_id: -ceIJx7zaBM --- # Transcript: GPT Actions: How to Integrate APIs Into OpenAI's Custom GPTs in this video I'm going to be showing you how you can set up your own GPD actions where you'll be able to integrate information from your endpoint I'll show you how to map that schema to your endpoint and spin up a quick example to get you started with how this works so gpts if you're not familiar so gpts were just released during open a Dev day and essentially what they are they're like a customizable version of chat GPT so say if you want to make a specific chatbot to a specific feature or implementation or an idea that you have you can go ahead and generate that so there's a handful of examples here like creative writing coach laundry Buddy game time in this example I'll show you a sort of rudimentary and starter example for something like a financial analyst now this is going to be a very crude example but it's going to get you hopefully going and showing you sort of the core components to get started with us so if you have uh access to the new GPT editor go ahead within the editor create a new GPT and we're going to start this completely from scratch here so once you have uh gone into here what we're going to be doing is essentially setting up a basic endpoint so we're going to be quering for some stock data so all of this is things like the opening closing price of Apple's stock data we'll be able to pass in any ticker and what we're going to be doing to be able to interact with our Local Host is we're going to essentially be putting something called enro in front of it so this will allow us to essentially serve our Local Host to make that local development a lot easier so instead of continually having to push something to like for cell or AWS if you're using Lambda or something like that this will allow you to essentially develop locally but have the nicity of having a server that you can actually query so both of these services and what I'm going to show you in the example you will be able to access for free uh there are free tiers that are quite generous for both of them so for an example like this you will be able to get up and running so without further Ado so head over to the enro site if you don't have an account already go ahead and make one and also go to polygon doio and create um a an account so also if you don't want to make accounts for this you'll get sort of the general Sense on how to set this up so I'm going to be setting this up in bun or node.js so for JavaScript developers this is sort of the the focus here um I'm sure there's going to be lots of python content on something similar now the thing with this is what I'm not going to show in this video is if you actually want to deploy this you could use something like I mentioned versell or serverless is really good for deploying Lambda functions on AWS but it should be very simple to deploy what I'm going to show you and all of the code I'm going to have within the description of the video where you can link out to the GitHub and pull it down and use whatever you want uh from it so um the first thing that we're going to do is we're just going to open up a new directory and I use bun init Dy to start all of my projects so this this will allow you just to have a simple uh index.ts it will have the sort of Base uh boiler plate for starting your project so once you have that installed we're going to have one dependency so we're going to bun install Express so we're going to be using Express for our server I know we could use bun directly but I think Express is probably more familiar to most people on the channel so once we have that you will need to put in your API key from polygon so once youve made an account just go to this settings page I believe it is or your account page plug in your API key just like you see here and then essentially what we're going to be doing is uh two parts mainly So within our interface uh we're going to go ahead and generate some of it so I'm going to say I want you to be a financial analyst chatbot and let's just start with that it can sort of run in the background as I'm running through some other things it will start to sort of generate the B boiler plate for our chatbot here and then we'll go in and set up our API So within your index TS you can go ahead and open that up I have a handful of comments here just running through the basic example of plugging this all in so the first thing that we're going to do is we're going to import Express um and then from there we're just going to initialize Express we're going to set the port to 880 you feel free to set this to whatever you want though then we're just going to have the endpoint be the base um route so we're not going to you could put it like something like SL whatever but in this case we're just going to leave it as the base URL so here we're going to extract the query so this symbol is going to be what we're going to map within the schema of our GPT action so this is going to be what gets passed hopefully as a payload to our endpoint so we're just going to do a little bit of error handling to make sure that a symbol was actually sent otherwise it's just going to send that message back to the GPT and let let it know that a symbol is required so here we're just going to reference our API key if you're using something like bun you don't need to install EnV if you're using no just make sure to install something like EnV and set that up to be able to access your API key so here we're just going to specify the current date and the reason that we're doing this is we're essentially going to get the last 3 months now the reason that I picked the last 3 months is it's approximately 3,000 tokens so I believe it's around 4,000 tokens within the offering that you can pass in within the chatbot each time so for instance if you try to get a year of data which I did try in setting up this video that context length is going to be too long so that's why I put three 3 months it sort of gives you about 3,000 tokens so it gives you enough for your message and the data that's being sent so you're sort of you sort of have a safe margin there with 3 months so then we're just going to format the date uh for what polygon accepts for the date range here so see we have 3 months ago and then we have the current date we have the symbol that we're passing in and then we're going to be passing in the API key so the other thing with polygon there's a number of different end points that you can interact with so say if you don't just want historical data there's a number of different metrics that you can get from their API both a free tier they also have some really good uh professional tiers that I encourage to check out if you're interested so here we're just going to wrap it within a try catch and then we're actually just going to make a fetch request so we're going to say okay if there's not a okay um response we're just going to go ahead and parse the data and then we're going to check the data to make sure that there is a payload that has been sent back so an instance where maybe it wouldn't send back a valid payload is in um you know maybe you're passing in an invalid ticker or something like that then from there we're just going to send that response right back to the GPT so you could do things like if you want to parse it a little bit maybe you only want certain values maybe you want to be a bit more descriptive with the values maybe you want actually make the the keys like volume and opening price and whatever you could do that um if you want to experiment it uh with it like that but that's pretty much it then we're just going to catch any errors and then we're just going to listen for the port so I'm going to go ahead and save that out and then you can just go ahead and Bun index so that will go ahead and start your server on the port 8080 so once you have enro setup just go through their setup uh steps and then you should be able to just run the enro HTTP 8080 command so once you're all authenticated from your CLI you can just go ahead and run that and so that will essentially create this um um sort of mirrored version of your Local Host where you'll be able to access it so just go ahead and run that here and the nice thing with it so you both have a SSL certificate and then you have one without so I'm just going to use the one with the SSL now this screen I'm going to touch on for just a moment so you can't just plug in the endpoint URL directly you're going to have to take one of these steps so I'm going to show you the first uh step here the enro skip browser that's what I found to just to be the easiest most straightforward this will essentially allow you to bypass the screen so if you just Tred to directly uh go ahead and ping this URL is it will send back a payload of this page itself which is no good for us right so we want that valid uh Json to come back just like this so if we take this URL and if we just head over to configure for a sec now let's go back to to actually before we go into configure let's just answer a couple questions here we'll say sure that's Financial Guru is going to be the name we also see that it generated some prompting questions for us it has sort of the subtitle or or title of the actual uh bot here and you can actually see all of the things that it generated for us just from that basic prompt uh of setting it up so in this I'm going to turn off web browsing and Dolly and in within the create action that's where we're going to be doing most of the work here so here we have a photo do you like it let's say yes and we'll just sort of let that run in the background So within our create action uh we'll just ignore that I'm sure that should hopefully be all right maybe I should wait for this to finish okay so within our create action there are some examples so I'm going to be basing it off of this weather example here so I have this exact example just within a Json file on the left hand side here and what we're going to be doing is we're going to be using really close to the boiler plate so you can start to tweak and build off this but I wanted to keep the example very simple so here this is the weather endpoint so this isn't a real endpoint weather. example.com does not exist so if you try to query it it's just going to eror out now essentially what I did is I just went through and swapped out all of the descriptions uh for the things that you need like the query parameter what the actual function does so that the GPT model has the context of how and when to invoke that GPT action so you can sort of go in here toy around with this so in this I just I took sort of 30 seconds to run through this so retrieve the past 3 months of stock data for a particular stock get the last three months of stock data for a symbol and then a valid symbol for a publicly listed company so just to make sure that it's um trying its best to give a valid symbol so I haven't had it hallucinate yet but you likely could if maybe you you know put on some madeup company names or whatnot so for our URL that we have here um you can go ahead and put it within like you see here and just make sure that there's not a slash or anything when you put it in so I'm just going to make sure that this is the same endpoint that we have here okay so once we click visit site that should go away okay so here we can just copy this portion we're going to put it in here it was slightly different from when I was testing this earlier and then now once you have this you can go ahead within your GPT action you can paste in that schema now if you go ahead and test this I'll just show you the error and the first thing that you'll have to do is if you're testing new endpoints you will have to allow them so just go ahead and test it again here so you can see the responses so it is a little buggy it's obviously still new there's obviously a lot that have has gone on at open AI recently so I'd imagine this will improve pretty quickly over time uh okay even the responsiveness is a little bit broken but if you look here this is that response data so that was that page that I showed you where it's this essentially so to get around that so here it says you can set and send the enro skip browser warning uh with any value okay so now once we copy this over we're just going to go ahead and put that within the authentication tab so I'll just highlight this here and copy that to my clipboard I'll head back over here so I'm just going to remove this slash here that I didn't remove on the previous screen before pasting it in here and then I'm going to go within the authentication tab of the API key so just go ahead and go to API key then click custom then put in that inro skip browser warning and then you can put any value within the API key so it specifies you can put any value there it's just looking for that header name so you can go ahead and and test that and then I can go ahead and say what has Tesla stock done in the past couple months so on the back end what it's doing is it's taking that natural language query it's looking to those GPT action schema descriptions and seeing if there's a match so here it sees that the uh request was for Tesla it knows the uh symbol or the ticker is TSLA and if we look at the response that was received you can see all of that data that was being sent back from our endpoint so here it's it's telling you just some sort of high level information based on that data so you can ask specifics so you can say be more specific with the values now I'd also encourage you instead of just taking the base generated boiler plate for the GPT go in there refine it tweak it over time those are essentially system promps that are weighted higher for when you go ahead and query it so anything that you put in within the actual description of the GPT it should be rated really weighted rather really high uh in the responses that you get back so here you sort of have a high level overview now that's pretty much it for this video I just wanted to show a really basic example on how you can get up and running now obviously you don't have to use a financial endpoint you can use your own endpoint of whatever you'd like um or whatever you already have implemented um you just have to get used to mapping that schema now the other thing I'll mention is you can also set this up with a yaml file if you'd like um but there's a lot of different flexibility there so hopefully you found this video useful if you did please like comment share and subscribe and otherwise until the next one
Weekly deep dives on AI agents, coding tools, and building with LLMs - delivered to your inbox.
Free forever. No spam.
Subscribe FreeNew tutorials, open-source projects, and deep dives on coding agents - delivered weekly.
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.