Translation Setup
When a user submits a query in a language other than English, the query is first translated into English to facilitate source retrieval. The response is then translated back into the original query language before being delivered to the user. This translation process occurs only if it has been enabled. The translation can be performed using the Azure Translation API the Google Translation API, or LLMs.
NOTE: The file translation is currently not supported with Azure Translator and LLMs.
Setting up the Google Translator
To set up the keys
JavaScriptgoogleTranslatorConfig = Genai.Llm.Gcp.Config.inst(); googleTranslatorConfig.setSecretValue('serviceAccountInfo', '<serviceAccountInfo>'); googleTranslatorConfig.setConfigValue('project', '<project>'); googleTranslatorConfig.setConfigValue('location', '<location>');To set up the Google translator
JavaScripttranslatorConfig = Genai.Translator.Config.getConfig(); translatorConfig.setConfigValue('enabled', true); translatorConfig.setConfigValue('translatorTypeName', Genai.Translator.Google);
Setting up the Azure Translator
By default Genai.Translator.Llm is setup up. To switch to Azure translator, update the Genai.Translator.Config
Genai.Translator.Config.translatorTypeName = 'Genai.Translator.Azure';To set up the keys
JavaScriptazureTranslatorConfig = Genai.Translator.Azure.Config.getConfig(); azureTranslatorConfig.setConfigValue('endPoint', '<endPoint>'); azureTranslatorConfig.setConfigValue('region', '<region>'); azureTranslatorConfig.setSecretValue('apiKey', '<apiKey>');To set up the Azure translator
JavaScripttranslatorConfig = Genai.Translator.Config.getConfig(); translatorConfig.setConfigValue('enabled', true); translatorConfig.setConfigValue('translatorTypeName', Genai.Translator.Azure);
Setting up the LLM Translator
To switch to LLM translator, update the Genai.Translator.Config. Genai.Translator.Llm is also the default translator set in Genai.Translator.Config#translatorTypeName
Genai.Translator.Config.translatorTypeName = 'Genai.Translator.Llm';NOTE: This feature is currently in beta. While it's designed to be fully functional, please note that the accuracy of different models and prompts may vary. It's recommended to experiment with different LLMs to find the best results for your specific needs.
To set up the keys
a. For Azure OpenAI GPT-4 model
JavaScriptGenai.Llm.OpenAI.Config.forConfigKey(<gpt4model>).setSecretValue('apiKey', <apiKey>, ConfigOverride.APP); Genai.Llm.OpenAI.Config.forConfigKey(<gpt4model>).setConfigValue('apiBase', <apiBase>, ConfigOverride.APP); Genai.Llm.OpenAI.Config.forConfigKey(<gpt4model>).setConfigValue('apiVersion', <apiVersion>, ConfigOverride.APP);b. For Gemini
JavaScriptGenai.Llm.Gcp.Config.inst().setSecretValue('serviceAccountInfo', <serviceAccountInfo>, ConfigOverride.APP); Genai.Llm.Gcp.Config.inst().setConfigValue('project', <project>, ConfigOverride.APP); Genai.Llm.Gcp.Config.inst().setConfigValue('location', <location>, ConfigOverride.APP);similarly can be used with other LLM's by setting up their respective keys. For further assistance, refer to Setting up LLM. However, the LLM translation has only been tested with the
azureGpt4oandgeminimodels.To set up the LLM translator
JavaScripttranslatorConfig = Genai.Translator.Config.getConfig(); translatorConfig.setConfigValue('enabled', true); translatorConfig.setConfigValue("translatorTypeName", Genai.Translator.Llm); translatorConfig.setConfigValue("llmConfigName", <llmModelName>);By default, the LLM translator is set to use the
azureGpt4omodel.
Setting up different translation services for document and query translation
You can configure separate translator type names for document translation, query translation, and language detection. If a type name is not explicitly specified, the system will fall back to the default translator.
translatorConfig = Genai.Translator.Config.getConfig();
translatorConfig.setConfigValue('languageDetectionHandlerTypeName', 'Genai.Translator.Google');
translatorConfig.setConfigValue('queryTranslatorTypeName', 'Genai.Translator.Llm');
translatorConfig.setConfigValue("documentTranslatorTypeName", 'Genai.Translator.Google_file');