Skip to content

Commit 523a6d9

Browse files
committed
Some code cleanup
1 parent 59bc45e commit 523a6d9

File tree

7 files changed

+289
-117
lines changed

7 files changed

+289
-117
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/** Endpoint for Configuration operations */
99
@SuppressWarnings("unused") // debug class that doesn't need to be tested
1010
@RestController
11-
public class ConfigurationController {
11+
class ConfigurationController {
1212

1313
private static final ConfigurationApi CLIENT = new ConfigurationApi();
1414

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class DeploymentController {
3131

3232
private static final DeploymentApi CLIENT = new DeploymentApi();
33-
private static final String RESSOURCE_GROUP = "default";
33+
private static final String RESOURCE_GROUP = "default";
3434

3535
/**
3636
* Create and delete a deployment with the Java specific configuration ID
@@ -40,15 +40,15 @@ class DeploymentController {
4040
*/
4141
@GetMapping("/by-config/{id}/createDelete")
4242
@Nullable
43-
public AiDeploymentDeletionResponse createAndDeleteDeploymentByConfigId(
43+
AiDeploymentDeletionResponse createAndDeleteDeploymentByConfigId(
4444
@Nonnull @PathVariable("id") final String configId) {
4545
final var deployment =
4646
CLIENT.create(
47-
RESSOURCE_GROUP, AiDeploymentCreationRequest.create().configurationId(configId));
47+
RESOURCE_GROUP, AiDeploymentCreationRequest.create().configurationId(configId));
4848

4949
// shortly after creation, the deployment will be status UNKNOWN.
5050
// We can directly DELETE it, without going through STOPPED
51-
return CLIENT.delete(RESSOURCE_GROUP, deployment.getId());
51+
return CLIENT.delete(RESOURCE_GROUP, deployment.getId());
5252
}
5353

5454
/**
@@ -62,7 +62,7 @@ public AiDeploymentDeletionResponse createAndDeleteDeploymentByConfigId(
6262
@GetMapping("/by-config/{id}/stop")
6363
@Nonnull
6464
@SuppressWarnings("unused") // debug method that doesn't need to be tested
65-
public List<AiDeploymentModificationResponse> stopByConfigId(
65+
List<AiDeploymentModificationResponse> stopByConfigId(
6666
@Nonnull @PathVariable("id") final String configId) {
6767
final List<AiDeployment> myDeployments = getAllByConfigId(configId);
6868
log.info("Found {} deployments to STOP", myDeployments.size());
@@ -72,7 +72,7 @@ public List<AiDeploymentModificationResponse> stopByConfigId(
7272
.map(
7373
deployment ->
7474
CLIENT.modify(
75-
RESSOURCE_GROUP,
75+
RESOURCE_GROUP,
7676
deployment.getId(),
7777
AiDeploymentModificationRequest.create()
7878
.targetStatus(AiDeploymentTargetStatus.STOPPED)))
@@ -90,14 +90,14 @@ public List<AiDeploymentModificationResponse> stopByConfigId(
9090
@GetMapping("/by-config/{id}/delete")
9191
@Nonnull
9292
@SuppressWarnings("unused") // debug method that doesn't need to be tested
93-
public List<AiDeploymentDeletionResponse> deleteByConfigId(
93+
List<AiDeploymentDeletionResponse> deleteByConfigId(
9494
@Nonnull @PathVariable("id") final String configId) {
9595
final List<AiDeployment> myDeployments = getAllByConfigId(configId);
9696
log.info("Found {} deployments to DELETE", myDeployments.size());
9797

9898
// DELETE my deployments
9999
return myDeployments.stream()
100-
.map(deployment -> CLIENT.delete(RESSOURCE_GROUP, deployment.getId()))
100+
.map(deployment -> CLIENT.delete(RESOURCE_GROUP, deployment.getId()))
101101
.toList();
102102
}
103103

@@ -109,8 +109,8 @@ public List<AiDeploymentDeletionResponse> deleteByConfigId(
109109
*/
110110
@GetMapping("/by-config/{id}/getAll")
111111
@Nonnull
112-
public List<AiDeployment> getAllByConfigId(@Nonnull @PathVariable("id") final String configId) {
113-
final AiDeploymentList deploymentList = CLIENT.query(RESSOURCE_GROUP);
112+
List<AiDeployment> getAllByConfigId(@Nonnull @PathVariable("id") final String configId) {
113+
final AiDeploymentList deploymentList = CLIENT.query(RESOURCE_GROUP);
114114

115115
return deploymentList.getResources().stream()
116116
.filter(deployment -> configId.equals(deployment.getConfigurationId()))
@@ -124,8 +124,8 @@ public List<AiDeployment> getAllByConfigId(@Nonnull @PathVariable("id") final St
124124
*/
125125
@GetMapping("/getAll")
126126
@Nullable
127-
public AiDeploymentList getAll() {
128-
return CLIENT.query(RESSOURCE_GROUP);
127+
AiDeploymentList getAll() {
128+
return CLIENT.query(RESOURCE_GROUP);
129129
}
130130

131131
/**
@@ -138,7 +138,7 @@ public AiDeploymentList getAll() {
138138
*/
139139
@Nonnull
140140
@SuppressWarnings("unused") // debug method that doesn't need to be tested
141-
public AiDeploymentCreationResponse createConfigAndDeploy(final OpenAiModel model) {
141+
AiDeploymentCreationResponse createConfigAndDeploy(final OpenAiModel model) {
142142

143143
// Create a configuration
144144
final var modelNameParameter =
@@ -154,12 +154,12 @@ public AiDeploymentCreationResponse createConfigAndDeploy(final OpenAiModel mode
154154
.addParameterBindingsItem(modelVersion);
155155

156156
final AiConfigurationCreationResponse configuration =
157-
new ConfigurationApi().create(RESSOURCE_GROUP, configurationBaseData);
157+
new ConfigurationApi().create(RESOURCE_GROUP, configurationBaseData);
158158

159159
// Create a deployment from the configuration
160160
final var deploymentCreationRequest =
161161
AiDeploymentCreationRequest.create().configurationId(configuration.getId());
162162

163-
return CLIENT.create(RESSOURCE_GROUP, deploymentCreationRequest);
163+
return CLIENT.create(RESOURCE_GROUP, deploymentCreationRequest);
164164
}
165165
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class OpenAiController {
4040
*/
4141
@GetMapping("/chatCompletion")
4242
@Nonnull
43-
public static OpenAiChatCompletionOutput chatCompletion() {
43+
OpenAiChatCompletionOutput chatCompletion() {
4444
return OpenAiClient.forModel(GPT_35_TURBO).chatCompletion("Who is the prettiest");
4545
}
4646

@@ -52,7 +52,7 @@ public static OpenAiChatCompletionOutput chatCompletion() {
5252
@SuppressWarnings("unused") // The end-to-end test doesn't use this method
5353
@GetMapping("/streamChatCompletionDeltas")
5454
@Nonnull
55-
public static ResponseEntity<ResponseBodyEmitter> streamChatCompletionDeltas() {
55+
ResponseEntity<ResponseBodyEmitter> streamChatCompletionDeltas() {
5656
final var msg = "Can you give me the first 100 numbers of the Fibonacci sequence?";
5757
final var request =
5858
new OpenAiChatCompletionParameters().addMessages(new OpenAiChatUserMessage().addText(msg));
@@ -97,7 +97,7 @@ private static String objectToJson(@Nonnull final Object obj) {
9797
@SuppressWarnings("unused") // The end-to-end test doesn't use this method
9898
@GetMapping("/streamChatCompletion")
9999
@Nonnull
100-
public static ResponseEntity<ResponseBodyEmitter> streamChatCompletion() {
100+
ResponseEntity<ResponseBodyEmitter> streamChatCompletion() {
101101
final var stream =
102102
OpenAiClient.forModel(GPT_35_TURBO)
103103
.withSystemPrompt("Be a good, honest AI and answer the following question:")
@@ -138,7 +138,7 @@ private static void send(
138138
*/
139139
@GetMapping("/chatCompletionImage")
140140
@Nonnull
141-
public static OpenAiChatCompletionOutput chatCompletionImage() {
141+
OpenAiChatCompletionOutput chatCompletionImage() {
142142
final var request =
143143
new OpenAiChatCompletionParameters()
144144
.addMessages(
@@ -158,7 +158,7 @@ public static OpenAiChatCompletionOutput chatCompletionImage() {
158158
*/
159159
@GetMapping("/chatCompletionTool")
160160
@Nonnull
161-
public static OpenAiChatCompletionOutput chatCompletionTools() {
161+
OpenAiChatCompletionOutput chatCompletionTools() {
162162
final var question =
163163
"A pair of rabbits is placed in a field. Each month, every pair produces one new pair, starting from the second month. How many rabbits will there be after 12 months?";
164164
final var par = Map.of("type", "object", "properties", Map.of("N", Map.of("type", "integer")));
@@ -184,7 +184,7 @@ public static OpenAiChatCompletionOutput chatCompletionTools() {
184184
*/
185185
@GetMapping("/embedding")
186186
@Nonnull
187-
public static OpenAiEmbeddingOutput embedding() {
187+
OpenAiEmbeddingOutput embedding() {
188188
final var request = new OpenAiEmbeddingParameters().setInput("Hello World");
189189

190190
return OpenAiClient.forModel(TEXT_EMBEDDING_ADA_002).embedding(request);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class OrchestrationController {
3939
*/
4040
@GetMapping("/completion")
4141
@Nonnull
42-
public OrchestrationChatResponse completion() {
42+
OrchestrationChatResponse completion() {
4343
final var prompt = new OrchestrationPrompt("Hello world! Why is this phrase so famous?");
4444

4545
return client.chatCompletion(prompt, config);
@@ -52,7 +52,7 @@ public OrchestrationChatResponse completion() {
5252
*/
5353
@GetMapping("/template")
5454
@Nonnull
55-
public OrchestrationChatResponse template() {
55+
OrchestrationChatResponse template() {
5656
final var template =
5757
new UserMessage("Reply with 'Orchestration Service is working!' in {{?language}}");
5858
final var templatingConfig = Template.create().template(List.of(template.createChatMessage()));
@@ -71,7 +71,7 @@ public OrchestrationChatResponse template() {
7171
*/
7272
@GetMapping("/messagesHistory")
7373
@Nonnull
74-
public OrchestrationChatResponse messagesHistory() {
74+
OrchestrationChatResponse messagesHistory() {
7575
final List<Message> messagesHistory =
7676
List.of(
7777
new UserMessage("What is the capital of France?"),
@@ -91,7 +91,7 @@ public OrchestrationChatResponse messagesHistory() {
9191
*/
9292
@GetMapping("/filter/{policy}")
9393
@Nonnull
94-
public OrchestrationChatResponse filter(
94+
OrchestrationChatResponse filter(
9595
@Nonnull @PathVariable("policy") final AzureFilterThreshold policy) {
9696
final var prompt =
9797
new OrchestrationPrompt(
@@ -118,16 +118,16 @@ public OrchestrationChatResponse filter(
118118
*/
119119
@GetMapping("/maskingAnonymization")
120120
@Nonnull
121-
public OrchestrationChatResponse maskingAnonymization() {
121+
OrchestrationChatResponse maskingAnonymization() {
122122
final var systemMessage =
123123
new SystemMessage(
124124
"Please evaluate the following user feedback and judge if the sentiment is positive or negative.");
125125
final var userMessage =
126126
new UserMessage(
127127
"""
128-
I think the SDK is good, but could use some further enhancements.
129-
My architect Alice and manager Bob pointed out that we need the grounding capabilities, which aren't supported yet.
130-
""");
128+
I think the SDK is good, but could use some further enhancements.
129+
My architect Alice and manager Bob pointed out that we need the grounding capabilities, which aren't supported yet.
130+
""");
131131

132132
final var prompt = new OrchestrationPrompt(systemMessage, userMessage);
133133
final var maskingConfig = DpiMasking.anonymization().withEntities(DPIEntities.PERSON);
@@ -144,7 +144,7 @@ public OrchestrationChatResponse maskingAnonymization() {
144144
*/
145145
@GetMapping("/maskingPseudonymization")
146146
@Nonnull
147-
public OrchestrationChatResponse maskingPseudonymization() {
147+
OrchestrationChatResponse maskingPseudonymization() {
148148
final var systemMessage =
149149
new SystemMessage(
150150
"""

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/** Endpoint for Scenario operations */
1111
@RestController
1212
@SuppressWarnings("unused") // debug method that doesn't need to be tested
13-
public class ScenarioController {
13+
class ScenarioController {
1414

1515
private static final ScenarioApi CLIENT = new ScenarioApi();
1616

@@ -32,7 +32,7 @@ AiScenarioList getScenarios() {
3232
*/
3333
@GetMapping("/models")
3434
@Nonnull
35-
public AiModelList getModels() {
35+
AiModelList getModels() {
3636
return CLIENT.queryModels("foundation-models", "default");
3737
}
3838
}

0 commit comments

Comments
 (0)