diff --git a/docs-js/orchestration/chat-completion.mdx b/docs-js/orchestration/chat-completion.mdx index 051566705..4f674be63 100644 --- a/docs-js/orchestration/chat-completion.mdx +++ b/docs-js/orchestration/chat-completion.mdx @@ -804,6 +804,79 @@ const response = await orchestrationClient.chatCompletion({ }); ``` +### ApplyTo Selector + +The `applyTo` property in the translation configuration allows you to selectively translate which messages or parts of messages in the conversation should be translated. +This provides granular control over translation in multi-turn conversations. + +This selector is optional and allows specifying: + +- **`category`**: can be either `placeholders` or `template_roles`. +- **`items`**: array of specific placeholder or role names to apply the translation to. +- **`sourceLanguage`** (optional): source language for the items. If not specified, the detected language will be applied. + +When you don't define an `applyTo` selector, the system translates all applicable content without selective filtering. +For more information about this feature, refer to the [translation documentation](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/enhance-model-consumption-with-translation#loio152a5f4796f9493d98323786571356bf__section_rck_4gp_2hc). + +##### Placeholders + +The `placeholders` category allows translating specific placeholder values from the `placeholderValues` parameter of the `chatCompletion()` method. + +##### Template Roles + +The `template_roles` category allows translating template messages with specific message roles, such as `user`, `assistant`, or `system` messages in the prompt. + +```ts +const inputTranslation = buildTranslationConfig('input', { + sourceLanguage: 'en-US', + targetLanguage: 'de-DE', + applyTo: [ + { + category: 'placeholders', + items: ['country'], + sourceLanguage: 'en-US' + }, + { + category: 'placeholders', + items: ['groundingRequest'], + sourceLanguage: 'de-DE' + } + ] +}); + +const outputTranslation = buildTranslationConfig('output', { + sourceLanguage: 'en-US', + targetLanguage: 'de-DE', + applyTo: [ + { + category: 'template_roles', + items: ['user', 'assistant'], + sourceLanguage: 'de-DE' + } + ] +}); +``` + +#### Automatic Target Language Inference + +By detecting the source language from translation, the output translation can automatically respond in the user's original language. +There is no need to specify a fixed target language, instead reference the `applyTo` item from the input translation. + +For more information check out [this](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/enhance-model-consumption-with-output-translation-48be058d01bd4df2a82e5430561e6f44#automatic-target-language-inference) link. + +#### Chat History Control + +By default, chat history messages are translated. +If chat history message translation is not necessary, set the `translateMessagesHistory` to `false`. + +```ts +const translationConfig = buildTranslationConfig('input', { + sourceLanguage: 'de-DE', + targetLanguage: 'en-US', + translateMessagesHistory: false +}); +``` + ## Use JSON Configuration from AI Launchpad If you already have an orchestration workflow created in your SAP AI Launchpad instance, you can either download the configuration as a JSON file or copy the JSON string in code to configure the orchestration client.