|
44 | 44 | import com.sap.ai.sdk.orchestration.model.DataRepositoryType; |
45 | 45 | import com.sap.ai.sdk.orchestration.model.DocumentGroundingFilter; |
46 | 46 | import com.sap.ai.sdk.orchestration.model.GenericModuleResult; |
| 47 | +import com.sap.ai.sdk.orchestration.model.GroundingFilterSearchConfiguration; |
47 | 48 | import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig; |
48 | 49 | import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfig; |
49 | 50 | import com.sap.ai.sdk.orchestration.model.ImageContent; |
50 | 51 | import com.sap.ai.sdk.orchestration.model.ImageContentImageUrl; |
| 52 | +import com.sap.ai.sdk.orchestration.model.KeyValueListPair; |
51 | 53 | import com.sap.ai.sdk.orchestration.model.LLMModuleConfig; |
52 | 54 | import com.sap.ai.sdk.orchestration.model.LLMModuleResult; |
53 | 55 | import com.sap.ai.sdk.orchestration.model.LLMModuleResultSynchronous; |
54 | 56 | import com.sap.ai.sdk.orchestration.model.ModuleConfigs; |
55 | 57 | import com.sap.ai.sdk.orchestration.model.MultiChatMessage; |
56 | 58 | import com.sap.ai.sdk.orchestration.model.OrchestrationConfig; |
| 59 | +import com.sap.ai.sdk.orchestration.model.SearchDocumentKeyValueListPair; |
| 60 | +import com.sap.ai.sdk.orchestration.model.SearchSelectOptionEnum; |
57 | 61 | import com.sap.ai.sdk.orchestration.model.Template; |
58 | 62 | import com.sap.ai.sdk.orchestration.model.TextContent; |
59 | 63 | import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; |
@@ -141,10 +145,18 @@ void testGrounding() throws IOException { |
141 | 145 | .withBodyFile("groundingResponse.json") |
142 | 146 | .withHeader("Content-Type", "application/json"))); |
143 | 147 |
|
| 148 | + final var documentMetadata = |
| 149 | + SearchDocumentKeyValueListPair.create() |
| 150 | + .key("document metadata") |
| 151 | + .value("2") |
| 152 | + .selectMode(List.of(SearchSelectOptionEnum.IGNORE_IF_KEY_ABSENT)); |
144 | 153 | final var databaseFilter = |
145 | 154 | DocumentGroundingFilter.create() |
146 | 155 | .id("arbitrary-user-defined-id") |
147 | | - .dataRepositoryType(DataRepositoryType.VECTOR); |
| 156 | + .dataRepositoryType(DataRepositoryType.VECTOR) |
| 157 | + .searchConfig(GroundingFilterSearchConfiguration.create().maxChunkCount(3)) |
| 158 | + .documentMetadata(List.of(documentMetadata)) |
| 159 | + .chunkMetadata(List.of(KeyValueListPair.create().key("chunk metadata").value("1"))); |
148 | 160 | final var groundingConfigConfig = |
149 | 161 | GroundingModuleConfigConfig.create() |
150 | 162 | .inputParams(List.of("query")) |
@@ -184,46 +196,6 @@ void testGrounding() throws IOException { |
184 | 196 | "First chunk```Second chunk```Last found chunk"); |
185 | 197 | assertThat(groundingModule.getData()).isEqualTo(groundingData); |
186 | 198 |
|
187 | | - var systemMessage = (ChatMessage) moduleResults.getTemplating().get(0); |
188 | | - assertThat((systemMessage.getRole())).isEqualTo("system"); |
189 | | - assertThat(systemMessage.getContent()) |
190 | | - .isEqualTo( |
191 | | - "Context message with embedded grounding results. First chunk```Second chunk```Last found chunk"); |
192 | | - |
193 | | - var llmModule = (LLMModuleResultSynchronous) moduleResults.getLlm(); |
194 | | - assertThat(llmModule).isNotNull(); |
195 | | - assertThat(llmModule.getId()).isEqualTo("chatcmpl-Apz5s3CMf99jkOnxvPshH1rGLwvvU"); |
196 | | - assertThat(llmModule.getObject()).isEqualTo("chat.completion"); |
197 | | - assertThat(llmModule.getCreated()).isEqualTo(1736952936); |
198 | | - assertThat(llmModule.getModel()).isEqualTo("gpt-4o-2024-08-06"); |
199 | | - assertThat(llmModule.getSystemFingerprint()).isEqualTo("fp_f3927aa00d"); |
200 | | - assertThat(llmModule.getChoices()).hasSize(1); |
201 | | - assertThat(llmModule.getChoices().get(0).getIndex()).isZero(); |
202 | | - assertThat(llmModule.getChoices().get(0).getMessage().getContent()) |
203 | | - .isEqualTo("Response that makes uses of grounding results in the context message."); |
204 | | - assertThat(llmModule.getChoices().get(0).getMessage().getRole()).isEqualTo("assistant"); |
205 | | - assertThat(llmModule.getChoices().get(0).getFinishReason()).isEqualTo("stop"); |
206 | | - assertThat(llmModule.getUsage()).isNotNull(); |
207 | | - assertThat(llmModule.getUsage().getCompletionTokens()).isEqualTo(163); |
208 | | - assertThat(llmModule.getUsage().getPromptTokens()).isEqualTo(217); |
209 | | - assertThat(llmModule.getUsage().getTotalTokens()).isEqualTo(380); |
210 | | - |
211 | | - var orchestrationResult = |
212 | | - (LLMModuleResultSynchronous) response.getOriginalResponse().getOrchestrationResult(); |
213 | | - assertThat(orchestrationResult).isNotNull(); |
214 | | - assertThat(orchestrationResult.getId()).isEqualTo("chatcmpl-Apz5s3CMf99jkOnxvPshH1rGLwvvU"); |
215 | | - assertThat(orchestrationResult.getObject()).isEqualTo("chat.completion"); |
216 | | - assertThat(orchestrationResult.getCreated()).isEqualTo(1736952936); |
217 | | - assertThat(orchestrationResult.getModel()).isEqualTo("gpt-4o-2024-08-06"); |
218 | | - assertThat(orchestrationResult.getSystemFingerprint()).isEqualTo("fp_f3927aa00d"); |
219 | | - assertThat(orchestrationResult.getChoices()).hasSize(1); |
220 | | - assertThat(orchestrationResult.getChoices().get(0).getIndex()).isZero(); |
221 | | - assertThat(orchestrationResult.getChoices().get(0).getMessage().getContent()) |
222 | | - .isEqualTo("Response that makes uses of grounding results in the context message."); |
223 | | - assertThat(orchestrationResult.getChoices().get(0).getMessage().getRole()) |
224 | | - .isEqualTo("assistant"); |
225 | | - assertThat(orchestrationResult.getChoices().get(0).getFinishReason()).isEqualTo("stop"); |
226 | | - |
227 | 199 | final String requestBody = new String(fileLoader.apply("groundingRequest.json").readAllBytes()); |
228 | 200 | verify( |
229 | 201 | postRequestedFor(urlPathEqualTo("/completion")).withRequestBody(equalToJson(requestBody))); |
|
0 commit comments