Skip to content

Commit 5045cc1

Browse files
committed
Minor comments
1 parent a394527 commit 5045cc1

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

docs/adrs/003-code-generation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@ For the **foundation models** we choose alternative **2**, generating about 80-9
7878

7979
For the **orchestration service** we choose a mix of alternatives **2** and **3**.
8080
The main reason is that the desired API quality and stability can not be achieved with generated code alone.
81+
8182
- We generate all DTO classes but mark them as beta and leave them in a dedicated `.dto` package.
8283
- We offer a hand-crafted convenience API on top that uses the DTO objects internally.
8384
- The convenience API is considered stable and is tested in full
8485
- The convenience API has the best API quality, but may not cover all edge cases and not allow for arbitrary customization
8586
- Users may transition to the low-level API, directly working with the DTOs, if the convenience API isn't flexible enough for their use case
87+
88+
Key benefits:
89+
- We can guarantee API stability and quality for the orchestration service
90+
- Allows for additional convenience & clarity (e.g. azure content filter levels, flattened out API, smart defaults etc.)
91+
- Clear separation of concerns: User-facing API vs. POJOs for JSON (de-) serialization
92+
- Avoid feature gaps in the generator impacting end users
93+
-

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum Sensitivity {
2323
HIGH(0),
2424
MEDIUM(2),
2525
LOW(4);
26-
26+
// note: we leave out the value 6, as setting it is equivalent to not setting the filter at all
2727
private final int value;
2828
}
2929

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import lombok.NoArgsConstructor;
2121
import lombok.val;
2222

23+
/**
24+
* Factory to create all DTOs from an orchestration configuration.
25+
*/
2326
@NoArgsConstructor(access = AccessLevel.NONE)
2427
final class ModuleConfigFactory {
2528
@Nonnull
2629
static ModuleConfigs toModuleConfigDTO(
2730
@Nonnull final OrchestrationConfig<?> config, @Nonnull final List<Message> messages) {
28-
val llm =
31+
val llmDto =
2932
config
3033
.getLlmConfig()
3134
.map(ModuleConfigFactory::toLlmModuleConfigDTO)
@@ -34,15 +37,15 @@ static ModuleConfigs toModuleConfigDTO(
3437
val template = config.getTemplate().getOrElse(() -> TemplateConfig.fromMessages(List.of()));
3538
val templateDto = toTemplateModuleConfigDTO(template, messages);
3639

37-
var dto = ModuleConfigs.create().llmModuleConfig(llm).templatingModuleConfig(templateDto);
40+
var resultDto = ModuleConfigs.create().llmModuleConfig(llmDto).templatingModuleConfig(templateDto);
3841

3942
config
4043
.getMaskingConfig()
4144
.filter(DpiMaskingConfig.class::isInstance)
4245
.map(DpiMaskingConfig.class::cast)
4346
.map(DpiMaskingConfig::toMaskingProviderDTO)
4447
.map(it -> MaskingModuleConfig.create().maskingProviders(it))
45-
.forEach(dto::maskingModuleConfig);
48+
.forEach(resultDto::maskingModuleConfig);
4649

4750
val maybeInputFilter = config.getInputContentFilter();
4851
val maybeOutputFilter = config.getOutputContentFilter();
@@ -61,22 +64,22 @@ static ModuleConfigs toModuleConfigDTO(
6164
.map(AzureContentFilter::toFilterConfigDTO)
6265
.map(it -> OutputFilteringConfig.create().filters(it))
6366
.forEach(filter::output);
64-
dto = dto.filteringModuleConfig(filter);
67+
resultDto = resultDto.filteringModuleConfig(filter);
6568
}
6669

67-
return dto;
70+
return resultDto;
6871
}
6972

7073
@Nonnull
7174
static LLMModuleConfig toLlmModuleConfigDTO(@Nonnull final AiModel model) {
7275
if (model instanceof LlmConfig llmConfig) {
7376
return llmConfig.toLLMModuleConfigDTO();
7477
}
75-
val result = LLMModuleConfig.create().modelName(model.name()).modelParams(Map.of());
78+
val dto = LLMModuleConfig.create().modelName(model.name()).modelParams(Map.of());
7679
if (model.version() != null) {
77-
result.modelVersion(model.version());
80+
dto.modelVersion(model.version());
7881
}
79-
return result;
82+
return dto;
8083
}
8184

8285
@Nonnull

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.stream.Stream;
2222
import javax.annotation.Nonnull;
2323
import lombok.AllArgsConstructor;
24+
import lombok.RequiredArgsConstructor;
2425
import lombok.experimental.Delegate;
2526
import lombok.val;
2627
import org.apache.hc.client5.http.classic.methods.HttpPost;
@@ -29,7 +30,7 @@
2930
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
3031
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3132

32-
@AllArgsConstructor
33+
@RequiredArgsConstructor
3334
public class OrchestrationClient implements OrchestrationConfig<OrchestrationClient> {
3435
static final ObjectMapper JACKSON;
3536

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.sap.ai.sdk.app.controllers;
22

3+
import com.sap.ai.sdk.foundationmodels.openai.OpenAiModel;
34
import com.sap.ai.sdk.orchestration.AzureContentFilter;
45
import com.sap.ai.sdk.orchestration.AzureContentFilter.Sensitivity;
56
import com.sap.ai.sdk.orchestration.DpiMaskingConfig;
@@ -23,10 +24,9 @@
2324
@RestController
2425
@RequestMapping("/orchestration")
2526
class OrchestrationController {
26-
static final String MODEL = "gpt-35-turbo";
2727

2828
private final OrchestrationClient client =
29-
new OrchestrationClient().withLlmConfig(new LlmConfig(MODEL));
29+
new OrchestrationClient().withLlmConfig(OpenAiModel.GPT_35_TURBO);
3030

3131
/**
3232
* Chat request to OpenAI through the Orchestration service with a template

sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OrchestrationTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.assertj.core.api.Assertions.assertThat;
55
import static org.assertj.core.api.Assertions.assertThatThrownBy;
66

7+
import com.sap.ai.sdk.foundationmodels.openai.OpenAiModel;
78
import com.sap.ai.sdk.orchestration.AzureContentFilter;
89
import com.sap.ai.sdk.orchestration.OrchestrationClientException;
910
import com.sap.ai.sdk.orchestration.OrchestrationResponse;
@@ -39,7 +40,7 @@ void testCompletion() {
3940
assertThat(llm.getId()).isNotEmpty();
4041
assertThat(llm.getObject()).isEqualTo("chat.completion");
4142
assertThat(llm.getCreated()).isGreaterThan(1);
42-
assertThat(llm.getModel()).isEqualTo(OrchestrationController.MODEL);
43+
assertThat(llm.getModel()).isEqualTo(OpenAiModel.GPT_35_TURBO.name());
4344
var choices = llm.getChoices();
4445
assertThat(choices.get(0).getIndex()).isZero();
4546
assertThat(choices.get(0).getMessage().getContent()).isNotEmpty();
@@ -52,7 +53,7 @@ void testCompletion() {
5253
assertThat(responseDto.getOrchestrationResult().getObject()).isEqualTo("chat.completion");
5354
assertThat(responseDto.getOrchestrationResult().getCreated()).isGreaterThan(1);
5455
assertThat(responseDto.getOrchestrationResult().getModel())
55-
.isEqualTo(OrchestrationController.MODEL);
56+
.isEqualTo(OpenAiModel.GPT_35_TURBO.name());
5657
choices = responseDto.getOrchestrationResult().getChoices();
5758
assertThat(choices.get(0).getIndex()).isZero();
5859
assertThat(choices.get(0).getMessage().getContent()).isNotEmpty();

0 commit comments

Comments
 (0)