import { Glossary } from "./glossary.js"; import { LanguageModel } from "ai"; //#region src/evaluation.d.ts /** * Options for {@link TranslationEvaluator}. */ interface EvaluatorOptions { /** * An optional `AbortSignal` to cancel the evaluation. */ readonly signal?: AbortSignal; } /** * Options for the {@link evaluate} function. */ interface EvaluateOptions { /** * The target language of the translation. */ readonly targetLanguage: Intl.Locale | string; /** * The source language of the original text. */ readonly sourceLanguage?: Intl.Locale | string; /** * A glossary of terms that should be used consistently. */ readonly glossary?: Glossary; /** * An optional `AbortSignal` to cancel the evaluation. */ readonly signal?: AbortSignal; } /** * Evaluates the quality of a translation. * * @param original The original text that was translated. * @param translated The translated text to evaluate. * @param options Optional settings for the evaluation. * @returns A promise that resolves to the evaluation result. */ type TranslationEvaluator = (original: string, translated: string, options?: EvaluatorOptions) => Promise; /** * The result of evaluating a translation. */ interface EvaluationResult { /** * A quality score between 0 and 1, where 1 indicates a perfect translation * and 0 indicates a completely incorrect translation. */ readonly score: number; /** * Specific issues found in the translation. */ readonly issues: readonly TranslationIssue[]; } /** * The type of issue found in a translation. * * - `"accuracy"`: The translation does not accurately convey the meaning * of the original text. * - `"fluency"`: The translation is not natural or readable in the target * language. * - `"terminology"`: Incorrect or inconsistent use of domain-specific terms. * - `"style"`: The translation does not match the desired tone or style. */ type TranslationIssueType = "accuracy" | "fluency" | "terminology" | "style"; /** * A specific issue found in a translation. */ interface TranslationIssue { /** * The type of issue. */ readonly type: TranslationIssueType; /** * A human-readable description of the issue. */ readonly description: string; /** * The location of the issue in the translated text, if applicable. */ readonly location?: TranslationIssueLocation; } /** * The location of a translation issue within the translated text. */ interface TranslationIssueLocation { /** * The starting character index (0-based, inclusive). */ readonly start: number; /** * The ending character index (0-based, exclusive). */ readonly end: number; } /** * Evaluates the quality of a translation using an LLM. * * @param model The language model to use for evaluation. * @param original The original text that was translated. * @param translated The translated text to evaluate. * @param options Evaluation options including target language. * @returns A promise that resolves to the evaluation result. */ declare function evaluate(model: LanguageModel, original: string, translated: string, options: EvaluateOptions): Promise; //#endregion export { EvaluateOptions, EvaluationResult, EvaluatorOptions, TranslationEvaluator, TranslationIssue, TranslationIssueLocation, TranslationIssueType, evaluate };