Tired of the same-looking answers ChatGPT gives you?
In this guide, we’ll teach you:
- How to train ChatGPT with your own data
- Make it sound like you
- Give custom answers — according to your preference
Training ChatGPT is 100% free.
However, light coding is required.
Very relevant topic: How to give ChatGPT custom instructions.
For now, we’ll focus on training ChatGPT with data, which is very different than giving instructions to the AI.
How to train your own ChatGPT model
Yes, you can train your own ChatGPT model with custom data.
1. Install Python
You first need to install Python. Follow this process:
- Go to the Phyton.org website
- Select Download
- Choose your Operating System
- Download & Install the app.
Then, install the essential libraries for your custom ChatGPT model:
Why install these? → They develop an LLM that accesses your data and trains the bot.
LLM = Lifelong Learning Machine.
2. Open a Code Editor
Now you need to install a code editor.
If you already have one, simply open it.
Here are a few examples:
- Windows: NotePad++
- Mac: Sublime Text
- Linux: Visual Studio Code
- iOS: Textastic
- Android: Acode
For this example, we’ve used Sublime Text on a Mac.
3. Copy your API Key
You need to create an API Key in your OpenAI-ChatGPT account.
Here’s how to:
- Go to your OpenAI API Keys — it takes you to settings
- Log in — if you’re not already, you will be asked to
- Click + Create a new secret key
- Optional: Name your API key
After creating your API key, write it down somewhere 100% private.
Make sure you’re the only one to ever see it.
How to keep your API key secure:
- Never type your key on the internet
- Don’t give your API key to anybody
- Make sure you store it in a private/secure document
4. Select a GPT Model
Select which ChatGPT model you want for your custom-made AI chatbot.
Find all of ChatGPT’s models here.
The smarter the model, the more credits you need to pay for.
For example, GPT-3.5 will be cheaper to use than GPT-4.
5. Create a new Script
Now that you’ve selected your GPT model, you can use our free script below:
- Copy the code below
- Open your code editor
- Replace “Insert API Key” with your own key
- Save the file as “app.py” in the “docs” folder
from gpt_lib import CustomDirectoryLoader, GPTQueryIndex, GPTVectorIndex, LanguageModelInfer, QueryAssistant
from chain_language import OpenAIApi
import gradio as grd
import sys
import os
os.environ["API_KEY_OPENAI"] = 'Insert API Key'
def create_index(folder_path):
max_query_size = 4096
output_dims = 512
overlap_margin = 20
max_segment_size = 600
query_assistant = QueryAssistant(max_query_size, output_dims, overlap_margin, segment_limit=max_segment_size)
lang_model = LanguageModelInfer(temperature=0.7, model_type="davinci-text-003", token_limit=output_dims)
doc_data = CustomDirectoryLoader(folder_path).get_documents()
query_index = GPTVectorIndex(doc_data, model_predictor=lang_model, query_helper=query_assistant)
query_index.save('index_data.json')
return query_index
def my_chatbot(query_text):
query_index = GPTVectorIndex.load('index_data.json')
bot_response = query_index.search(query_text, mode="compact")
return bot_response.answer
gui = grd.Interface(fn=my_chatbot,
inputs=grd.inputs.Textbox(lines=7, label="Input your text"),
outputs="text",
live_title="Custom Chatbot")
gpt_index = create_index("document_folder")
gui.launch(public=True)
After executing the code in the Terminal and the .JSON file is generated..
A local URL will pop up:
- Copy that URL.
- Paste it into your web browser.
- You’re now accessing your custom ChatGPT bot.
Have fun asking questions!
Conclusion
That’s all you need to know — a simple and free way to train ChatGPT.
You’ve just learned how to create a custom AI bot based on ChatGPT.
Learn how to become more productive with our guides on how to use AI.
Thank you for reading this,
Ch David and Daniel