Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions docs-js/orchestration/chat-completion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,79 @@
});
```

### 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 no `applyTo` selector is defined, the system translates all applicable content without selective filtering.
For more information about this feature please refer to [this](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/enhance-model-consumption-with-translation#loio152a5f4796f9493d98323786571356bf__section_rck_4gp_2hc) link.

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

Check warning on line 811 in docs-js/orchestration/chat-completion.mdx

View workflow job for this annotation

GitHub Actions / checks

[vale] reported by reviewdog 🐶 [SAP.SentencesList] Each sentence should have it's own line. Raw Output: {"message": "[SAP.SentencesList] Each sentence should have it's own line.", "location": {"path": "docs-js/orchestration/chat-completion.mdx", "range": {"start": {"line": 811, "column": 57}}}, "severity": "WARNING"}
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.
Expand Down