Polyweave

@polyweave/finetuning (1.0.5)

Published 2026-07-11 15:24:57 +00:00 by Dvorak

Installation

@polyweave:registry=https://hub.kl1.tenere.ai/api/packages/Polyweave/npm/
npm install @polyweave/finetuning@1.0.5
"@polyweave/finetuning": "1.0.5"

About this package

@polyweave/finetuning

Fine-tuning orchestration and dataset management for Polyweave. Provides dataset builder primitives (JSONL/JSON formatting with normalization) and training job state machines for LLM fine-tuning workflows.

Published as @polyweave/finetuning.

Synopsis

import { createDatasetBuilder, createTrainingJob } from '@polyweave/finetuning';

const builder = createDatasetBuilder({ format: 'jsonl', normalize: row => ({ ...row, timestamp: Date.now() }) });
const dataset = builder.buildDataset([
  { prompt: 'Hello', completion: 'Hi there' }
]);
console.log(builder.validate(dataset)); // { valid: true, count: 1 }

const job = createTrainingJob({ provider: 'openai', model: 'gpt-4o-mini', dataset });
job.start();
console.log(job.getState()); // { status: 'running', ... }
job.complete();

Install

npm install @polyweave/finetuning

Why

LLM fine-tuning requires structured dataset preparation in specific formats (JSONL for most providers, JSON for others) and managed training job lifecycles. This package provides pure data-transformation functions for dataset building with optional row-level normalization, and a simple state machine for tracking training job progress through pending→running→completed/failed transitions.

API

createDatasetBuilder(options)

Creates a dataset builder that formats arrays of rows into JSONL or JSON strings with optional normalization.

createDatasetBuilder(options?: Object): { buildDataset, validate }
Name Type Required Default Description
options.format string No 'jsonl' Output format: 'jsonl' or 'json'
options.normalize Function No Row normalization function (row) => normalizedRow. Applied to each row before formatting.

Returns: An object with two methods:

buildDataset(rows)

Formats an array of rows into a string.

buildDataset(rows: Array<Object>): string
  • If normalize is provided, each row is passed through normalize(row) first.
  • If format is 'jsonl', each row is JSON.stringify(row) and joined with '\n'.
  • If format is 'json', the entire normalized array is JSON.stringify(normalized, null, 2).

validate(dataset)

Validates a dataset.

validate(dataset: string|Array): { valid: boolean, errors?: string[], count?: number }
  • If dataset is a string, it is JSON.parse'd first.
  • Returns { valid: true, count: parsed.length } if the result is an array.
  • Returns { valid: false, errors: ['Dataset must be an array of rows'] } if not an array.

Error conditions: validate() does not throw — it catches parse errors implicitly through the Array.isArray check (a non-parseable string or non-array object returns { valid: false }).


createTrainingJob(options)

Creates a training job state machine with a simple lifecycle: pending → running → completed/failed.

createTrainingJob(options?: Object): { getState, start, complete, fail }
Name Type Required Default Description
options.provider string No 'openai' Provider name
options.model string No undefined Model identifier
options.dataset any No [] Training dataset

Returns: An object with four methods:

getState()

Returns a shallow clone of the current state object. State shape:

{
  status: 'pending' | 'running' | 'completed' | 'failed',
  provider: string,
  model: string|undefined,
  dataset: any,
  startedAt: string|null,
  completedAt: string|null,
  error: any|null
}

start()

Sets status to 'running' and startedAt to new Date().toISOString().

complete()

Sets status to 'completed' and completedAt to new Date().toISOString().

fail(error)

Sets status to 'failed', error to the provided value, and completedAt to new Date().toISOString().

Error conditions: None. All methods succeed unconditionally — this is a pure state machine, not an actual API client.

Tests

npm test

Runs: node --test test/*.js

Covers: dataset builder with jsonl/json formats, normalization, validation of arrays and non-arrays, training job lifecycle (pending→running→completed, pending→running→failed), getState immutability (shallow clone).

Requirements

  • Node.js >= 22.0.0
  • ESM only ("type": "module")
  • No peer dependencies
  • No runtime dependencies

Dependencies

Development Dependencies

ID Version
@rigor/core *

Keywords

fine-tuning training datasets polyweave
Details
npm
2026-07-11 15:24:57 +00:00
5
John Dvorak
SEE LICENSE IN LICENSE
latest
3.2 KiB
Assets (1)
Versions (4) View all
1.0.5 2026-07-11
1.0.4 2026-07-11
1.0.2 2026-07-10
1.0.1 2026-07-10