C3 AI Documentation Home

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

  1. To set up the keys

    JavaScript
    googleTranslatorConfig = Genai.Llm.Gcp.Config.inst();
    googleTranslatorConfig.setSecretValue('serviceAccountInfo', '<serviceAccountInfo>');
    googleTranslatorConfig.setConfigValue('project', '<project>');
    googleTranslatorConfig.setConfigValue('location', '<location>');
  2. To set up the Google translator

    JavaScript
    translatorConfig = 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

JavaScript
Genai.Translator.Config.translatorTypeName = 'Genai.Translator.Azure';
  1. To set up the keys

    JavaScript
    azureTranslatorConfig = Genai.Translator.Azure.Config.getConfig();
    azureTranslatorConfig.setConfigValue('endPoint', '<endPoint>');
    azureTranslatorConfig.setConfigValue('region', '<region>');
    azureTranslatorConfig.setSecretValue('apiKey', '<apiKey>');
  2. To set up the Azure translator

    JavaScript
    translatorConfig = 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

JavaScript
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.

  1. To set up the keys

    a. For Azure OpenAI GPT-4 model

    JavaScript
    Genai.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

    JavaScript
    Genai.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 azureGpt4o and gemini models.

  2. To set up the LLM translator

    JavaScript
    translatorConfig = 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 azureGpt4o model.

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.

JavaScript
 translatorConfig = Genai.Translator.Config.getConfig();
 translatorConfig.setConfigValue('languageDetectionHandlerTypeName', 'Genai.Translator.Google');
 translatorConfig.setConfigValue('queryTranslatorTypeName', 'Genai.Translator.Llm');
 translatorConfig.setConfigValue("documentTranslatorTypeName", 'Genai.Translator.Google_file');
Was this page helpful?