Skip to content

Commit b9cd64f

Browse files
committed
Added. More. Javadoc.
1 parent 77b8f20 commit b9cd64f

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,38 @@
1010
import lombok.experimental.Accessors;
1111
import lombok.val;
1212

13+
/**
14+
* Represents a content filter based on Azure AI Content Safety. Filters content based on up to four
15+
* categories: hate speech, self-harm, sexual content, and violence. Any category not set will not
16+
* be filtered.
17+
*/
1318
@Data
1419
@Accessors(fluent = true)
1520
public final class AzureContentFilter implements ContentFilter {
21+
/** The sensitivity level for hate speech, if any. */
1622
@Nullable private Sensitivity hate;
23+
24+
/** The sensitivity level for self-harm, if any. */
1725
@Nullable private Sensitivity selfHarm;
26+
27+
/** The sensitivity level for sexual content, if any. */
1828
@Nullable private Sensitivity sexual;
29+
30+
/** The sensitivity level for violence, if any. */
1931
@Nullable private Sensitivity violence;
2032

33+
/** The sensitivity level for the content filter categories. */
2134
@RequiredArgsConstructor
2235
public enum Sensitivity {
36+
/** High filter sensitivity, filtering out more content. */
2337
HIGH(0),
38+
/** Medium filter sensitivity, filtering out less content. */
2439
MEDIUM(2),
40+
/** Low filter sensitivity, filtering out the least content. */
2541
LOW(4);
42+
2643
// note: we leave out the value 6, as setting it is equivalent to not setting the filter at all
44+
/** The integer value of the sensitivity level, will be applied as threshold. */
2745
private final int value;
2846
}
2947

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
3131
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3232

33+
/**
34+
* Client to execute requests to the orchestration service. Can be configured to hold a default
35+
* {@link OrchestrationConfig} to be used for all requests. Configuration set on an {@link
36+
* OrchestrationPrompt} will take precedence upon execution.
37+
*/
3338
@Slf4j
3439
@RequiredArgsConstructor
3540
public class OrchestrationClient implements OrchestrationConfig<OrchestrationClient> {
@@ -104,20 +109,53 @@ public OrchestrationResponse chatCompletion(@Nonnull final OrchestrationPrompt p
104109
return OrchestrationResponse.fromCompletionPostResponseDTO(result);
105110
}
106111

112+
/**
113+
* Stream a completion for the given user message.
114+
*
115+
* @param prompt The user message.
116+
* @return A stream of message chunks.
117+
* @throws OrchestrationClientException If the request fails.
118+
*/
107119
@Nonnull
108120
public Stream<String> streamChatCompletion(@Nonnull final String prompt)
109121
throws OrchestrationClientException {
110122
throw new NotImplementedError();
111123
}
112124

125+
/**
126+
* Stream a completion for the given prompt.
127+
*
128+
* @param prompt The prompt, including messages and other configuration.
129+
* @return A stream of message chunks.
130+
* @throws OrchestrationClientException If the request fails.
131+
*/
113132
@Nonnull
114133
public Stream<String> streamChatCompletionDelta(@Nonnull final OrchestrationPrompt prompt)
115134
throws OrchestrationClientException {
116135
throw new NotImplementedError();
117136
}
118137

138+
/**
139+
* Serializes the given request, executes it and deserializes the response.
140+
*
141+
* <p>Override this method to customize the request execution. For example, to modify the request
142+
* object before it is sent, use:
143+
*
144+
* <pre>{@code
145+
* @Override
146+
* protected CompletionPostResponse executeRequest(@Nonnull CompletionPostRequest request) {
147+
* request.setCustomField("myField", "myValue");
148+
* return super.executeRequest(request);
149+
* }
150+
* }</pre>
151+
*
152+
* @param request The request DTO to send to orchestration.
153+
* @return The response DTO from orchestration.
154+
* @throws OrchestrationClientException If the request fails.
155+
*/
119156
@Nonnull
120-
protected CompletionPostResponse executeRequest(@Nonnull final CompletionPostRequest request) {
157+
protected CompletionPostResponse executeRequest(@Nonnull final CompletionPostRequest request)
158+
throws OrchestrationClientException {
121159
final BasicClassicHttpRequest postRequest = new HttpPost("/completion");
122160
try {
123161
val json = JACKSON.writeValueAsString(request);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ public record OrchestrationResponse(
2727
@Nonnull TokenUsage tokenUsage,
2828
@Nonnull CompletionPostResponse originalResponseDto) {
2929

30+
/** The reason why an assistant message finished. */
3031
@RequiredArgsConstructor
3132
public enum FinishReason {
33+
/** The assistant message finished normally. */
3234
STOP("stop"),
35+
/** The generated message is cut off because the maximum number of output tokens was reached. */
3336
MAX_TOKENS("max_tokens"),
37+
/** The generated message was filtered out by an output content filter. */
3438
CONTENT_FILTER("content_filter"),
39+
/** The assistant message finished with a non-standardized reason. */
3540
UNKNOWN("unknown");
3641

37-
@Nonnull final String value;
42+
/** String representation of the finish reason. */
43+
@Nonnull private final String value;
3844

3945
@Nonnull
4046
static FinishReason fromValue(@Nonnull final String value) {

0 commit comments

Comments
 (0)