openvino-genai-node
Version:
OpenVINO™ GenAI pipelines for using from Node.js environment
74 lines • 3.02 kB
JavaScript
// Copyright (C) 2023-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
/**
* Structure to store resulting batched text outputs and scores for each batch.
* @note The first num_return_sequences elements correspond to the first batch element.
*/
export class DecodedResults {
/**
* @param {string[]} texts - Vector of resulting sequences.
* @param {number[]} scores - Scores for each sequence.
* @param {PerfMetrics} perfMetrics - Performance metrics (tpot, ttft, etc.).
* @param {Record<string, unknown>[]} parsed - The results of parsers processing for each sequence.
* @param {GenerationFinishReason[]} finishReasons - Finish reasons for each sequence.
*/
constructor(texts, scores, perfMetrics, parsed, finishReasons = []) {
this.texts = texts;
this.scores = scores;
this.perfMetrics = perfMetrics;
this.parsed = parsed;
this.finishReasons = finishReasons;
}
toString() {
if (this.scores.length !== this.texts.length) {
throw new Error("The number of scores and texts doesn't match in DecodedResults.");
}
if (this.texts.length === 0) {
return "";
}
if (this.texts.length === 1) {
return this.texts[0];
}
const lines = this.scores.map((score, i) => `${score.toFixed(6)}: ${this.texts[i]}`);
return lines.join("\n");
}
}
/**
* Structure to store VLM resulting batched text outputs and scores for each batch.
* @note The first num_return_sequences elements correspond to the first batch element.
*/
export class VLMDecodedResults extends DecodedResults {
/**
* @param {string[]} texts - Vector of resulting sequences.
* @param {number[]} scores - Scores for each sequence.
* @param {VLMPerfMetrics} perfMetrics - VLM-specific performance metrics.
* @param {Record<string, unknown>[]} parsed - The results of parsers processing for each sequence.
* @param {GenerationFinishReason[]} finishReasons - Finish reasons for each sequence.
*/
constructor(texts, scores, perfMetrics, parsed, finishReasons = []) {
super(texts, scores, perfMetrics, parsed, finishReasons);
this.perfMetrics = perfMetrics;
}
}
/**
* Result of WhisperPipeline.generate() with texts, scores, perf metrics, and optional timestamps.
*/
export class WhisperDecodedResults extends DecodedResults {
constructor(texts, scores, perfMetrics, chunks, words) {
super(texts, scores, perfMetrics, []);
this.chunks = chunks;
this.words = words;
this.perfMetrics = perfMetrics;
}
}
/**
* Result of Text2SpeechPipeline.generate() with audio tensors and perf metrics.
* Each element in `speeches` is an audio waveform tensor sampled at 16 kHz.
*/
export class Text2SpeechDecodedResults {
constructor(speeches, perfMetrics) {
this.speeches = speeches;
this.perfMetrics = perfMetrics;
}
}
//# sourceMappingURL=decodedResults.js.map