Skip to content

Commit adcf76e

Browse files
committed
test: Fix AI tests (box/box-codegen#886)
1 parent 6e36828 commit adcf76e

File tree

3 files changed

+26
-56
lines changed

3 files changed

+26
-56
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "2ac72c4", "specHash": "e7ce024", "version": "5.0.0" }
1+
{ "engineHash": "a17cbb6", "specHash": "e7ce024", "version": "5.0.0" }

docs/sdkgen/ai.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See the endpoint docs at
1818

1919
<!-- sample post_ai_ask -->
2020
```
21-
client.getAi().createAiAsk(new AiAsk.Builder(AiAskModeField.SINGLE_ITEM_QA, "which direction sun rises", Arrays.asList(new AiItemAsk.Builder(fileToAsk.getId(), AiItemAskTypeField.FILE).content("Sun rises in the East").build())).aiAgent(aiAskAgentConfig).build())
21+
client.getAi().createAiAsk(new AiAsk.Builder(AiAskModeField.SINGLE_ITEM_QA, "Which direction does the Sun rise?", Arrays.asList(new AiItemAsk.Builder(fileToAsk.getId(), AiItemAskTypeField.FILE).content("The Sun rises in the east").build())).aiAgent(aiAskAgentBasicTextConfig).build())
2222
```
2323

2424
### Arguments
@@ -47,7 +47,7 @@ See the endpoint docs at
4747

4848
<!-- sample post_ai_text_gen -->
4949
```
50-
client.getAi().createAiTextGen(new AiTextGen.Builder("Parapharse the document.s", Arrays.asList(new AiTextGenItemsField.Builder(fileToAsk.getId()).type(AiTextGenItemsTypeField.FILE).content("The Earth goes around the sun. Sun rises in the East in the morning.").build())).dialogueHistory(Arrays.asList(new AiDialogueHistory.Builder().prompt("What does the earth go around?").answer("The sun").createdAt(dateTimeFromString("2021-01-01T00:00:00Z")).build(), new AiDialogueHistory.Builder().prompt("On Earth, where does the sun rise?").answer("East").createdAt(dateTimeFromString("2021-01-01T00:00:00Z")).build())).aiAgent(aiTextGenAgentConfig).build())
50+
client.getAi().createAiTextGen(new AiTextGen.Builder("Paraphrase the documents", Arrays.asList(new AiTextGenItemsField.Builder(fileToAsk.getId()).type(AiTextGenItemsTypeField.FILE).content("The Earth goes around the Sun. The Sun rises in the east in the morning.").build())).dialogueHistory(Arrays.asList(new AiDialogueHistory.Builder().prompt("What does the earth go around?").answer("The Sun").createdAt(dateTimeFromString("2021-01-01T00:00:00Z")).build(), new AiDialogueHistory.Builder().prompt("On Earth, where does the Sun rise?").answer("east").createdAt(dateTimeFromString("2021-01-01T00:00:00Z")).build())).build())
5151
```
5252

5353
### Arguments
@@ -113,7 +113,7 @@ See the endpoint docs at
113113

114114
<!-- sample post_ai_extract -->
115115
```
116-
client.getAi().createAiExtract(new AiExtract.Builder("firstName, lastName, location, yearOfBirth, company", Arrays.asList(new AiItemBase(file.getId()))).aiAgent(agentIgnoringOverridingEmbeddingsModel).build())
116+
client.getAi().createAiExtract(new AiExtract.Builder("firstName, lastName, location, yearOfBirth, company", Arrays.asList(new AiItemBase(file.getId()))).aiAgent(aiExtractAgentBasicTextConfig).build())
117117
```
118118

119119
### Arguments
@@ -149,7 +149,7 @@ See the endpoint docs at
149149

150150
<!-- sample post_ai_extract_structured -->
151151
```
152-
client.getAi().createAiExtractStructured(new AiExtractStructured.Builder(Arrays.asList(new AiItemBase(file.getId()))).fields(Arrays.asList(new AiExtractStructuredFieldsField.Builder("firstName").description("Person first name").displayName("First name").prompt("What is the your first name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("lastName").description("Person last name").displayName("Last name").prompt("What is the your last name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("dateOfBirth").description("Person date of birth").displayName("Birth date").prompt("What is the date of your birth?").type("date").build(), new AiExtractStructuredFieldsField.Builder("age").description("Person age").displayName("Age").prompt("How old are you?").type("float").build(), new AiExtractStructuredFieldsField.Builder("hobby").description("Person hobby").displayName("Hobby").prompt("What is your hobby?").type("multiSelect").options(Arrays.asList(new AiExtractStructuredFieldsOptionsField("guitar"), new AiExtractStructuredFieldsOptionsField("books"))).build())).aiAgent(agentIgnoringOverridingEmbeddingsModel).build())
152+
client.getAi().createAiExtractStructured(new AiExtractStructured.Builder(Arrays.asList(new AiItemBase(file.getId()))).fields(Arrays.asList(new AiExtractStructuredFieldsField.Builder("firstName").description("Person first name").displayName("First name").prompt("What is the your first name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("lastName").description("Person last name").displayName("Last name").prompt("What is the your last name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("dateOfBirth").description("Person date of birth").displayName("Birth date").prompt("What is the date of your birth?").type("date").build(), new AiExtractStructuredFieldsField.Builder("age").description("Person age").displayName("Age").prompt("How old are you?").type("float").build(), new AiExtractStructuredFieldsField.Builder("hobby").description("Person hobby").displayName("Hobby").prompt("What is your hobby?").type("multiSelect").options(Arrays.asList(new AiExtractStructuredFieldsOptionsField("guitar"), new AiExtractStructuredFieldsOptionsField("books"))).build())).aiAgent(aiExtractStructuredAgentBasicTextConfig).build())
153153
```
154154

155155
### Arguments

src/intTest/java/com/box/sdkgen/ai/AiITest.java

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.box.sdkgen.schemas.aiagentask.AiAgentAsk;
2424
import com.box.sdkgen.schemas.aiagentextract.AiAgentExtract;
2525
import com.box.sdkgen.schemas.aiagentextractstructured.AiAgentExtractStructured;
26-
import com.box.sdkgen.schemas.aiagentlongtexttool.AiAgentLongTextTool;
2726
import com.box.sdkgen.schemas.aiagenttextgen.AiAgentTextGen;
2827
import com.box.sdkgen.schemas.aiask.AiAsk;
2928
import com.box.sdkgen.schemas.aiask.AiAskModeField;
@@ -63,21 +62,23 @@ public void testAskAiSingleItem() {
6362
.language("en-US")
6463
.build());
6564
AiAgentAsk aiAskAgentConfig = aiAgentConfig.getAiAgentAsk();
65+
AiAgentAsk aiAskAgentBasicTextConfig =
66+
new AiAgentAsk.Builder().basicText(aiAskAgentConfig.getBasicText()).build();
6667
FileFull fileToAsk = uploadNewFile();
6768
AiResponseFull response =
6869
client
6970
.getAi()
7071
.createAiAsk(
7172
new AiAsk.Builder(
7273
AiAskModeField.SINGLE_ITEM_QA,
73-
"which direction sun rises",
74+
"Which direction does the Sun rise?",
7475
Arrays.asList(
7576
new AiItemAsk.Builder(fileToAsk.getId(), AiItemAskTypeField.FILE)
76-
.content("Sun rises in the East")
77+
.content("The Sun rises in the east")
7778
.build()))
78-
.aiAgent(aiAskAgentConfig)
79+
.aiAgent(aiAskAgentBasicTextConfig)
7980
.build());
80-
assert response.getAnswer().contains("East");
81+
assert response.getAnswer().contains("east");
8182
assert response.getCompletionReason().equals("done");
8283
client.getFiles().deleteFileById(fileToAsk.getId());
8384
}
@@ -92,15 +93,15 @@ public void testAskAiMultipleItems() {
9293
.createAiAsk(
9394
new AiAsk(
9495
AiAskModeField.MULTIPLE_ITEM_QA,
95-
"Which direction sun rises?",
96+
"Which direction does the Sun rise?",
9697
Arrays.asList(
9798
new AiItemAsk.Builder(fileToAsk1.getId(), AiItemAskTypeField.FILE)
98-
.content("Earth goes around the sun")
99+
.content("Earth goes around the Sun")
99100
.build(),
100101
new AiItemAsk.Builder(fileToAsk2.getId(), AiItemAskTypeField.FILE)
101-
.content("Sun rises in the East in the morning")
102+
.content("The Sun rises in the east in the morning")
102103
.build())));
103-
assert response.getAnswer().contains("East");
104+
assert response.getAnswer().contains("east");
104105
assert response.getCompletionReason().equals("done");
105106
client.getFiles().deleteFileById(fileToAsk1.getId());
106107
client.getFiles().deleteFileById(fileToAsk2.getId());
@@ -109,42 +110,32 @@ public void testAskAiMultipleItems() {
109110
@Test
110111
public void testAiTextGenWithDialogueHistory() {
111112
FileFull fileToAsk = uploadNewFile();
112-
AiAgent aiAgentConfig =
113-
client
114-
.getAi()
115-
.getAiAgentDefaultConfig(
116-
new GetAiAgentDefaultConfigQueryParams.Builder(
117-
GetAiAgentDefaultConfigQueryParamsModeField.TEXT_GEN)
118-
.language("en-US")
119-
.build());
120-
AiAgentTextGen aiTextGenAgentConfig = aiAgentConfig.getAiAgentTextGen();
121113
AiResponse response =
122114
client
123115
.getAi()
124116
.createAiTextGen(
125117
new AiTextGen.Builder(
126-
"Parapharse the document.s",
118+
"Paraphrase the documents",
127119
Arrays.asList(
128120
new AiTextGenItemsField.Builder(fileToAsk.getId())
129121
.type(AiTextGenItemsTypeField.FILE)
130122
.content(
131-
"The Earth goes around the sun. Sun rises in the East in the morning.")
123+
"The Earth goes around the Sun. The Sun rises in the east in the morning.")
132124
.build()))
133125
.dialogueHistory(
134126
Arrays.asList(
135127
new AiDialogueHistory.Builder()
136128
.prompt("What does the earth go around?")
137-
.answer("The sun")
129+
.answer("The Sun")
138130
.createdAt(dateTimeFromString("2021-01-01T00:00:00Z"))
139131
.build(),
140132
new AiDialogueHistory.Builder()
141-
.prompt("On Earth, where does the sun rise?")
142-
.answer("East")
133+
.prompt("On Earth, where does the Sun rise?")
134+
.answer("east")
143135
.createdAt(dateTimeFromString("2021-01-01T00:00:00Z"))
144136
.build()))
145-
.aiAgent(aiTextGenAgentConfig)
146137
.build());
147-
assert response.getAnswer().contains("sun");
138+
assert response.getAnswer().contains("Sun");
148139
assert response.getCompletionReason().equals("done");
149140
client.getFiles().deleteFileById(fileToAsk.getId());
150141
}
@@ -215,19 +206,8 @@ public void testAiExtract() {
215206
.language("en-US")
216207
.build());
217208
AiAgentExtract aiExtractAgentConfig = aiAgentConfig.getAiAgentExtract();
218-
AiAgentLongTextTool longTextConfigWithNoEmbeddings =
219-
new AiAgentLongTextTool.Builder()
220-
.systemMessage(aiExtractAgentConfig.getLongText().getSystemMessage())
221-
.promptTemplate(aiExtractAgentConfig.getLongText().getPromptTemplate())
222-
.model(aiExtractAgentConfig.getLongText().getModel())
223-
.numTokensForCompletion(aiExtractAgentConfig.getLongText().getNumTokensForCompletion())
224-
.llmEndpointParams(aiExtractAgentConfig.getLongText().getLlmEndpointParams())
225-
.build();
226-
AiAgentExtract agentIgnoringOverridingEmbeddingsModel =
227-
new AiAgentExtract.Builder()
228-
.longText(longTextConfigWithNoEmbeddings)
229-
.basicText(aiExtractAgentConfig.getBasicText())
230-
.build();
209+
AiAgentExtract aiExtractAgentBasicTextConfig =
210+
new AiAgentExtract.Builder().basicText(aiExtractAgentConfig.getBasicText()).build();
231211
Files uploadedFiles =
232212
client
233213
.getUploads()
@@ -247,7 +227,7 @@ public void testAiExtract() {
247227
new AiExtract.Builder(
248228
"firstName, lastName, location, yearOfBirth, company",
249229
Arrays.asList(new AiItemBase(file.getId())))
250-
.aiAgent(agentIgnoringOverridingEmbeddingsModel)
230+
.aiAgent(aiExtractAgentBasicTextConfig)
251231
.build());
252232
String expectedResponse =
253233
"{\"firstName\": \"John\", \"lastName\": \"Doe\", \"location\": \"San Francisco\", \"yearOfBirth\": \"1990\", \"company\": \"Box\"}";
@@ -268,18 +248,8 @@ public void testAiExtractStructuredWithFields() {
268248
.build());
269249
AiAgentExtractStructured aiExtractStructuredAgentConfig =
270250
aiAgentConfig.getAiAgentExtractStructured();
271-
AiAgentLongTextTool longTextConfigWithNoEmbeddings =
272-
new AiAgentLongTextTool.Builder()
273-
.systemMessage(aiExtractStructuredAgentConfig.getLongText().getSystemMessage())
274-
.promptTemplate(aiExtractStructuredAgentConfig.getLongText().getPromptTemplate())
275-
.model(aiExtractStructuredAgentConfig.getLongText().getModel())
276-
.numTokensForCompletion(
277-
aiExtractStructuredAgentConfig.getLongText().getNumTokensForCompletion())
278-
.llmEndpointParams(aiExtractStructuredAgentConfig.getLongText().getLlmEndpointParams())
279-
.build();
280-
AiAgentExtractStructured agentIgnoringOverridingEmbeddingsModel =
251+
AiAgentExtractStructured aiExtractStructuredAgentBasicTextConfig =
281252
new AiAgentExtractStructured.Builder()
282-
.longText(longTextConfigWithNoEmbeddings)
283253
.basicText(aiExtractStructuredAgentConfig.getBasicText())
284254
.build();
285255
Files uploadedFiles =
@@ -335,7 +305,7 @@ public void testAiExtractStructuredWithFields() {
335305
new AiExtractStructuredFieldsOptionsField("guitar"),
336306
new AiExtractStructuredFieldsOptionsField("books")))
337307
.build()))
338-
.aiAgent(agentIgnoringOverridingEmbeddingsModel)
308+
.aiAgent(aiExtractStructuredAgentBasicTextConfig)
339309
.build());
340310
assert convertToString(response.getAnswer().get("hobby"))
341311
.equals(convertToString(Arrays.asList("guitar")));

0 commit comments

Comments
 (0)