Method ExportAsync
- Namespace
- LMKit.Finetuning.Export
- Assembly
- LM-Kit.NET.dll
ExportAsync(IEnumerable<ChatTrainingSample>, string, DatasetBuilderOptions, IProgress<ExportProgress>, CancellationToken)
Exports chat training samples to a ShareGPT-style JSON dataset using streaming I/O (asynchronous).
public static Task<ExportResult> ExportAsync(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. Must not be null.
outputFilePath
stringDestination path for the ShareGPT JSON file (for example,
./data/sharegpt.json
). Parent directories are created if needed.options
DatasetBuilderOptionsOptional exporter configuration. When null, sensible defaults are used.
progress
IProgress<ExportProgress>Optional progress reporter. Receives periodic ExportProgress updates after each sample is written.
cancellationToken
CancellationTokenA token observed for cooperative cancellation.
Returns
- Task<ExportResult>
An ExportResult describing the outcome, including counts and resolved output paths.
Remarks
The exporter writes one JSON object per sample directly to the output stream, avoiding large in-memory buffers for big datasets. Images embedded in the samples are emitted to a sibling folder.
The output JSON schema:
[
{
"id": "sample001",
"images": ["images/sample001_1.png", "..."],
"messages": [
{ "role": "system", "content": "..." },
{ "role": "user", "content": "..." },
{ "role": "assistant", "content": "..." }
]
},
...
]
Exceptions
- IOException
The destination file exists and overwrite is disabled, or an I/O error occurs.
- UnauthorizedAccessException
The caller lacks the required file system permissions.
- PathTooLongException
A path or file name exceeds the system-defined maximum length.
- NotSupportedException
An invalid path format is used for the current platform.
- OperationCanceledException
Export was canceled via
cancellationToken
.