Skip to content

Commit 388ce0a

Browse files
committed
fix: Fix AI dialogue history
1 parent 9119adc commit 388ce0a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/main/java/com/box/sdk/BoxAIDialogueEntry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ public void setCreatedAt(Date createdAt) {
9494
*/
9595
public JsonObject getJSONObject() {
9696
JsonObject itemJSON = new JsonObject()
97-
.add("id", this.prompt)
98-
.add("type", this.answer);
97+
.add("prompt", this.prompt)
98+
.add("answer", this.answer);
9999

100100
if (this.createdAt != null) {
101-
itemJSON.add("content", this.createdAt.toString());
101+
itemJSON.add("created_at", this.createdAt.toString());
102102
}
103103

104104
return itemJSON;

src/test/java/com/box/sdk/BoxAITest.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ public void testSendAIRequestSuccess() {
6666
public void testSendAITexGenRequestWithNoDialogueHistorySuccess() {
6767
final String fileId = "12345";
6868
final String prompt = "What is the name of the file?";
69+
String expectedRequestBody = String.format(
70+
"{\"prompt\": \"%s\", \"items\": [{\"id\": \"%s\", \"type\": \"file\"}]}", prompt, fileId);
6971

7072
String result = TestUtils.getFixture("BoxAI/SendAITextGen200");
7173
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo("/2.0/ai/text_gen"))
74+
.withRequestBody(WireMock.equalToJson(expectedRequestBody))
7275
.willReturn(WireMock.aResponse()
7376
.withHeader("Content-Type", APPLICATION_JSON)
7477
.withBody(result)));
@@ -92,18 +95,34 @@ public void testSendAITexGenRequestWithDialogueHistorySuccess() throws ParseExce
9295
final String prompt = "What is the name of the file?";
9396

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

9799
List<BoxAIDialogueEntry> dialogueHistory = new ArrayList<>();
98100
dialogueHistory.add(
99101
new BoxAIDialogueEntry("What is the name of the file?", "Test file", date1)
100102
);
101103
dialogueHistory.add(
102-
new BoxAIDialogueEntry("What is the size of the file?", "10kb", date2)
104+
new BoxAIDialogueEntry("What is the size of the file?", "10kb")
105+
);
106+
107+
String expectedRequestBody = String.format(
108+
"{\n"
109+
+ " \"prompt\": \"%s\",\n"
110+
+ " \"items\": [\n"
111+
+ " {\"id\": \"%s\", \"type\": \"file\"}\n"
112+
+ " ],\n"
113+
+ " \"dialogue_history\": [\n"
114+
+ " {\"prompt\": \"What is the name of the file?\", \"answer\": \"Test file\", "
115+
+ " \"created_at\": \"Fri May 17 00:27:57 CEST 2013\"},\n"
116+
+ " {\"prompt\": \"What is the size of the file?\", \"answer\": \"10kb\"}\n"
117+
+ " ]\n"
118+
+ "}",
119+
prompt, fileId
103120
);
104121

122+
105123
String result = TestUtils.getFixture("BoxAI/SendAITextGen200");
106124
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo("/2.0/ai/text_gen"))
125+
.withRequestBody(WireMock.equalToJson(expectedRequestBody))
107126
.willReturn(WireMock.aResponse()
108127
.withHeader("Content-Type", APPLICATION_JSON)
109128
.withBody(result)));

0 commit comments

Comments
 (0)