Skip to content

Commit ffbbe41

Browse files
chore: [Orchestration] Add E2E test for grounding via Sharepoint (#458)
* WiP * Add e2e test * Add endpoint for sample app * delete unnecessary * Formatting * retrigger tests after formatting 🙄 --------- Co-authored-by: Jonas Israel <[email protected]> Co-authored-by: SAP Cloud SDK Bot <[email protected]>
1 parent 92df9ae commit ffbbe41

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ Object grounding(
224224
return response.getContent();
225225
}
226226

227+
@GetMapping("/groundingSharepoint")
228+
@Nonnull
229+
Object groundingSharepoint(
230+
@Nullable @RequestParam(value = "format", required = false) final String format) {
231+
final var response = service.groundingSharepoint("What is the secret for the AI SDK e2e test?");
232+
if ("json".equals(format)) {
233+
return response;
234+
}
235+
return response.getContent();
236+
}
237+
227238
@GetMapping("/groundingHelpSapCom")
228239
@Nonnull
229240
Object groundingHelpSapCom(

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OrchestrationService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,34 @@ public OrchestrationChatResponse grounding(
362362
return client.chatCompletion(prompt, configWithGrounding);
363363
}
364364

365+
/**
366+
* Using grounding via a sharepoint repository to provide additional context to the AI model.
367+
*
368+
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/grounding">SAP
369+
* AI Core: Orchestration - Grounding</a>
370+
* @param userMessage the user message to provide grounding for
371+
* @return the assistant response object
372+
*/
373+
@Nonnull
374+
public OrchestrationChatResponse groundingSharepoint(@Nonnull final String userMessage) {
375+
// The sharepoint for this test is in the resource group "ai-sdk-js-e2e"
376+
// under repository ID "0bd2adc2-8d0d-478a-94f6-a0c10958f602".
377+
val destination =
378+
new AiCoreService().getInferenceDestination("ai-sdk-js-e2e").forScenario("orchestration");
379+
val customClient = new OrchestrationClient(destination);
380+
val dataRepositoryId = "0bd2adc2-8d0d-478a-94f6-a0c10958f602";
381+
382+
val filter =
383+
DocumentGroundingFilter.create()
384+
.dataRepositoryType(DataRepositoryType.VECTOR)
385+
.dataRepositories(List.of(dataRepositoryId))
386+
.searchConfig(GroundingFilterSearchConfiguration.create().maxChunkCount(1));
387+
val groundingConfig = Grounding.create().filters(filter);
388+
val prompt = groundingConfig.createGroundingPrompt(userMessage);
389+
val configWithGrounding = config.withGrounding(groundingConfig);
390+
return customClient.chatCompletion(prompt, configWithGrounding);
391+
}
392+
365393
/**
366394
* Using grounding via *help.sap.com* to provide additional SAP-specific context to the AI model.
367395
*

sample-code/spring-app/src/main/resources/static/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,19 @@ <h2>Orchestration</h2>
429429
</div>
430430
</div>
431431
</li>
432+
<li class="list-group-item">
433+
<div class="info-tooltip">
434+
<button type="submit"
435+
formaction="/orchestration/groundingSharepoint"
436+
class="link-offset-2-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover endpoint">
437+
<code>/orchestration/groundingSharepoint</code>
438+
</button>
439+
<div class="tooltip-content">
440+
Using grounding via a sharepoint repository to provide
441+
additional context to the AI model.
442+
</div>
443+
</div>
444+
</li>
432445
<li class="list-group-item">
433446
<div class="info-tooltip">
434447
<button type="submit"

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ void testGrounding() {
197197
assertThat(maskingResult.getMessage()).isNotEmpty();
198198
}
199199

200+
@Test
201+
@DisabledIfSystemProperty(named = "aicore.landscape", matches = "production")
202+
void testGroundingSharepoint() {
203+
assertThat(System.getProperty("aicore.landscape")).isNotEqualTo("production");
204+
var response = service.groundingSharepoint("What is the secret for the AI SDK e2e test?");
205+
assertThat(response).isNotNull();
206+
var result = response.getOriginalResponse();
207+
var llmChoice =
208+
((LLMModuleResultSynchronous) result.getOrchestrationResult()).getChoices().get(0);
209+
assertThat(llmChoice.getMessage().getContent()).contains("&)UPnkL_izT)&1u%?2Kg*Y.@qFqR@/");
210+
}
211+
200212
@Test
201213
void testCompletionWithResourceGroup() {
202214
var response = service.completionWithResourceGroup("ai-sdk-java-e2e", "Hello world!");

0 commit comments

Comments
 (0)