import { InferenceOutputError } from "../../lib/InferenceOutputError"; import type { BaseArgs, Options } from "../../types"; import { request } from "../custom/request"; export type TranslationArgs = BaseArgs & { /** * A string to be translated */ inputs: string; }; export interface TranslationOutput { /** * The string after translation */ translation_text: string; } /** * This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en. */ export async function translation(args: TranslationArgs, options?: Options): Promise { const res = await request(args, options); const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.translation_text === "string"); if (!isValidOutput) { throw new InferenceOutputError("Expected type Array<{translation_text: string}>"); } return res?.[0]; }