Table of Contents

Method Export

Namespace
LMKit.Finetuning.Export
Assembly
LM-Kit.NET.dll

Export(IEnumerable<ChatTrainingSample>, string, DatasetBuilderOptions, IProgress<ExportProgress>, CancellationToken)

Exports chat training samples to a ShareGPT-style JSON dataset (synchronous wrapper).

public static ExportResult Export(IEnumerable<ChatTrainingSample> samples, string outputFilePath, DatasetBuilderOptions options = null, IProgress<ExportProgress> progress = null, CancellationToken cancellationToken = default)

Parameters

samples IEnumerable<ChatTrainingSample>

The chat training samples to export. Each sample provides an ordered conversation (and optional images) for fine-tuning. Must not be null.

outputFilePath string

Destination path for the ShareGPT JSON file (for example, ./data/sharegpt.json).

options DatasetBuilderOptions

Optional exporter configuration. When null, defaults are used (pretty-printed JSON, images/ folder, identifier prefix "sample", and strict role mapping).

progress IProgress<ExportProgress>

Optional progress reporter. Receives ExportProgress updates with totals, counts, last sample id, and percentage.

cancellationToken CancellationToken

A token to observe for cooperative cancellation of the export operation.

Returns

ExportResult

An ExportResult describing the outcome, including the JSON path, images folder path, and skipped count.

Remarks

Blocks the calling thread and delegates to ExportAsync(IEnumerable<ChatTrainingSample>, string, DatasetBuilderOptions, IProgress<ExportProgress>, CancellationToken). Records are streamed directly to disk; any embedded images are written to a sibling folder (by default, images/ next to the JSON file).

Prefer ExportAsync(IEnumerable<ChatTrainingSample>, string, DatasetBuilderOptions, IProgress<ExportProgress>, CancellationToken) in UI or server contexts to avoid blocking. Use this overload for console apps, build scripts, or when synchronous execution is explicitly required.

The input sequence is enumerated exactly once. If provided, progress receives an ExportProgress update after each processed sample. The cancellationToken is observed between samples; if cancellation is requested, an OperationCanceledException is thrown.

File system behavior: When Overwrite is true, an existing file at outputFilePath is replaced; otherwise an IOException is thrown. Parent directories and the images folder are created if missing.

Exceptions

ArgumentNullException

Thrown if samples is null.

IOException

Thrown when the destination file exists and overwriting is disabled, or when an I/O error occurs while writing files.

UnauthorizedAccessException

The caller does not have required file system permissions.

PathTooLongException

A path or file name exceeds the system-defined maximum length.

NotSupportedException

A path format is invalid for the current platform.

OperationCanceledException

The operation was canceled via cancellationToken.