Hi everyone!
Like a lot of people I've been using ChatGPT to come up with initial drafts of emails and web copy. This has been working well, as long as you prime ChatGPT with context before every task.
Yesterday, OpenAI announced that businesses and developers now have the ability to fine-tune GPT-3.5 Turbo with their personal data. This means you can benefit from creating a custom-trainer and tuned GPT model for your company, allowing for more precise responses and a better match to your specific tone.
I posted about how to use this in the context of a virtual assistant: https://sitespeak.ai/blog/gpt-3-5-turbo-fine-tuning-custom-model-training, but any Saas can use this to easily create a custom model that they can use instead of ChatGPT to create email and website copy (or draft blog posts).
To get started you'll need an OpenAI API key. Once you have your key, you'll need to prepare some data, upload it to OpenAI and create your fine-tune job.
Step 1: Prepare your data
You'll have to get a dataset ready and send it to the OpenAI API for fine-tuning your model. At least 10 examples are needed, but you'll likely see more improvements with more than 50.
Each example in the dataset should be in line with our Chat completions API format, meaning a list of messages with each containing a role, content, and maybe a name. Make sure some of the training samples target situations where the prompted model doesn't behave right. The assistant messages in the data should be the ideal answers you want your model to provide.
Example Dataset
{"messages": [{"role": "system", "content": "SiteSpeak AI Assistant is a customer support virtual assistant that is helpful and friendly."}, {"role": "user", "content": "What is SiteSpeakAI?"}, {"role": "assistant", "content": "SiteSpeakAI is a tool that allows you to create a custom trained chatbot that uses ChatGPT to answer you visitor questions."}]}
{"messages": [{"role": "system", "content": "SiteSpeak AI Assistant is a customer support virtual assistant that is helpful and friendly."}, {"role": "user", "content": "How much does it cost?"}, {"role": "assistant", "content": "We have 3 pricing plans, $30/mo, $60/mo and $500/mo."}]}
{"messages": [{"role": "system", "content": "SiteSpeak AI Assistant is a customer support virtual assistant that is helpful and friendly."}, {"role": "user", "content": "Does it support Wordpress?"}, {"role": "assistant", "content": "Yes! You can easily install SiteSpeakAI on Wordpress and add a chatbot to your website."}]}
Step 2: Upload your training data
There's a complete script to upload and train a model in the post, but if you just need to upload a file:
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
# Upload file
print('Uploading file...')
file = openai.File.create(
file=open("yourfile.jsonl", "rb"),
purpose='fine-tune'
)
print('File uploaded: ', file)
Step 3: Create your fine-tuned model
After uploading your file and making sure the status has changed from uploaded to processed, you can create your fine-tune training job. Training jobs can take a while to complete (5 - 10 minutes). Once the training job is done, the status of the job will change to succeeded. You will then be able to get the fine_tune_model from the response and use this model ID for inference.
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
# Create fine-tuning job
print('Creating fine-tuning job...')
job = openai.FineTuningJob.create(
training_file="file-123abc", model="gpt-3.5-turbo")
print('Job created.')
print(job)
Step 4: Use your fine-tuned model
You can now use your newly trained GPT-3.5 Turbo model for inference:
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
completion = openai.ChatCompletion.create(
model="your-fine-tune-model-id",
messages=[
{"role": "system", "content": "SiteSpeak AI Assistant is a customer support virtual assistant that is helpful and friendly."},
{"role": "user", "content": "Please write a short overview of what SiteSpeakAI is and how it can benefit a business."}
]
)
print(completion.choices[0].message)
You now have a custom trained GPT model you can use to craft brand accurate emails and copy 😎
Would love to know if anyone else is doing this as well?
Also, please check out https://sitespeak.ai and let me know what you think. It's a crowded marked I know, but I think SiteSpeakAI has a few features that sets it apart from the rest.