We can teach an AI model to better understand the information we want to generate responses from. To do that, we can use training data in a particular format, JSONL.
Once we have our data generated and uploaded to OpenAI, we can now use it to fine tune or customize a model to provide better results.
We'll use the training data we generated and uploaded in previous lessons to create a new fine-tuned model based off of the OpenAI davinci model.
Man: [0:00] Once we've uploaded our training data and received a file ID, we can now use that to create a fine-tuned model. To do this, we can use the createFineTune method and simply pass in that training file ID in order to start that process.
[0:13] To start, I'm going to create a new script inside of my directory called create-fine-tune. Inside, I added some boilerplate code, including requiring my environment variables, the OpenAI SDK, configuring that, and creating a new instance of the OpenAI API.
[0:27] To get started, I'm going to simply copy the snippet, including the createFineTune method. I'm going to go ahead and paste it inside this asynchronous run function, which we'll immediately invoke. The only thing we need to do is make sure we update the training file to our file ID.
[0:40] In the previous lesson, we uploaded our training data and we got that file ID. I'm going to go ahead and copy my previous ID and paste it in as my value.
[0:48] If we look inside of the documentation, we can see that we have a few options for what we want to do in order to create that fine-tune, where in particular, we want to look at the model, where by default, it uses Curie.
[0:58] When selecting which model we want to use, we're currently limited to a specific set of models. Particularly, we're going to use Davinci for our use case.
[1:05] The only other thing that I'm going to do is specify my model and set that to Davinci. Once that response is complete, I want to make sure I can see the results. I'm going to console.log out the response, but in particular, I'm going to log out the response.data.
[1:18] Now when I run that script, we can see that we get a lot of information in this response. There's a few things that we're particularly interested in, where we see we have this ID, we have our model that we trained this on, we even have our training files which we referenced.
[1:31] We want to look at the status and the events that are occurring. Creating a fine-tune is not a synchronous process. That's going to take a little bit of time for it to finish. We can see that our first event is simply creating that fine-tune.
[1:43] We want to check on the progress of that fine-tune, including checking the status of it, make sure that there were no errors, but specifically, we want to make sure we can know when it's available to use.
[1:52] Like we did with the file, I'm going to first copy this ID so that I can reference it, and I'm personally going to store it inside of my script. What I'm going to do is I'm going to duplicate this file and I'm going to say, I want to get a fine-tune this time.
[2:04] If we look inside of the documentation, we can see that to retrieve the fine-tune, we can use the retrieveFineTune method and simply pass in that ID. Just as another option, we could use the listFineTune methods if we want to check a bunch of our different fine-tunes.
[2:19] For now, we're just checking the status of one fine-tune, so we're going to use the retrieve method. What I'm going to do is replace createFineTune with retrieve, I'm going to copy that ID and replace that object with my fine-tune ID.
[2:31] If I run that script, we can see that I have updates inside of my events, including how much that fine-tune's going to cost, which is going to be 11 cents in US dollars. We can also see that my fine-tune was enqueued.
[2:44] Now, at this point, creating the fine-tune might take a little while. It might depend on how busy it is. It's not going to be something that's going to happen instantly. It's going to be a little bit before you get that successful response where you can start using it.
[2:55] We can even see that if we run this script again, we might have different results, where this time, I can see that my fine-tune has started. If I run it again, I can see the different parts that were completed, and I can even see that my model was now uploaded, where I have that ID that I can now use.
[3:10] This Davinci variation is going to be the ID that I want to use, where that's going to be the ID of my model. Like usual, I want to make sure that I store that ID somewhere that I know I can use whenever I want to use my fine-tune model, where now I can use that model to create things like completions or wherever that custom model's supported.
[3:26] In review, in order to create a new fine-tune model, we want to use the createFineTune method on the OpenAI SDK, where we want to pass our training file ID, as well as the model that we want to base it off of.
[3:38] Once we do that, we need to use the ID from the fine-tune in order to get its status so we know when it's ready to use. Once it's ready, we'll be able to see that uploaded status, as well as a dedicated fine-tune model property with that ID, that will allow us to generate things like completions using that custom model.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!