Skip to main content

Class: TranscriptTranslator

Defined in: packages/agentos/src/cognition/nlp/language/TranscriptTranslator.ts:235

Translates a live transcript's final lines, one line and one target a call.

Constructors​

Constructor​

new TranscriptTranslator(): TranscriptTranslator

Returns​

TranscriptTranslator

Methods​

boundMicro()​

boundMicro(line, target, options): number

Defined in: packages/agentos/src/cognition/nlp/language/TranscriptTranslator.ts:256

The most one translateLine with these options can cost, in micro-dollars, times the attempts: the request as generateText sends it, bounded by estimateMaxCallCostUSD, which counts a prompt at up to a token a byte, where estimateCallCostUSD's four characters a token undercounts CJK text, emoji and base64, and the output cap the call sends, a reasoning model's room for its reasoning included. The model is read as the call reads it: openai:gpt-4o-mini is priced as the gpt-4o-mini it sends.

Parameters​

line​

TranscriptLineInput

target​

string

options​

TranscriptTranslatorOptions

Returns​

number

Throws​

For a maxAttempts that is not a whole number of 1 or more, a maxContextLines that is not a whole number of 0 or more, or a timeoutMs that is not a number from 1 to 2,147,483,647: a call with these options cannot run, so no bound is reserved for it.

Throws​

For a model with no price row, a model of another provider, or a request it cannot bound.


translateLine()​

translateLine(line, target, options): Promise<TranslatedLine>

Defined in: packages/agentos/src/cognition/nlp/language/TranscriptTranslator.ts:302

Translates line into target, or skips it when its configured or detected source is the target's language, compared without case or region (en-US is en, zh-Hant is not zh-Hans), a Chinese region naming its script (zh-TW is zh-Hant, not zh-CN).

Parameters​

line​

TranscriptLineInput

target​

string

options​

TranscriptTranslatorOptions

Returns​

Promise<TranslatedLine>

Throws​

TRANSLATION_REQUEST_FAILED (with the HTTP status when the provider answered, and the usage the provider's error reported), TRANSLATION_TIMEOUT past timeoutMs, while the provider is still starting included (with the usage earlier attempts answered with an error status reported), TRANSLATION_EMPTY_OUTPUT, TRANSLATION_TRUNCATED and TRANSLATION_INCOMPLETE (each with the billed usage); each carries unansweredAttempts. A call ended through abortSignal rejects with the signal's reason at once.

Throws​

For a maxAttempts that is not a whole number of 1 or more, a maxContextLines that is not a whole number of 0 or more, or a timeoutMs that is not a number from 1 to 2,147,483,647, before anything is sent.


defaultMaxOutputTokens()​

static defaultMaxOutputTokens(text): number

Defined in: packages/agentos/src/cognition/nlp/language/TranscriptTranslator.ts:240

The default output cap for the answer: 64 tokens plus three times the line's estimated tokens, at most 2,048. A call to an OpenAI reasoning model sends 1,024 tokens more, for the reasoning that shares the cap.

Parameters​

text​

string

Returns​

number


failedCallMicro()​

static failedCallMicro(error, boundMicro, price): number

Defined in: packages/agentos/src/cognition/nlp/language/TranscriptTranslator.ts:281

What a failed call is recorded as costing, in micro-dollars: the tokens the provider reported for an answer it billed and the translator refused (error.usage, priced by the caller's price); the bound where the bill is unknown (a timeout, though its error carries the tokens earlier attempts reported, a network error, a caller's abort, an attempt of the call that got no usable answer, anything not a TranslationProviderError); nothing where the provider refused every attempt with an HTTP status and reported no tokens, since it wrote nothing. The bound covers an unanswered attempt and the answer after it together: it is a whole answer's bound for every attempt the call may make.

Parameters​

error​

unknown

boundMicro​

number

price​

(usage) => number

Returns​

number