Skip to main content

Agentic SFT Data generation with CAMEL and finetuning Meta models with Unsloth

For more detailed usage information, please refer to our cookbook To run this, press “Runtime” and press “Run all” on a free Tesla T4 Google Colab instance!
CAMEL HomepageJoin Discord
Star us on GitHub, join our Discord, or follow us on X
CAMEL and Unsloth make an excellent pair. In this notebook we will combine the two to train a model to be proficient at content on a page You will learn how to do data generation with CAMEL, how to train, and how to run the model. SFT v2.png
First we will set the OPENAI_API_KEY that will be used to generate the data. CAMEL supports many other models. See here for a list.
Alternatively, if running on Colab, you could save your API keys and tokens as Colab Secrets, and use them across notebooks. To do so, comment out the above manual API key prompt code block(s), and uncomment the following codeblock. ⚠️ Don’t forget granting access to the API key you would be using to the current notebook.
Next we will set up our model for training using Unsloth.
Now as a control, lets see how this model does with our CAMEL-specific question
Note that it hasn’t been trained on this output format, so the output is total junk

Data models

We want to generate data in the Alpaca format, so we can use CAMEL’s built-in AlpacaItem class which has some handy conversion functions for us. We will be using CAMEL’s structured output to generate all of these items in one request, which is much faster and cheaper. Here we create a wrapper around the AlpacaItem to help the model know how many have been generated as it’s going along, and another wrapper class that represents a list of these.

Data generation

Next we define our data generation function. It takes a source content, and generates a list of instruction-input-response triplets around it. We will use this later to train our model to be proficient with the source content.

Point to content and generate data!

Now we point to the content that we wish to generate SFT data around and use CAMEL’s Firecrawl integration to get this content in a nice markdown format. You can get a Firecrawl API key from here
Now to define how each row is formatted
Train the model

Inference

Let’s run the model! You can change the instruction and input - leave the output blank!
Summary We have generated realistic user queries and responses from a real page and trained on them to produce a model that understands the underlying content. That’s everything: Got questions about 🐫 CAMEL-AI? Join us on Discord! Whether you want to share feedback, explore the latest in multi-agent systems, get support, or connect with others on exciting projects, we’d love to have you in the community! 🤝 Check out some of our other work:
  1. 🐫 Creating Your First CAMEL Agent free Colab
  2. Graph RAG Cookbook free Colab
  3. 🧑‍⚖️ Create A Hackathon Judge Committee with Workforce free Colab
  4. 🔥 3 ways to ingest data from websites with Firecrawl & CAMEL free Colab
  5. 🦥 Agentic SFT Data Generation with CAMEL and Mistral Models, Fine-Tuned with Unsloth free Colab
  6. 🦥 Agentic SFT Data Generation with CAMEL and Qwen Models, Fine-Tuned with Unsloth free Colab
Thanks from everyone at 🐫 CAMEL-AI
CAMEL HomepageJoin Discord
Star us on GitHub, join our Discord, or follow us on X