import { Glossary } from "./glossary.js"; import { TranslationIssue } from "./evaluation.js"; import { LanguageModel } from "ai"; //#region src/refine.d.ts /** * Options for the {@link refineChunks} function. */ interface RefineChunksOptions { /** * The target language of the translation. */ readonly targetLanguage: Intl.Locale | string; /** * The source language of the original text. */ readonly sourceLanguage?: Intl.Locale | string; /** * The minimum acceptable quality score (0-1). Chunks with scores below * this threshold will be refined. Defaults to 0.85. */ readonly targetScore?: number; /** * Maximum number of refinement iterations per chunk. Defaults to 3. */ readonly maxIterations?: number; /** * A glossary of terms that should be used consistently. */ readonly glossary?: Glossary; /** * Whether to evaluate boundaries between chunks for coherence. * Defaults to true. */ readonly evaluateBoundaries?: boolean; /** * An optional `AbortSignal` to cancel the refinement. */ readonly signal?: AbortSignal; } /** * The result of evaluating a boundary between two chunks. */ interface BoundaryEvaluation { /** * Index of the first chunk in the boundary (chunk i and chunk i+1). */ readonly chunkIndex: number; /** * A coherence score between 0 and 1. */ readonly score: number; /** * Issues found at the boundary. */ readonly issues: readonly BoundaryIssue[]; } /** * An issue found at a chunk boundary. */ interface BoundaryIssue { /** * The type of boundary issue. */ readonly type: "coherence" | "style" | "reference" | "terminology"; /** * A human-readable description of the issue. */ readonly description: string; } /** * Record of a single refinement iteration for a chunk. */ interface RefineIteration { /** * The chunk index that was refined. */ readonly chunkIndex: number; /** * The iteration number (1-based). */ readonly iteration: number; /** * The text before refinement. */ readonly before: string; /** * The text after refinement. */ readonly after: string; /** * The evaluation score before refinement. */ readonly scoreBefore: number; /** * The evaluation score after refinement. */ readonly scoreAfter: number; /** * Issues that were addressed in this iteration. */ readonly issuesAddressed: readonly TranslationIssue[]; } /** * The result of the {@link refineChunks} function. */ interface RefineChunksResult { /** * The refined translated chunks. */ readonly chunks: readonly string[]; /** * Final evaluation scores for each chunk. */ readonly scores: readonly number[]; /** * Total number of refinement iterations performed. */ readonly totalIterations: number; /** * History of all refinement iterations. */ readonly history: readonly RefineIteration[]; /** * Boundary evaluations (if evaluateBoundaries was enabled). */ readonly boundaryEvaluations?: readonly BoundaryEvaluation[]; } /** * Evaluates the boundary between two chunks for coherence. */ declare function evaluateBoundary(model: LanguageModel, chunk1Translated: string, chunk2Translated: string, chunk1Original: string, chunk2Original: string, options: RefineChunksOptions): Promise>; /** * Refines translated chunks to improve quality using an iterative * evaluate-fix loop. * * @param model The language model to use for refinement. * @param originalChunks The original text chunks that were translated. * @param translatedChunks The translated chunks to refine. * @param options Refinement options. * @returns A promise that resolves to the refinement result. * @throws {RangeError} If the number of original and translated chunks * do not match. */ declare function refineChunks(model: LanguageModel, originalChunks: readonly string[], translatedChunks: readonly string[], options: RefineChunksOptions): Promise; //#endregion export { BoundaryEvaluation, BoundaryIssue, RefineChunksOptions, RefineChunksResult, RefineIteration, evaluateBoundary, refineChunks };