Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/box/sdk/BoxAIDialogueEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public void setCreatedAt(Date createdAt) {
*/
public JsonObject getJSONObject() {
JsonObject itemJSON = new JsonObject()
.add("id", this.prompt)
.add("type", this.answer);
.add("prompt", this.prompt)
.add("answer", this.answer);

if (this.createdAt != null) {
itemJSON.add("content", this.createdAt.toString());
itemJSON.add("created_at", this.createdAt.toString());
}

return itemJSON;
Expand Down
26 changes: 21 additions & 5 deletions src/test/java/com/box/sdk/BoxAITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ public void testSendAIRequestSuccess() {
public void testSendAITexGenRequestWithNoDialogueHistorySuccess() {
final String fileId = "12345";
final String prompt = "What is the name of the file?";
String expectedRequestBody = String.format(
"{\"prompt\": \"%s\", \"items\": [{\"id\": \"%s\", \"type\": \"file\"}]}", prompt, fileId);

String result = TestUtils.getFixture("BoxAI/SendAITextGen200");
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo("/2.0/ai/text_gen"))
.withRequestBody(WireMock.equalToJson(expectedRequestBody))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(result)));
Expand All @@ -91,19 +94,32 @@ public void testSendAITexGenRequestWithDialogueHistorySuccess() throws ParseExce
final String fileId = "12345";
final String prompt = "What is the name of the file?";

Date date1 = BoxDateFormat.parse("2013-05-16T15:27:57-07:00");
Date date2 = BoxDateFormat.parse("2013-05-16T15:26:57-07:00");

List<BoxAIDialogueEntry> dialogueHistory = new ArrayList<>();
dialogueHistory.add(
new BoxAIDialogueEntry("What is the name of the file?", "Test file", date1)
new BoxAIDialogueEntry("What is the name of the file?", "Test file")
);
dialogueHistory.add(
new BoxAIDialogueEntry("What is the size of the file?", "10kb", date2)
new BoxAIDialogueEntry("What is the size of the file?", "10kb")
);

String expectedRequestBody = String.format(
"{\n"
+ " \"prompt\": \"%s\",\n"
+ " \"items\": [\n"
+ " {\"id\": \"%s\", \"type\": \"file\"}\n"
+ " ],\n"
+ " \"dialogue_history\": [\n"
+ " {\"prompt\": \"What is the name of the file?\", \"answer\": \"Test file\"},\n"
+ " {\"prompt\": \"What is the size of the file?\", \"answer\": \"10kb\"}\n"
+ " ]\n"
+ "}",
prompt, fileId
);


String result = TestUtils.getFixture("BoxAI/SendAITextGen200");
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo("/2.0/ai/text_gen"))
.withRequestBody(WireMock.equalToJson(expectedRequestBody))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(result)));
Expand Down
Loading