tweaktune is a Rust-powered, Python-facing library for synthesizing datasets for training and fine-tuning AI models, especially Language Models.
Build powerful data pipelines to generate synthetic text, structured JSON, and function calling datasets using LLM APIs. Perfect for creating high-quality training data for model fine-tuning.
Load data from multiple sources:
Connect to any LLM provider:
Create datasets for:
pip install tweaktune
Generate synthetic data in minutes:
from tweaktune import Pipeline
import os
# Create a Q&A dataset
(Pipeline()
.with_workers(3)
.with_llm_openai(
name="gpt4",
api_key=os.environ["OPENAI_API_KEY"],
model="gpt-4o-mini"
)
.with_template("system", "You are an expert educator.")
.with_template("question", "Generate a question about: {{topic}}")
.with_template("answer", "Answer this question: {{question}}")
.with_template("output", """{"topic": "{{topic}}", "question": "{{question}}", "answer": "{{answer}}"}""")
.iter_range(100)
.add_column("topic", lambda data: f"Topic {data['index']}")
.generate_text(
template="question",
llm="gpt4",
output="question",
system_template="system"
)
.generate_text(
template="answer",
llm="gpt4",
output="answer",
system_template="system"
)
.write_jsonl(path="qa_dataset.jsonl", template="output")
.run())
Create datasets for training models on tool use:
from tweaktune import Pipeline
from pydantic import Field
def search_products(
query: str = Field(..., description="Search query"),
category: str = Field(..., description="Product category")
):
"""Search for products in the catalog."""
pass
(Pipeline()
.with_workers(5)
.with_llm_openai("gpt4", api_key, "gpt-4o-mini")
.with_tools_dataset("tools", [search_products])
.iter_range(50)
.sample_tools("tools", 1, "tool")
# Generate user question, tool call, and response
# ... (see examples/08_function_calling.py for complete code)
.render_conversation(
conversation="@user:question|@assistant:tool_calls([call])|@tool:result|@assistant:answer",
tools="tool",
output="conversation"
)
.write_jsonl(path="function_calling.jsonl", value="conversation")
.run())
More examples in the examples directory.
Chain together powerful steps:
sample(), read(), filter()generate_text(), generate_json(), generate_structured()add_column(), mutate(), map(), ifelse()validate_json(), validate_tools(), check_language()check_hash(), check_simhash(), check_embedding()render(), render_conversation(), render_tool_call()write_jsonl(), write_csv(), print().step() for your own Python classesWe welcome contributions! Feel free to open issues, suggest features, or create pull requests.
Please note that by contributing to this project, you agree to the terms of the Contributor License Agreement (CLA).
# Clone the repository
git clone https://github.com/qooba/tweaktune.git
cd tweaktune
# Build the Python package (development mode)
make pyo3-develop
# Run tests
pytest
This project is licensed under either of:
at your option.
Built with:
416 commits
Rust
65.0%
Python
30.7%
Jinja
3.5%
tweaktune is a Rust-powered, Python-facing library for synthesizing datasets for training and fine-tuning AI models, especially Language Models.
Build powerful data pipelines to generate synthetic text, structured JSON, and function calling datasets using LLM APIs. Perfect for creating high-quality training data for model fine-tuning.
Load data from multiple sources:
Connect to any LLM provider:
Create datasets for:
pip install tweaktune
Generate synthetic data in minutes:
from tweaktune import Pipeline
import os
# Create a Q&A dataset
(Pipeline()
.with_workers(3)
.with_llm_openai(
name="gpt4",
api_key=os.environ["OPENAI_API_KEY"],
model="gpt-4o-mini"
)
.with_template("system", "You are an expert educator.")
.with_template("question", "Generate a question about: {{topic}}")
.with_template("answer", "Answer this question: {{question}}")
.with_template("output", """{"topic": "{{topic}}", "question": "{{question}}", "answer": "{{answer}}"}""")
.iter_range(100)
.add_column("topic", lambda data: f"Topic {data['index']}")
.generate_text(
template="question",
llm="gpt4",
output="question",
system_template="system"
)
.generate_text(
template="answer",
llm="gpt4",
output="answer",
system_template="system"
)
.write_jsonl(path="qa_dataset.jsonl", template="output")
.run())
Create datasets for training models on tool use:
from tweaktune import Pipeline
from pydantic import Field
def search_products(
query: str = Field(..., description="Search query"),
category: str = Field(..., description="Product category")
):
"""Search for products in the catalog."""
pass
(Pipeline()
.with_workers(5)
.with_llm_openai("gpt4", api_key, "gpt-4o-mini")
.with_tools_dataset("tools", [search_products])
.iter_range(50)
.sample_tools("tools", 1, "tool")
# Generate user question, tool call, and response
# ... (see examples/08_function_calling.py for complete code)
.render_conversation(
conversation="@user:question|@assistant:tool_calls([call])|@tool:result|@assistant:answer",
tools="tool",
output="conversation"
)
.write_jsonl(path="function_calling.jsonl", value="conversation")
.run())
More examples in the examples directory.
Chain together powerful steps:
sample(), read(), filter()generate_text(), generate_json(), generate_structured()add_column(), mutate(), map(), ifelse()validate_json(), validate_tools(), check_language()check_hash(), check_simhash(), check_embedding()render(), render_conversation(), render_tool_call()write_jsonl(), write_csv(), print().step() for your own Python classesWe welcome contributions! Feel free to open issues, suggest features, or create pull requests.
Please note that by contributing to this project, you agree to the terms of the Contributor License Agreement (CLA).
# Clone the repository
git clone https://github.com/qooba/tweaktune.git
cd tweaktune
# Build the Python package (development mode)
make pyo3-develop
# Run tests
pytest
This project is licensed under either of:
at your option.
Built with:
416 commits
Rust
65.0%
Python
30.7%
Jinja
3.5%