Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsocha2 committed Apr 30, 2024
1 parent c3fcd9b commit 39e3549
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
10 changes: 5 additions & 5 deletions doc/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ an answer based on the provided prompt and items.
Send AI request
--------------------------

To send an AI request to get an answer call static
To send an AI request, call static
[`sendAIRequest(String prompt, List<BoxAIItem> items, Mode mode)`][send-ai-request] method.
In the request you have to provide a prompt, a list of items that your prompt refers to and a mode of the request.
There are two modes available: `SINGLE_ITEM_QA` and `MULTI_ITEM_QA`, which specifies if this request refers to
for a single or multiple items.

<!-- sample get_enterprises_id_device_pinners -->
<!-- sample post_ai_ask -->
```java
BoxAIResponse response = BoxAI.sendAIRequest(
api,
Expand All @@ -39,12 +39,12 @@ It usually takes a few seconds for the file to be indexed and available for the
Send AI text generation request
--------------

To send an AI request to get an answer specifically focused on the creation of new text call static
To send an AI request specifically focused on the creation of new text, call static
[`sendAITextGenRequest(String prompt, List<BoxAIItem> items, List<BoxAIDialogueEntry> dialogueHistory)`][send-ai-text-gen-request] method.
In the request you have to provide a prompt, a list of items that your prompt refers to and a dialogue history,
In the request you have to provide a prompt, a list of items that your prompt refers to and optionally a dialogue history,
which provides additional context to the LLM in generating the response.

<!-- sample get_device_pinners_id -->
<!-- sample post_ai_text_gen -->
```java
List<BoxAIDialogueEntry> dialogueHistory = new ArrayList<>();
dialogueHistory.add(
Expand Down
45 changes: 25 additions & 20 deletions src/intTest/java/com/box/sdk/BoxAIIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,35 @@ public void askAIMultipleItems() throws InterruptedException {
BoxAPIConnection api = jwtApiForServiceAccount();
String fileName1 = "[askAIMultipleItems] Test File.txt";
BoxFile uploadedFile1 = uploadFileToUniqueFolder(api, fileName1, "Test file");

try {
String fileName2 = "[askAIMultipleItems] Weather forecast.txt";
BoxFile uploadedFile2 = uploadFileToUniqueFolder(api, fileName2, "Test file");

BoxFile.Info uploadedFileInfo1 = uploadedFile1.getInfo();
BoxFile.Info uploadedFileInfo2 = uploadedFile2.getInfo();

List<BoxAIItem> items = new ArrayList<>();
items.add(new BoxAIItem(uploadedFileInfo1.getID(), BoxAIItem.Type.FILE));
items.add(new BoxAIItem(uploadedFileInfo2.getID(), BoxAIItem.Type.FILE));

// When a file has been just uploaded, AI service may not be ready to return text response
// and 412 is returned
retry(() -> {
BoxAIResponse response = BoxAI.sendAIRequest(
api,
"What is the content of these files?",
items,
BoxAI.Mode.MULTIPLE_ITEM_QA
);
assertThat(response.getAnswer(), containsString("Test file"));
assert response.getCreatedAt().before(new Date(System.currentTimeMillis()));
assertThat(response.getCompletionReason(), equalTo("done"));
}, 2, 2000);
try {
BoxFile.Info uploadedFileInfo1 = uploadedFile1.getInfo();
BoxFile.Info uploadedFileInfo2 = uploadedFile2.getInfo();

List<BoxAIItem> items = new ArrayList<>();
items.add(new BoxAIItem(uploadedFileInfo1.getID(), BoxAIItem.Type.FILE));
items.add(new BoxAIItem(uploadedFileInfo2.getID(), BoxAIItem.Type.FILE));

// When a file has been just uploaded, AI service may not be ready to return text response
// and 412 is returned
retry(() -> {
BoxAIResponse response = BoxAI.sendAIRequest(
api,
"What is the content of these files?",
items,
BoxAI.Mode.MULTIPLE_ITEM_QA
);
assertThat(response.getAnswer(), containsString("Test file"));
assert response.getCreatedAt().before(new Date(System.currentTimeMillis()));
assertThat(response.getCompletionReason(), equalTo("done"));
}, 2, 2000);
} finally {
deleteFile(uploadedFile2);
}

} finally {
deleteFile(uploadedFile1);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/box/sdk/BoxAITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void setUpBaseUrl() {
}

@Test
public void testsendAIRequestSuccess() {
public void testSendAIRequestSuccess() {
final String fileId = "12345";
final String prompt = "What is the name of the file?";

Expand All @@ -59,7 +59,7 @@ public void testsendAIRequestSuccess() {
}

@Test
public void testsendAITexGenRequestWithNoDialogueHistorySuccess() {
public void testSendAITexGenRequestWithNoDialogueHistorySuccess() {
final String fileId = "12345";
final String prompt = "What is the name of the file?";

Expand All @@ -83,7 +83,7 @@ public void testsendAITexGenRequestWithNoDialogueHistorySuccess() {
}

@Test
public void testsendAITexGenRequestWithDialogueHistorySuccess() throws ParseException {
public void testSendAITexGenRequestWithDialogueHistorySuccess() throws ParseException {
final String fileId = "12345";
final String prompt = "What is the name of the file?";

Expand Down

0 comments on commit 39e3549

Please sign in to comment.