Skip to content

Commit c78a07b

Browse files
committed
Extend test to use additional model classes
1 parent 077e632 commit c78a07b

File tree

2 files changed

+57
-83
lines changed

2 files changed

+57
-83
lines changed

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@
4444
import com.sap.ai.sdk.orchestration.model.DataRepositoryType;
4545
import com.sap.ai.sdk.orchestration.model.DocumentGroundingFilter;
4646
import com.sap.ai.sdk.orchestration.model.GenericModuleResult;
47+
import com.sap.ai.sdk.orchestration.model.GroundingFilterSearchConfiguration;
4748
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig;
4849
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfig;
4950
import com.sap.ai.sdk.orchestration.model.ImageContent;
5051
import com.sap.ai.sdk.orchestration.model.ImageContentImageUrl;
52+
import com.sap.ai.sdk.orchestration.model.KeyValueListPair;
5153
import com.sap.ai.sdk.orchestration.model.LLMModuleConfig;
5254
import com.sap.ai.sdk.orchestration.model.LLMModuleResult;
5355
import com.sap.ai.sdk.orchestration.model.LLMModuleResultSynchronous;
5456
import com.sap.ai.sdk.orchestration.model.ModuleConfigs;
5557
import com.sap.ai.sdk.orchestration.model.MultiChatMessage;
5658
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;
5761
import com.sap.ai.sdk.orchestration.model.Template;
5862
import com.sap.ai.sdk.orchestration.model.TextContent;
5963
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor;
@@ -141,10 +145,18 @@ void testGrounding() throws IOException {
141145
.withBodyFile("groundingResponse.json")
142146
.withHeader("Content-Type", "application/json")));
143147

148+
final var documentMetadata =
149+
SearchDocumentKeyValueListPair.create()
150+
.key("document metadata")
151+
.value("2")
152+
.selectMode(List.of(SearchSelectOptionEnum.IGNORE_IF_KEY_ABSENT));
144153
final var databaseFilter =
145154
DocumentGroundingFilter.create()
146155
.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")));
148160
final var groundingConfigConfig =
149161
GroundingModuleConfigConfig.create()
150162
.inputParams(List.of("query"))
@@ -184,46 +196,6 @@ void testGrounding() throws IOException {
184196
"First chunk```Second chunk```Last found chunk");
185197
assertThat(groundingModule.getData()).isEqualTo(groundingData);
186198

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-
227199
final String requestBody = new String(fileLoader.apply("groundingRequest.json").readAllBytes());
228200
verify(
229201
postRequestedFor(urlPathEqualTo("/completion")).withRequestBody(equalToJson(requestBody)));
Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
11
{
2-
"orchestration_config": {
3-
"module_configurations": {
4-
"llm_module_config": {
5-
"model_name": "gpt-35-turbo-16k",
6-
"model_params": {
7-
"max_tokens": 50,
8-
"temperature": 0.1,
9-
"frequency_penalty": 0,
10-
"presence_penalty": 0,
11-
"top_p": 1,
12-
"n": 1
2+
"orchestration_config" : {
3+
"module_configurations" : {
4+
"llm_module_config" : {
5+
"model_name" : "gpt-35-turbo-16k",
6+
"model_params" : {
7+
"max_tokens" : 50,
8+
"temperature" : 0.1,
9+
"frequency_penalty" : 0,
10+
"presence_penalty" : 0,
11+
"top_p" : 1,
12+
"n" : 1
1313
},
14-
"model_version": "latest"
14+
"model_version" : "latest"
1515
},
16-
"templating_module_config": {
17-
"template": [
18-
{
19-
"role": "system",
20-
"content": "Context message with embedded grounding results. {{?results}}"
21-
}
22-
]
16+
"templating_module_config" : {
17+
"template" : [ {
18+
"role" : "system",
19+
"content" : "Context message with embedded grounding results. {{?results}}"
20+
} ]
2321
},
24-
"grounding_module_config": {
25-
"type": "document_grounding_service",
26-
"config": {
27-
"filters": [
28-
{
29-
"id": "arbitrary-user-defined-id",
30-
"data_repositories": [
31-
"*"
32-
],
33-
"data_repository_type": "vector",
34-
"data_repository_metadata": [],
35-
"document_metadata": [],
36-
"chunk_metadata": []
37-
}
38-
],
39-
"input_params": [
40-
"query"
41-
],
42-
"output_param": "results"
22+
"grounding_module_config" : {
23+
"type" : "document_grounding_service",
24+
"config" : {
25+
"filters" : [ {
26+
"id" : "arbitrary-user-defined-id",
27+
"search_config" : {
28+
"max_chunk_count" : 3
29+
},
30+
"data_repositories" : [ "*" ],
31+
"data_repository_type" : "vector",
32+
"data_repository_metadata" : [ ],
33+
"document_metadata" : [ {
34+
"key" : "document metadata",
35+
"value" : [ "2" ],
36+
"select_mode" : [ "ignoreIfKeyAbsent" ]
37+
} ],
38+
"chunk_metadata" : [ {
39+
"key" : "chunk metadata",
40+
"value" : [ "1" ]
41+
} ]
42+
} ],
43+
"input_params" : [ "query" ],
44+
"output_param" : "results"
4345
}
4446
}
4547
},
46-
"stream": false
48+
"stream" : false
4749
},
48-
"input_params": {
49-
"query": "String used for similarity search in database"
50+
"input_params" : {
51+
"query" : "String used for similarity search in database"
5052
},
51-
"messages_history": []
53+
"messages_history" : [ ]
5254
}

0 commit comments

Comments
 (0)