Skip to content

Commit 77b8f20

Browse files
committed
Add javadoc and logging
1 parent e847328 commit 77b8f20

19 files changed

+355
-30
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package com.sap.ai.sdk.orchestration;
22

33
import javax.annotation.Nonnull;
4+
import javax.annotation.Nullable;
45

5-
public record AssistantMessage(@Nonnull String content) implements Message {
6+
/**
7+
* Response messages from an LLM.
8+
*
9+
* @param content the content, if any.
10+
* @see Message
11+
*/
12+
public record AssistantMessage(@Nullable String content) implements Message {
613
@Nonnull
714
@Override
815
public String type() {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
package com.sap.ai.sdk.orchestration;
22

3+
/**
4+
* A content filter configuration for orchestration requests.
5+
*
6+
* @see AzureContentFilter
7+
*/
38
public sealed interface ContentFilter permits AzureContentFilter {}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
import lombok.Setter;
1212
import lombok.ToString;
1313

14+
/**
15+
* Default implementation of the {@link OrchestrationConfig} interface. This class supports
16+
* delegation from other classes by accepting a wrapper instance.
17+
*
18+
* @param <T> The type of the wrapper object that delegates to this object, if any.
19+
*/
1420
@Data
1521
@Setter(AccessLevel.PRIVATE)
1622
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,37 @@
1313
import javax.annotation.Nonnull;
1414
import javax.annotation.Nullable;
1515
import lombok.AccessLevel;
16+
import lombok.Getter;
1617
import lombok.RequiredArgsConstructor;
1718
import lombok.Value;
1819
import lombok.val;
1920

21+
/**
22+
* Implementation of {@link MaskingConfig} for SAP Data Privacy Integration (DPI) service. Supports
23+
* both anonymization and pseudonymization of personally identifiable information.
24+
*/
2025
@Value
26+
@Getter(AccessLevel.PACKAGE)
2127
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
2228
public class DpiMaskingConfig implements MaskingConfig {
2329
@Nonnull MaskingProviderConfig.MethodEnum maskingMethod;
2430
@Nonnull List<DPIEntities> entities;
2531

32+
/**
33+
* Build a configuration applying anonymization.
34+
*
35+
* @return A builder configured for anonymization
36+
*/
2637
@Nonnull
2738
public static Builder anonymization() {
2839
return new DpiMaskingConfig.Builder(ANONYMIZATION);
2940
}
3041

42+
/**
43+
* Build a configuration applying pseudonymization.
44+
*
45+
* @return A builder configured for pseudonymization
46+
*/
3147
@Nonnull
3248
public static Builder pseudonymization() {
3349
return new DpiMaskingConfig.Builder(PSEUDONYMIZATION);
@@ -42,10 +58,22 @@ MaskingProviderConfig toMaskingProviderDTO() {
4258
.entities(entitiesDTO);
4359
}
4460

61+
/**
62+
* Builder for creating DPI masking configurations. Allows specifying which entity types should be
63+
* masked in the input text.
64+
*/
4565
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
4666
public static class Builder {
4767
private final MaskingProviderConfig.MethodEnum maskingMethod;
4868

69+
/**
70+
* Specifies which entities should be masked in the input text.
71+
*
72+
* @param entity An entity type to mask (required)
73+
* @param entities Additional entity types to mask (optional)
74+
* @return A configured {@link DpiMaskingConfig} instance
75+
* @see DPIEntities
76+
*/
4977
@Nonnull
5078
public DpiMaskingConfig withEntities(
5179
@Nonnull final DPIEntities entity, @Nullable final DPIEntities... entities) {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,47 @@
88
import javax.annotation.Nullable;
99
import lombok.val;
1010

11+
/**
12+
* Language model configuration for the orchestration service.
13+
*
14+
* <p>Please note that, depending on which model you are using, some parameters may be required.
15+
* Furthermore, do not set the "stream" parameter here but use {@link
16+
* OrchestrationClient#streamChatCompletion(String)} instead.
17+
*
18+
* @param name The name of the language model.
19+
* @param version Optional, the version of the language model.
20+
* @param parameters Optional, additional parameters of the language model.
21+
* @see AiModel
22+
* @see OrchestrationConfig#withLlmConfig(AiModel)
23+
*/
1124
public record LlmConfig(
1225
@Nonnull String name, @Nullable String version, @Nullable Map<String, ?> parameters)
1326
implements AiModel {
27+
/**
28+
* Reference a language model by name.
29+
*
30+
* @param name The name of the language model.
31+
*/
1432
public LlmConfig(@Nonnull final String name) {
1533
this(name, null, null);
1634
}
1735

36+
/**
37+
* Reference a language model by name and version.
38+
*
39+
* @param name The name of the language model.
40+
* @param version The version of the language model.
41+
*/
1842
public LlmConfig(@Nonnull final String name, @Nonnull final String version) {
1943
this(name, version, null);
2044
}
2145

46+
/**
47+
* Reference a language model by name and parameters.
48+
*
49+
* @param name The name of the language model.
50+
* @param parameters Additional parameters of the language model.
51+
*/
2252
public LlmConfig(@Nonnull final String name, @Nonnull final Map<String, ?> parameters) {
2353
this(name, null, parameters);
2454
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
package com.sap.ai.sdk.orchestration;
22

3+
/**
4+
* A masking configuration for orchestration requests.
5+
*
6+
* @see DpiMaskingConfig
7+
*/
38
public sealed interface MaskingConfig permits DpiMaskingConfig {}
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
package com.sap.ai.sdk.orchestration;
22

33
import javax.annotation.Nonnull;
4+
import javax.annotation.Nullable;
45

6+
/**
7+
* Represents messages that can be sent to and received from the orchestration service as part of a
8+
* template, message history or LLM response.
9+
*
10+
* @see UserMessage
11+
* @see SystemMessage
12+
* @see AssistantMessage
13+
*/
514
public interface Message {
615

16+
/**
17+
* Type (or sometimes role) of the message.
18+
*
19+
* @return the type of the message
20+
*/
721
@Nonnull
822
String type();
923

10-
@Nonnull
24+
/**
25+
* Content of the message.
26+
*
27+
* @return the content of the message. Can be {@code null}, unless specified otherwise by the
28+
* implementing type.
29+
*/
30+
@Nullable
1131
String content();
1232
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import javax.annotation.Nonnull;
2323
import lombok.RequiredArgsConstructor;
2424
import lombok.experimental.Delegate;
25+
import lombok.extern.slf4j.Slf4j;
2526
import lombok.val;
2627
import org.apache.hc.client5.http.classic.methods.HttpPost;
2728
import org.apache.hc.core5.http.ContentType;
2829
import org.apache.hc.core5.http.io.entity.StringEntity;
2930
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
3031
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3132

33+
@Slf4j
3234
@RequiredArgsConstructor
3335
public class OrchestrationClient implements OrchestrationConfig<OrchestrationClient> {
3436
static final ObjectMapper JACKSON;
@@ -52,6 +54,7 @@ public class OrchestrationClient implements OrchestrationConfig<OrchestrationCli
5254

5355
private interface IDelegate extends OrchestrationConfig<OrchestrationClient> {}
5456

57+
/** Default constructor. */
5558
public OrchestrationClient() {
5659
service = new AiCoreService();
5760
}
@@ -69,6 +72,9 @@ public String chatCompletion(@Nonnull final String userPrompt)
6972
val response = chatCompletion(new OrchestrationPrompt(userPrompt));
7073

7174
if (response.finishReason() == CONTENT_FILTER) {
75+
log.error(
76+
"Output content filter triggered. Full response details: {}",
77+
response.originalResponseDto());
7278
throw new OrchestrationClientException("Output content filter triggered");
7379
}
7480
return response.assistantMessage().getContent();
@@ -84,8 +90,16 @@ public String chatCompletion(@Nonnull final String userPrompt)
8490
@Nonnull
8591
public OrchestrationResponse chatCompletion(@Nonnull final OrchestrationPrompt prompt)
8692
throws OrchestrationClientException {
93+
log.debug(
94+
"""
95+
Performing request to orchestration service.
96+
Prompt: {}
97+
Defaults: {}
98+
""",
99+
prompt,
100+
clientConfig);
87101
val dto = prompt.toCompletionPostRequestDTO(clientConfig);
88-
102+
log.debug("Assembled data transfer object for request: {}", dto);
89103
val result = executeRequest(dto);
90104
return OrchestrationResponse.fromCompletionPostResponseDTO(result);
91105
}
@@ -107,6 +121,7 @@ protected CompletionPostResponse executeRequest(@Nonnull final CompletionPostReq
107121
final BasicClassicHttpRequest postRequest = new HttpPost("/completion");
108122
try {
109123
val json = JACKSON.writeValueAsString(request);
124+
log.debug("Serialized request into JSON payload: {}", json);
110125
postRequest.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
111126
} catch (final JsonProcessingException e) {
112127
throw new OrchestrationClientException("Failed to serialize request parameters", e);
@@ -120,6 +135,7 @@ protected CompletionPostResponse executeRequest(@Nonnull final CompletionPostReq
120135
CompletionPostResponse executeRequest(@Nonnull final BasicClassicHttpRequest request) {
121136
try {
122137
val destination = service.forDeploymentByScenario("orchestration").destination();
138+
log.debug("Using destination {} to connect to orchestration service", destination);
123139
val client = ApacheHttpClient5Accessor.getHttpClient(destination);
124140
return client.execute(
125141
request, new OrchestrationResponseHandler<>(CompletionPostResponse.class));

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

33
import javax.annotation.Nonnull;
44

5+
/** Exception thrown by the {@link OrchestrationClient} in case of an error. */
56
public class OrchestrationClientException extends RuntimeException {
6-
public OrchestrationClientException(@Nonnull final String msg, @Nonnull final Throwable cause) {
7-
super(msg, cause);
8-
}
97

8+
/**
9+
* Constructor.
10+
*
11+
* @param msg the error message
12+
*/
1013
public OrchestrationClientException(@Nonnull final String msg) {
1114
super(msg);
1215
}
16+
17+
/**
18+
* Constructor.
19+
*
20+
* @param msg the error message
21+
* @param cause the cause of the error
22+
*/
23+
public OrchestrationClientException(@Nonnull final String msg, @Nonnull final Throwable cause) {
24+
super(msg, cause);
25+
}
1326
}

0 commit comments

Comments
 (0)