Skip to content

Commit 6fe5fe7

Browse files
committed
Requested changes
1 parent 42d7d22 commit 6fe5fe7

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

.pipeline/spotbugs-exclusions.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
<Package name="com.sap.ai.sdk.grounding.model"/>
1010
</Or>
1111
</Match>
12+
<Match>
13+
<Class name="com.sap.ai.sdk.orchestration.ResponseJsonSchema" />
14+
<Method name="withStrict" />
15+
<Bug pattern="RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN" />
16+
</Match>
1217
</FindBugsFilter>

orchestration/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<coverage.complexity>82%</coverage.complexity>
3535
<coverage.line>93%</coverage.line>
3636
<coverage.instruction>94%</coverage.instruction>
37-
<coverage.branch>74%</coverage.branch>
37+
<coverage.branch>76%</coverage.branch>
3838
<coverage.method>93%</coverage.method>
3939
<coverage.class>100%</coverage.class>
4040
</properties>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class OrchestrationModuleConfig {
6262
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/templating">SAP
6363
* AI Core: Orchestration - Templating</a>
6464
*/
65-
@With @Nullable TemplatingModuleConfig templateConfig;
65+
@Nullable TemplatingModuleConfig templateConfig;
6666

6767
/**
6868
* A masking configuration to pseudonymous or anonymize sensitive data in the input.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.sap.ai.sdk.orchestration.model.TemplatingModuleConfig;
1212
import java.util.ArrayList;
1313
import java.util.HashMap;
14-
import java.util.LinkedHashMap;
1514
import java.util.List;
1615
import java.util.Map;
1716
import javax.annotation.Nonnull;
@@ -37,14 +36,13 @@
3736
@Beta
3837
public class OrchestrationTemplate extends TemplateConfig {
3938
@Nullable List<ChatMessage> template;
40-
@Nonnull Map<String, String> defaults = new HashMap<>();
39+
@Nullable Map<String, String> defaults;
4140

4241
@With(AccessLevel.PRIVATE)
4342
@Nullable
4443
TemplateResponseFormat responseFormat;
4544

46-
@Nonnull List<ChatCompletionTool> tools = new ArrayList<>();
47-
@Nonnull Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
45+
@Nullable List<ChatCompletionTool> tools;
4846

4947
/**
5048
* Create a low-level representation of the template.
@@ -55,6 +53,8 @@ public class OrchestrationTemplate extends TemplateConfig {
5553
@Nonnull
5654
protected TemplatingModuleConfig toLowLevel() {
5755
final List<ChatMessage> template = this.template != null ? this.template : List.of();
56+
final Map<String, String> defaults = this.defaults != null ? this.defaults : new HashMap<>();
57+
final List<ChatCompletionTool> tools = this.tools != null ? this.tools : new ArrayList<>();
5858
return Template.create()
5959
.template(template)
6060
.defaults(defaults)
@@ -77,7 +77,7 @@ public OrchestrationTemplate withJsonSchemaResponse(@Nonnull final ResponseJsonS
7777
ResponseFormatJsonSchemaJsonSchema.create()
7878
.name(schema.getName())
7979
.schema(schema.getSchemaMap())
80-
.strict(schema.getIsStrict())
80+
.strict(schema.getStrict())
8181
.description(schema.getDescription()));
8282
return this.withResponseFormat(responseFormatJsonSchema);
8383
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,7 @@ public class ResponseJsonSchema {
3333
@Nonnull Map<String, Object> schemaMap;
3434
@Nonnull String name;
3535
@Nullable String description;
36-
37-
@With(AccessLevel.NONE)
38-
@Nullable
39-
Boolean isStrict;
40-
41-
/**
42-
* Create a new instance of {@link ResponseJsonSchema} with the given strictness.
43-
*
44-
* @return A new ResponseJsonSchema instance with the given strictness
45-
*/
46-
@Nonnull
47-
public ResponseJsonSchema withStrict(@Nullable final Boolean isStrict) {
48-
return new ResponseJsonSchema(schemaMap, name, description, isStrict);
49-
}
36+
@Nullable Boolean strict;
5037

5138
/**
5239
* Create a new instance of {@link ResponseJsonSchema} with the given schema map and name.

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.sap.ai.sdk.orchestration.model.ChatCompletionTool;
7+
import com.sap.ai.sdk.orchestration.model.ChatMessage;
8+
import com.sap.ai.sdk.orchestration.model.FunctionObject;
9+
import com.sap.ai.sdk.orchestration.model.ResponseFormatJsonObject;
610
import com.sap.ai.sdk.orchestration.model.ResponseFormatJsonSchema;
711
import com.sap.ai.sdk.orchestration.model.ResponseFormatJsonSchemaJsonSchema;
12+
import com.sap.ai.sdk.orchestration.model.SingleChatMessage;
813
import com.sap.ai.sdk.orchestration.model.Template;
914
import com.sap.ai.sdk.orchestration.model.TemplateRef;
1015
import com.sap.ai.sdk.orchestration.model.TemplateRefByID;
@@ -113,6 +118,34 @@ void testConfigWithResponseSchema() {
113118
assertThat(configWithResponseSchemaFromClass).isEqualTo(configWithResponseSchemaLowLevel);
114119
}
115120

121+
@Test
122+
void testTemplateConstruction() {
123+
List<ChatMessage> templateMessages =
124+
List.of(SingleChatMessage.create().role("user").content("message"));
125+
var defaults = Map.of("key", "value");
126+
var tools =
127+
List.of(
128+
ChatCompletionTool.create()
129+
.type(ChatCompletionTool.TypeEnum.FUNCTION)
130+
.function(FunctionObject.create().name("func")));
131+
var template =
132+
TemplateConfig.create()
133+
.withTemplate(templateMessages)
134+
.withDefaults(defaults)
135+
.withTools(tools)
136+
.withJsonResponse();
137+
138+
var templateLowLevel =
139+
Template.create()
140+
.template(templateMessages)
141+
.defaults(defaults)
142+
.responseFormat(
143+
ResponseFormatJsonObject.create()
144+
.type(ResponseFormatJsonObject.TypeEnum.JSON_OBJECT))
145+
.tools(tools);
146+
assertThat(template.toLowLevel()).isEqualTo(templateLowLevel);
147+
}
148+
116149
@Test
117150
void testTemplateReferenceConstruction() {
118151
var templateReferenceId = TemplateConfig.reference().byId("id");

0 commit comments

Comments
 (0)