Document Translator

Functionality

The document translator agent that makes use of tool calls to find out when it is ready to translate a document. To start the translation it needs to find out what language is desired and what document should be translated and to find this information it an use predefined tools (see Capabilities). This approach allows that you can talk to it about other things than translation as well.

The document translator functionality takes a document and tries to extract all texts and to translate them into the target language. The text pieces are grouped into a single prompt of a maximum length and few shot learning with regard to the input and target language is applied to build up the prompt sent to the LLM. These request have a maximum token size and the number we send is limited by the maximum allowed token consumption per minute.

Input and Output

Simply talk to the agent, ask it its capability and it will tell you how to use it.

Capabilities

The Document Translator has the following capabilities:

  • Document Selection: If multiple documents are uploaded, the translator can ask the user to select a specific document by showing them as buttons. Clicking on these buttons injects a prompt into the chat window.

    document_selection.png

  • Language Selection: The translator can present the user with proposed languages as buttons if the user asks for languages to translate to. Clicking on these buttons injects a prompt into the chat window.

    language_selection.png

  • Time estimation: The translator can estimate the time it will take to translate documents.

 

Known Issues

Small Document Upload

Cannot upload small documents in chat for translation.

[2024-10-24 08:25:58.373 +0200] ERROR (28723): IngestionWorkerError - Content has too little information to be useful

Translated Document Reappears

After translation, the translated document appears in the uploaded documents list.

Sheet Names Not Translated

Sheet names in xlsx files are not translated.

Bullet points within tables*
Bullet points within tables are removed. Text is still there.

Configuration settings (technical)

Reference in Code

DocumentTranslator

Tool Definition

{ "type": "function", "function": { "name": "DocumentTranslator", "parameters": { "type": "object", "required": [ "outputLanguage" ], "properties": { "inputDocument": { "type": "string", "description": "The name of the document to translate" }, "output_language": { "type": "string", "description": "The language used to generate the translation of the document." } } }, "description": "The document translator helps you translate documents from one language to another. After translation you can download the document directly." } }

Configuration

The following is the default configuration for the module, it consists of four sections that will be discussed in detail below.

{ "agentConfig": { "historyTokenLimit": 400, "languageModelName": "AZURE_GPT_4_TURBO_2024_0409", "proposedLanguagesForTranslationIso6391": [ "en", "es", "fr", "de", "it", "pt", "nl", "ru", "sv" ], "supportedDocEndings": [ ".docx", ".xlsx", ".pptx" ] }, "agentPromptConfig": { "systemPrompt": "You are a friendly person that helps our customers to translated uploaded documents.\nTherefore, you must find out which uploaded documents they want to translate and to what language before starting the translation.\nIf you cannot find the information from the conversation, nicely ask them to provide it or to upload a document.\nYou have access to tools that can help you with these tasks, but use only one at the time elsewise it is complicated for the user.\nNote that at the moment, only word, powerpoint and excel documents can be translated, thus the files must end with an .docx, .xlsx or .pptx file extension.\nMention this if the user uploads other files." }, "translatorPromptConfig": { "systemPromptInstruction": "You are a helpful AI designed to to translate text to a specified language.\nDo it even if the target language is the same as the source language.\nMake sure the translated text contains the same amount of carriage returns '\\n' as the original text block.\nTry to keep the translated text as close to the original as possible and having approximately the same lenght.", "inputPromptInstructionTemplate": "List of text blocks to be translated to ${language}:\n\n<INPUT>\n${input_block}\n</INPUT>", "outputPromptInstructionTemplate": "<OUTPUT>\n${output_block}\n</OUTPUT>", "availableLanguagesForTranslationAsIso6391Codes": [ "en", "es", "fr", "de" ] }, "translatorUserConfig": { "languageModelName": "AZURE_GPT_4_0613", "maxTokensPerTranlationRequest": 1000, "maxTokenPerMinute": 40000, "prependKeywordTranlatedDocument": "translated_", "allowedInputLanguages": [ "en", "es", "fr", "de", "it", "pt", "nl", "ru", "sv" ] } }

Parameter Description

AgentConfig

Parameter

Description

Default

Parameter

Description

Default

historyTokenLimit

The number of tokens used from the history when calling the LLM.

400

languageModelName

The name of the language model to use for the agent.

"AZURE_GPT_4_TURBO_2024_0409"

proposedLanguagesForTranslationIso6391

The languages that the agent proposes to translate to as ISO 639-1 codes.

["en", "es", "fr", "de", "it", "pt", "nl", "ru", "sv"]

supportedDocEndings

The supported document endings for translation.

[".docx", ".xlsx", ".pptx"]

Example

AgentPromptConfi
❗Only adjust prompts if you are fully familiar with the code logic. Small changes can break the module or reduce the output quality.

Parameter

Description

Parameter

Description

systemPrompt

System prompt for document translation agent.

Default Value

Example

TranslatorPromptConfig
❗Only adjust prompts if you are fully familiar with the code logic. Small changes can break the module or reduce the output quality.

Parameter

Description

Default Value

Parameter

Description

Default Value

systemPromptInstruction

System prompt instruction for the document translation module.

See below

inputPromptInstructionTemplate

Input prompt for translating an array of text blocks with word formatting tags to a specified language.

See below

outputPromptInstructionTemplate

Output prompt instruction template.

See below

availableLanguagesForTranslationAsIso6391Codes

Available languages for translation as ISO 639-1 codes.

["en", "es", "fr", "de"]

Default Values

  • systemPromptInstruction:

  • inputPromptInstructionTemplate:

  • outputPromptInstructionTemplate:

Example

TranslatorUserConfig

Parameter

Description

Default Value

Parameter

Description

Default Value

languageModelName

The model that will be used to translate between languages.

"AZURE_GPT_4_0613"

maxTokensPerTranlationRequest

The maximum number of tokens that will be translated at once. If the model cannot handle more than this many tokens in a single request then it will be split into multiple requests.

1000

maxTokenPerMinute

The maximum number of tokens available for translation tasks per minute.

40000

prependKeywordTranlatedDocument

The keyword that will be prepended to the translated document name.

"translated_"

allowedInputLanguages

The languages that will be allowed as input as ISO codes.

["en", "es", "fr", "de", "it", "pt", "nl", "ru", "sv"]

Example

 


Author

@Cedric Klinkert

© 2024 Unique AG. All rights reserved. Privacy PolicyTerms of Service