Skip to main content

Fine-Tuning

Fine-Tuning

toothfairyai@latest…

Manager for fine-tuning operations.

This manager provides methods to list trainable models, generate datasets, start training, monitor job status, and cancel training jobs.

Example:

>>> client = ToothFairyClient(api_key="...", workspace_id="...")
>>> models = client.finetuning.list_models()
>>> job = client.finetuning.generate_dataset(
... name="my-sft-job",
... training_type="conversationalTraining",
... base_model="toothfairyai/Llama-3.2-1B-Instruct"
... )
>>> status = client.finetuning.get_status(job["training_log_id"])

Accessed via client.finetuning.

Methods

MethodHTTPEndpoint
list_modelsGETGET /models
list_jobsGETGET /jobs
generate_datasetPOSTPOST /dataset
get_statusGETGET /status/{training_log_id}
start_trainingPOSTPOST /start/{training_log_id}
cancel_trainingPOSTPOST /cancel/{training_log_id}
generate_training_dataPOSTPOST /magicwand

list_models

List all trainable models with their configurations.

def list_models() -> List[TrainableModel]

Endpoint: GET /models · Fine-Tuning service

Example

client.finetuning.list_models()

list_jobs

List all fine-tuning jobs for the authenticated workspace.

def list_jobs() -> List[TrainingJob]

Endpoint: GET /jobs · Fine-Tuning service

Example

client.finetuning.list_jobs()

generate_dataset

Generate a training dataset from workspace documents.

def generate_dataset(
name: str,
base_model: str,
training_type: str = 'conversationalTraining',
topics: Optional[List[str]] = None,
test_size: Optional[float] = None,
test_size_threshold: Optional[int] = None,
description: Optional[str] = None
) -> Dict[str, Any]

Endpoint: POST /dataset · Fine-Tuning service

Request fields

FieldTypeRequiredDescription
namestringyesHuman-readable name for the training job
training_typestringnoTraining method to use. Each method maps to a document type:
  • conversationalTraining (SFT) — uses Conversation documents
  • generativeTraining (DPO) — uses Preference documents
  • grpoTraining (GRPO) — uses Conversation documents (model self-generates)
  • ktoTraining (KTO) — uses Preference documents (unpaired)
  • continuedPretraining (CPT) — uses Conversation documents (plain text)

Defaults to conversationalTraining. Note: the REST endpoint does not enforce the enum at request time (validation occurs in the async worker); send one of the listed values.

Allowed: conversationalTraining, generativeTraining, grpoTraining, ktoTraining, continuedPretraining | | base_model | string | yes | Base model to fine-tune (canonical id from the /models endpoint) | | topics | array<string> | no | Optional list of topic IDs to filter documents by | | test_size | number | no | Fraction of the dataset to reserve as the test split (0.0–1.0) | | test_size_threshold | integer | no | Minimum number of examples required in the test split | | description | string | no | Optional human-readable description of the training job |

The Python SDK accepts snake_case keyword arguments and converts them to the camelCase wire fields shown above.

Example

client.finetuning.generate_dataset(name="…", base_model="…")

get_status

Get detailed status of a fine-tuning job.

def get_status(training_log_id: str) -> TrainingStatusResponse

Endpoint: GET /status/{training_log_id} · Fine-Tuning service

Response fields

FieldTypeDescription
training_log_idstringTraining log ID
statusstringCurrent job status. Lifecycle: dispatchedinProgressdatasetReadyfineTuningRequestedtrainingcompleted (or inError).

Allowed: dispatched, inProgress, datasetReady, fineTuningRequested, training, completed, inError, cancellationRequested | | name | string | Job name | | training_type | string | Training method | | created_at | string | Job creation timestamp (ISO 8601) | | duration | integer | Training duration in seconds (present once training has progressed) | | dataset | object | Dataset paths (present after dataset generation reaches the relevant stage) | | compute_uoi | number | UoI consumed by the training job (present when status is completed) | | model_id | string | S3 path to the fine-tuned LoRA adapter (present when status is completed) | | base_model | string | Base model used for training (present when status is completed) | | metrics_summary | object | Final training metrics (present when status is completed) | | downloads | object | Presigned download URLs (present when status is completed) | | error | object | Error detail (present when status is inError) |

Example

client.finetuning.get_status(training_log_id="agent-id")

start_training

Start a fine-tuning training job.

def start_training(
training_log_id: str,
config: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]

Endpoint: POST /start/{training_log_id} · Fine-Tuning service

Request fields

FieldTypeRequiredDescription
configobjectnoTraining configuration overrides merged over the existing training configuration. Keys not present retain their prior values.

The Python SDK accepts snake_case keyword arguments and converts them to the camelCase wire fields shown above.

Example

client.finetuning.start_training(training_log_id="agent-id")

cancel_training

Cancel a running fine-tuning job.

def cancel_training(training_log_id: str) -> Dict[str, Any]

Endpoint: POST /cancel/{training_log_id} · Fine-Tuning service

Example

client.finetuning.cancel_training(training_log_id="agent-id")

generate_training_data

Transform a chat conversation or uploaded file into training data.

def generate_training_data(
chat_id: Optional[str] = None,
file_key: Optional[str] = None,
training_type: str = 'conversationalTraining',
user_id: Optional[str] = None,
create_document: bool = True,
system_message: Optional[str] = None,
instructions: Optional[str] = None,
title: Optional[str] = None,
topics: Optional[List[str]] = None,
status: str = 'draft',
scope: str = 'training',
non_preferred_responses: Optional[List[Dict[str, Any]]] = None,
tools: Optional[List[Dict[str, Any]]] = None,
generate_non_preferred: bool = False,
chunk_size: Optional[int] = None,
overlap_percent: Optional[float] = None,
num_turns: Optional[int] = None,
samples_per_chunk: Optional[int] = None
) -> Dict[str, Any]

Endpoint: POST /magicwand · AI service

Request fields

FieldTypeRequiredDescription
chatidstringnoChat mode: Unique chat session identifier to extract messages from. Mutually exclusive with file_key.
file_keystringnoFile mode: S3 key of uploaded file to generate training data from. Obtain via /documents/requestPreSignedURL endpoint. Mutually exclusive with chatid.

Supported formats: PDF, DOCX, XLSX, PPTX, TXT, MD, CSV, JSON, HTML, XML | | workspaceid | string | yes | Unique workspace identifier | | userid | string | no | User identifier performing the operation | | chunk_size | integer | no | File mode only: Target size of each text chunk in characters. Larger chunks provide more context but generate fewer training samples. | | overlap_percent | number | no | File mode only: Percentage of overlap between adjacent chunks to preserve context continuity. | | num_turns | integer | no | File mode only: Number of conversation turns (user-assistant pairs) to generate per chunk. Each turn adds a question and answer. | | samples_per_chunk | integer | no | File mode only: Number of independent training samples to generate per chunk. Useful for data augmentation. | | create_document | boolean | no | Whether to create a training document in the knowledge hub. If false, only returns the transformed data without persisting. | | system_message | string | no | Custom system message to prepend to the training data. If not provided, a default message will be used. | | instructions | string | no | Optional instructions to refine the training data output.

Chat mode: Refine conversation messages. File mode: Guide conversation synthesis from document content.

Examples:

  • "Focus on technical accuracy"
  • "Remove any personal information"
  • "Make the tone more professional"
  • "Include code examples where relevant" | | title | string | no | Title for the training document (only used when create_document is true) | | topics | array<string> | no | Topic IDs to tag the training document with (only used when create_document is true) | | training_type | string | no | Training method to use

Allowed: conversationalTraining, generativeTraining, grpoTraining, ktoTraining, continuedPretraining | | non_preferred_responses | array<string> | no | For DPO training: List of non-preferred responses. Only used when training_type is 'generativeTraining' (chat mode only). | | generate_non_preferred | boolean | no | For DPO training: Auto-generate non-preferred responses using AI. Only used when training_type is 'generativeTraining' (chat mode only). | | tools | array<object> | no | Optional tools/functions for function calling training (chat mode only). | | scope | string | no | The scope of the training document:

  • training (default): Document will be used for model training
  • validation: Document will be used for model validation/evaluation

Allowed: training, validation | | status | string | no | Status for the created training document

Allowed: draft, published |

The Python SDK accepts snake_case keyword arguments and converts them to the camelCase wire fields shown above.

Response fields

FieldTypeDescription
successbooleanWhether the operation completed successfully
rawTrainingDataobjectThe transformed conversation in training data format
messageCountintegerTotal number of messages in the generated training data
chatIdstringSource chat identifier (chat mode only, null for file mode)
fileKeystringSource file S3 key (file mode only, null for chat mode)
sourceTypestringIndicates whether training data was generated from chat or file

Allowed: chat, file | | documentCreated | boolean | Whether a training document was created in the knowledge hub | | instructionsApplied | boolean | Whether custom instructions were applied to transform the data | | trainingType | string | The type of training data generated

Allowed: conversationalTraining, generativeTraining | | scope | string | The scope of the training document

Allowed: training, validation | | chunksProcessed | integer | Number of chunks processed (file mode only) | | samplesGenerated | integer | Number of training samples generated (file mode only) | | chunksConfig | object | Configuration used for chunking (file mode only) | | document | object | Created document details (only present when create_document is true) |

Example

client.finetuning.generate_training_data()