Skip to content

Commit ca75f86

Browse files
committed
Updates
1 parent 817a5e9 commit ca75f86

File tree

8 files changed

+153
-78
lines changed

8 files changed

+153
-78
lines changed

docs/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
### 📈 Improvements
1818

19-
-[Orchestration] Added new API `SAPDocumentTranslationInput#getInputTranslationConfig` to extract input config.
19+
-[Orchestration] Added new API `TranslationConfig#getInputTranslationConfig` to extract input config.
2020

21-
-[Orchestration] Added new API `SAPDocumentTranslationOutput#getOutputTranslationConfig` to extract output config.
21+
-[Orchestration] Added new API `TranslationConfig#getOutputTranslationConfig` to extract output config.
2222

2323
### 🐛 Fixed Issues
2424

orchestration/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<coverage.instruction>94%</coverage.instruction>
4242
<coverage.branch>75%</coverage.branch>
4343
<coverage.method>93%</coverage.method>
44-
<coverage.class>100%</coverage.class>
44+
<coverage.class>98%</coverage.class>
4545
</properties>
4646

4747
<dependencies>

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfig.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,24 @@ public class OrchestrationModuleConfig {
100100
*/
101101
@Nullable GroundingModuleConfig groundingConfig;
102102

103+
/**
104+
* Configuration for translating input content before processing.
105+
*
106+
* @link <a
107+
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/enhance-model-consumption-with-translation">
108+
* SAP AI Core: Orchestration - Input Translation</a>
109+
* @since 1.8.0
110+
*/
103111
@Nullable SAPDocumentTranslationInput inputTranslationConfig;
104112

113+
/**
114+
* Configuration for translating output content after processing.
115+
*
116+
* @link <a
117+
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/enhance-model-consumption-with-output-translation">
118+
* SAP AI Core: Orchestration - Output Translation</a>
119+
* @since 1.8.0
120+
*/
105121
@Nullable SAPDocumentTranslationOutput outputTranslationConfig;
106122

107123
/** Configuration of optional streaming options for output filtering. */
@@ -119,11 +135,11 @@ public class OrchestrationModuleConfig {
119135
/**
120136
* Creates a new configuration with the given LLM configuration.
121137
*
138+
* @param aiModel The LLM configuration to use.
139+
* @return A new configuration with the given LLM configuration.
122140
* @link <a
123141
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/model-configuration">
124142
* SAP AI Core: Orchestration - Model Configuration</a>
125-
* @param aiModel The LLM configuration to use.
126-
* @return A new configuration with the given LLM configuration.
127143
*/
128144
@Tolerate
129145
@Nonnull
@@ -149,12 +165,12 @@ public OrchestrationModuleConfig withStreamConfig(
149165
/**
150166
* Creates a new configuration with the given Data Masking configuration.
151167
*
152-
* @link <a
153-
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/data-masking">SAP AI
154-
* Core: Orchestration - Data Masking</a>
155168
* @param maskingProvider The Data Masking configuration to use.
156169
* @param maskingProviders Additional Data Masking configurations to use.
157170
* @return A new configuration with the given Data Masking configuration.
171+
* @link <a
172+
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/data-masking">SAP AI
173+
* Core: Orchestration - Data Masking</a>
158174
*/
159175
@Tolerate
160176
@Nonnull
@@ -174,13 +190,13 @@ public OrchestrationModuleConfig withMaskingConfig(
174190
*
175191
* <p>Preferred over {@link #withFilteringConfig(FilteringModuleConfig)} for adding input filters.
176192
*
177-
* @link <a
178-
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/input-filtering">SAP
179-
* AI Core: Orchestration - Input Filtering</a>
180193
* @param contentFilter a filter to apply to the input.
181194
* @param contentFilters zero or more additional content filters to apply to the input.
182195
* @return a new {@code OrchestrationModuleConfig} instance with the specified input filters
183196
* added.
197+
* @link <a
198+
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/input-filtering">SAP
199+
* AI Core: Orchestration - Input Filtering</a>
184200
*/
185201
@Nonnull
186202
public OrchestrationModuleConfig withInputFiltering(
@@ -212,13 +228,13 @@ public OrchestrationModuleConfig withInputFiltering(
212228
* <p>Preferred over {@link #withFilteringConfig(FilteringModuleConfig)} for adding output
213229
* filters.
214230
*
215-
* @link <a
216-
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/output-filtering">SAP
217-
* AI Core: Orchestration - Output Filtering</a>
218231
* @param contentFilter a filter to apply to the input.
219232
* @param contentFilters zero or more additional content filters to apply to the input.
220233
* @return a new {@code OrchestrationModuleConfig} instance with the specified output filters
221234
* added.
235+
* @link <a
236+
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/output-filtering">SAP
237+
* AI Core: Orchestration - Output Filtering</a>
222238
*/
223239
@Nonnull
224240
public OrchestrationModuleConfig withOutputFiltering(
@@ -250,11 +266,11 @@ public OrchestrationModuleConfig withOutputFiltering(
250266
/**
251267
* Creates a new configuration with the given output filtering stream options.
252268
*
269+
* @param outputFilteringStreamOptions The output filtering stream options to use.
270+
* @return A new configuration with the given output filtering stream options.
253271
* @see <a
254272
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/streaming">Orchestration
255273
* documentation on streaming.</a>
256-
* @param outputFilteringStreamOptions The output filtering stream options to use.
257-
* @return A new configuration with the given output filtering stream options.
258274
*/
259275
@Nonnull
260276
OrchestrationModuleConfig withOutputFilteringStreamOptions(
@@ -277,10 +293,10 @@ OrchestrationModuleConfig withOutputFilteringStreamOptions(
277293
/**
278294
* Creates a new configuration with the given grounding configuration.
279295
*
280-
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/grounding">SAP
281-
* AI Core: Orchestration - Grounding</a>
282296
* @param groundingProvider The grounding configuration to use.
283297
* @return A new configuration with the given grounding configuration.
298+
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/grounding">SAP
299+
* AI Core: Orchestration - Grounding</a>
284300
*/
285301
@Nonnull
286302
public OrchestrationModuleConfig withGrounding(
@@ -291,10 +307,10 @@ public OrchestrationModuleConfig withGrounding(
291307
/**
292308
* Creates a new configuration with the given template configuration as {@link TemplateConfig}.
293309
*
294-
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/templating">SAP
295-
* AI Core: Orchestration - Templating</a>
296310
* @param templateConfig The template configuration to use.
297311
* @return A new configuration with the given template configuration.
312+
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/templating">SAP
313+
* AI Core: Orchestration - Templating</a>
298314
* @since 1.4.0
299315
*/
300316
@Tolerate
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.sap.ai.sdk.orchestration;
2+
3+
import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationInput;
4+
import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationInputConfig;
5+
import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutput;
6+
import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutputConfig;
7+
import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutputTargetLanguage;
8+
import javax.annotation.Nonnull;
9+
import lombok.AccessLevel;
10+
import lombok.Getter;
11+
import lombok.RequiredArgsConstructor;
12+
import lombok.Value;
13+
14+
/**
15+
* Configuration helper for SAP Document Translation.
16+
*
17+
* @link <a
18+
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/sap-document-translation">SAP
19+
* AI Core: Orchestration - SAP Document Translation</a>
20+
*/
21+
@Value
22+
@Getter(AccessLevel.PACKAGE)
23+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
24+
public class TranslationConfig {
25+
@Nonnull SAPDocumentTranslationInput.TypeEnum translationType;
26+
27+
/**
28+
* Create a builder for the SAP_DOCUMENT_TRANSLATION translation provider
29+
*
30+
* @return The Builder instance.
31+
*/
32+
@Nonnull
33+
public static Builder inputTranslation() {
34+
return new TranslationConfig.Builder(
35+
SAPDocumentTranslationInput.TypeEnum.SAP_DOCUMENT_TRANSLATION);
36+
}
37+
38+
/**
39+
* Create a builder for the SAP_DOCUMENT_TRANSLATION translation provider
40+
*
41+
* @return The Builder2 instance.
42+
*/
43+
@Nonnull
44+
public static Builder2 outputTranslation() {
45+
return new TranslationConfig.Builder2(
46+
SAPDocumentTranslationOutput.TypeEnum.SAP_DOCUMENT_TRANSLATION);
47+
}
48+
49+
/** Builder helper class. */
50+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
51+
public static class Builder {
52+
53+
private final SAPDocumentTranslationInput.TypeEnum translationType;
54+
55+
/**
56+
* Get the input translation config with default values.
57+
*
58+
* @return The SAPDocumentTranslationInput instance.
59+
*/
60+
@Nonnull
61+
public SAPDocumentTranslationInput getInputTranslationConfig() {
62+
return SAPDocumentTranslationInput.create()
63+
.type(translationType)
64+
.config(SAPDocumentTranslationInputConfig.create().targetLanguage("en-US").applyTo(null));
65+
}
66+
}
67+
68+
/** Sample builder class */
69+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
70+
public static class Builder2 {
71+
private final SAPDocumentTranslationOutput.TypeEnum translationType;
72+
73+
/**
74+
* Get the output translation config with default values.
75+
*
76+
* @return The SAPDocumentTranslationOutput instance.
77+
*/
78+
@Nonnull
79+
public SAPDocumentTranslationOutput getOutputTranslationConfig() {
80+
return SAPDocumentTranslationOutput.create()
81+
.type(translationType)
82+
.config(
83+
SAPDocumentTranslationOutputConfig.create()
84+
.targetLanguage(SAPDocumentTranslationOutputTargetLanguage.create("de-DE"))
85+
.sourceLanguage("en-US"));
86+
}
87+
}
88+
}

orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/SAPDocumentTranslationInput.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.Set;
2525
import javax.annotation.Nonnull;
2626
import javax.annotation.Nullable;
27-
import lombok.AccessLevel;
28-
import lombok.RequiredArgsConstructor;
2927

3028
/** SAPDocumentTranslationInput */
3129
// CHECKSTYLE:OFF
@@ -86,12 +84,6 @@ public static TypeEnum fromValue(@Nonnull final String value) {
8684
}
8785
}
8886

89-
/** Create a builder for the SAP_DOCUMENT_TRANSLATION translation provider */
90-
@Nonnull
91-
public static Builder2 sapDocumentTranslation() {
92-
return new Builder2(TypeEnum.SAP_DOCUMENT_TRANSLATION);
93-
}
94-
9587
@JsonProperty("type")
9688
private TypeEnum type;
9789

@@ -342,22 +334,4 @@ public interface Builder1 {
342334
*/
343335
SAPDocumentTranslationInput config(@Nonnull final SAPDocumentTranslationInputConfig config);
344336
}
345-
346-
/** Builder helper class. */
347-
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
348-
public static class Builder2 {
349-
350-
private final SAPDocumentTranslationInput.TypeEnum translationType;
351-
352-
/**
353-
* Get the input translation config with default values.
354-
*
355-
* @return The SAPDocumentTranslationInput instance.
356-
*/
357-
public SAPDocumentTranslationInput getInputTranslationConfig() {
358-
return SAPDocumentTranslationInput.create()
359-
.type(translationType)
360-
.config(SAPDocumentTranslationInputConfig.create().targetLanguage("en-US").applyTo(null));
361-
}
362-
}
363337
}

orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/SAPDocumentTranslationOutput.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.Set;
2525
import javax.annotation.Nonnull;
2626
import javax.annotation.Nullable;
27-
import lombok.AccessLevel;
28-
import lombok.RequiredArgsConstructor;
2927

3028
/** SAPDocumentTranslationOutput */
3129
// CHECKSTYLE:OFF
@@ -86,12 +84,6 @@ public static TypeEnum fromValue(@Nonnull final String value) {
8684
}
8785
}
8886

89-
/** Create a builder for the SAP_DOCUMENT_TRANSLATION translation provider */
90-
@Nonnull
91-
public static Builder2 sapDocumentTranslation() {
92-
return new Builder2(TypeEnum.SAP_DOCUMENT_TRANSLATION);
93-
}
94-
9587
@JsonProperty("type")
9688
private TypeEnum type;
9789

@@ -301,24 +293,4 @@ public interface Builder1 {
301293
*/
302294
SAPDocumentTranslationOutput config(@Nonnull final SAPDocumentTranslationOutputConfig config);
303295
}
304-
305-
/** Sample builder class */
306-
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
307-
public static class Builder2 {
308-
private final SAPDocumentTranslationOutput.TypeEnum translationType;
309-
310-
/**
311-
* Get the output translation config with default values.
312-
*
313-
* @return The SAPDocumentTranslationOutput instance.
314-
*/
315-
public SAPDocumentTranslationOutput getOutputTranslationConfig() {
316-
return SAPDocumentTranslationOutput.create()
317-
.type(translationType)
318-
.config(
319-
SAPDocumentTranslationOutputConfig.create()
320-
.targetLanguage(SAPDocumentTranslationOutputTargetLanguage.create("de-DE"))
321-
.sourceLanguage("en-US"));
322-
}
323-
}
324296
}

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfigTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,32 @@ void testDpiMaskingRegex() {
138138
.value("**-**-*****"));
139139
}
140140

141+
@Test
142+
void testTranslationConfig() {
143+
var translationConfig = TranslationConfig.inputTranslation().getInputTranslationConfig();
144+
var config =
145+
new OrchestrationModuleConfig()
146+
.withLlmConfig(GPT_4O)
147+
.withInputTranslationConfig(translationConfig);
148+
149+
assertThat(config.getInputTranslationConfig()).isNotNull();
150+
assertThat(config.getInputTranslationConfig().getType()).isEqualTo(translationConfig.getType());
151+
assertThat(config.getInputTranslationConfig().getConfig().getTargetLanguage())
152+
.isEqualTo(translationConfig.getConfig().getTargetLanguage());
153+
154+
var translationConfig2 = TranslationConfig.inputTranslation().getInputTranslationConfig();
155+
var config2 =
156+
new OrchestrationModuleConfig()
157+
.withLlmConfig(GPT_4O)
158+
.withInputTranslationConfig(translationConfig2);
159+
160+
assertThat(config2.getInputTranslationConfig()).isNotNull();
161+
assertThat(config2.getInputTranslationConfig().getType())
162+
.isEqualTo(translationConfig2.getType());
163+
assertThat(config2.getInputTranslationConfig().getConfig().getTargetLanguage())
164+
.isEqualTo(translationConfig2.getConfig().getTargetLanguage());
165+
}
166+
141167
@Test
142168
void testParams() {
143169
// test withParams(Map<String, Object>)

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OrchestrationService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
import com.sap.ai.sdk.orchestration.OrchestrationPrompt;
2424
import com.sap.ai.sdk.orchestration.ResponseJsonSchema;
2525
import com.sap.ai.sdk.orchestration.TemplateConfig;
26+
import com.sap.ai.sdk.orchestration.TranslationConfig;
2627
import com.sap.ai.sdk.orchestration.model.DPIEntities;
2728
import com.sap.ai.sdk.orchestration.model.DataRepositoryType;
2829
import com.sap.ai.sdk.orchestration.model.DocumentGroundingFilter;
2930
import com.sap.ai.sdk.orchestration.model.GroundingFilterSearchConfiguration;
3031
import com.sap.ai.sdk.orchestration.model.LlamaGuard38b;
3132
import com.sap.ai.sdk.orchestration.model.ResponseFormatText;
32-
import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationInput;
33-
import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutput;
3433
import com.sap.ai.sdk.orchestration.model.SearchDocumentKeyValueListPair;
3534
import com.sap.ai.sdk.orchestration.model.SearchSelectOptionEnum;
3635
import com.sap.ai.sdk.orchestration.model.Template;
@@ -614,9 +613,9 @@ public OrchestrationChatResponse translation() {
614613
val configWithTranslation =
615614
config
616615
.withInputTranslationConfig(
617-
SAPDocumentTranslationInput.sapDocumentTranslation().getInputTranslationConfig())
616+
TranslationConfig.inputTranslation().getInputTranslationConfig())
618617
.withOutputTranslationConfig(
619-
SAPDocumentTranslationOutput.sapDocumentTranslation()
618+
TranslationConfig.outputTranslation()
620619
.getOutputTranslationConfig()); // optional source language
621620

622621
return client.chatCompletion(prompt, configWithTranslation);

0 commit comments

Comments
 (0)