Fine-tuning a ChatGPT model can significantly improve its accuracy and relevance for your specific use case. However, manually preparing datasets for fine-tuning can be tedious. Introducing the ChatGPT Fine-Tuning SDK, an open-source package designed to streamline the process of generating fine-tuning datasets in JSONL format.
🚀 Why Use ChatGPT Fine-Tuning SDK?
This SDK simplifies dataset generation by wrapping around the chatgpt npm package. It provides a structured approach to curating training data while allowing programmatic approval, rejection, and correction of AI-generated responses.
When finished, you will be left with a jsonl file you can upload directly to fine-tune a model.
🔧 Installation
You can install the package using npm or yarn:
# npm
npm install chatgpt-fine-tuning
# yarn
yarn add chatgpt-fine-tuning
⚙️ Configuration
Before using the SDK, configure it with your OpenAI API key and define a system message:
import ChatGptFineTuning from 'chatgpt-fine-tuning';
const outFile = 'fine-tuning-output.jsonl'; // required
const systemMessage = 'Marv is a factual chatbot that is also sarcastic.'; // required
const gpt4Api = new ChatGptFineTuning({
apiKey: process.env.GPT4_API_KEY || '', // required
systemMessage,
}, outFile);
🛠 Usage
Each sendMessage
call returns a tuner object, which enables:
- Approving the AI response
- Rejecting an incorrect response
- Fixing and correcting AI responses
- Logging actions to maintain a record
Example Workflow
const tuner = await gpt4Api.sendMessage("What is the capital of France?");
// Programmatic verification
if (tuner.response.text.includes("Paris")) {
tuner.approve();
} else {
tuner.reject();
tuner.fix("You did not provide the correct answer", "Paris");
}
tuner.log("Finished run");
📖 API Reference
tuner Methods
Method | Parameters | Return Type | Description |
---|---|---|---|
approve() |
- | Promise<void> |
Approves the current response for fine-tuning. |
reject() |
- | Promise<void> |
Rejects the response, marking it with a weight of 0 . |
fix(userText, assistantText, log?) |
string , string , boolean (optional) |
Promise<void> |
Submits a correction for the AI response with optional logging. |
log(message) |
string |
void |
Logs a message to the output file. |
ChatMessage Properties
Name | Type | Description |
---|---|---|
id |
string |
Unique identifier for the chat message. |
text |
string |
Text content of the message. |
role |
Role |
Role of the message sender (user, assistant, etc.). |
parentMessageId |
string (optional) |
ID of the parent message in the conversation. |
conversationId |
string (optional) |
ID of the conversation this message belongs to. |
The API follows the same structure as the chatgpt npm package, ensuring familiarity if you've used it before.
🤝 Contributing
Contributions, bug reports, and feature requests are welcome! Check out the issues page to get involved.
⭐ Show Your Support
If this SDK has been helpful, consider giving it a ⭐ on GitHub!
📝 License
This project is MIT licensed.
Get Started Now!
Fine-tune your ChatGPT models effortlessly with ChatGPT Fine-Tuning SDK and take AI customization to the next level!
Top comments (0)