Skip to content

Commit

Permalink
feat: update /ai/extract_structured response schema (box/box-openapi#505
Browse files Browse the repository at this point in the history
)
  • Loading branch information
box-sdk-build committed Jan 29, 2025
1 parent c2e3a60 commit d6ad69f
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "cf82faa", "specHash": "3dc3f1e", "version": "0.3.0" }
{ "engineHash": "cf82faa", "specHash": "1fdcbef", "version": "0.3.0" }
2 changes: 1 addition & 1 deletion docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ client.getAi().createAiExtractStructured(new AiExtractStructured.AiExtractStruct

### Returns

This function returns a value of type `AiExtractResponse`.
This function returns a value of type `AiExtractStructuredResponse`.

A successful response including the answer from the LLM.

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/box/sdkgen/managers/ai/AiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.box.sdkgen.schemas.aiagentaskoraiagentextractoraiagentextractstructuredoraiagenttextgen.AiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen;
import com.box.sdkgen.schemas.aiask.AiAsk;
import com.box.sdkgen.schemas.aiextract.AiExtract;
import com.box.sdkgen.schemas.aiextractresponse.AiExtractResponse;
import com.box.sdkgen.schemas.aiextractstructured.AiExtractStructured;
import com.box.sdkgen.schemas.aiextractstructuredresponse.AiExtractStructuredResponse;
import com.box.sdkgen.schemas.airesponse.AiResponse;
import com.box.sdkgen.schemas.airesponsefull.AiResponseFull;
import com.box.sdkgen.schemas.aitextgen.AiTextGen;
Expand Down Expand Up @@ -145,11 +145,11 @@ public AiResponse createAiExtract(AiExtract requestBody, CreateAiExtractHeaders
return JsonManager.deserialize(response.getData(), AiResponse.class);
}

public AiExtractResponse createAiExtractStructured(AiExtractStructured requestBody) {
public AiExtractStructuredResponse createAiExtractStructured(AiExtractStructured requestBody) {
return createAiExtractStructured(requestBody, new CreateAiExtractStructuredHeaders());
}

public AiExtractResponse createAiExtractStructured(
public AiExtractStructuredResponse createAiExtractStructured(
AiExtractStructured requestBody, CreateAiExtractStructuredHeaders headers) {
Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
FetchResponse response =
Expand All @@ -169,7 +169,7 @@ public AiExtractResponse createAiExtractStructured(
.auth(this.auth)
.networkSession(this.networkSession)
.build());
return JsonManager.deserialize(response.getData(), AiExtractResponse.class);
return JsonManager.deserialize(response.getData(), AiExtractStructuredResponse.class);
}

public Authentication getAuth() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.box.sdkgen.schemas.aiextractstructuredresponse;

import com.box.sdkgen.internal.SerializableObject;
import com.box.sdkgen.schemas.aiagentinfo.AiAgentInfo;
import com.box.sdkgen.schemas.aiextractresponse.AiExtractResponse;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;

public class AiExtractStructuredResponse extends SerializableObject {

protected final AiExtractResponse answer;

@JsonProperty("created_at")
protected final String createdAt;

@JsonProperty("completion_reason")
protected String completionReason;

@JsonProperty("ai_agent_info")
protected AiAgentInfo aiAgentInfo;

public AiExtractStructuredResponse(
@JsonProperty("answer") AiExtractResponse answer,
@JsonProperty("created_at") String createdAt) {
super();
this.answer = answer;
this.createdAt = createdAt;
}

protected AiExtractStructuredResponse(AiExtractStructuredResponseBuilder builder) {
super();
this.answer = builder.answer;
this.createdAt = builder.createdAt;
this.completionReason = builder.completionReason;
this.aiAgentInfo = builder.aiAgentInfo;
}

public AiExtractResponse getAnswer() {
return answer;
}

public String getCreatedAt() {
return createdAt;
}

public String getCompletionReason() {
return completionReason;
}

public AiAgentInfo getAiAgentInfo() {
return aiAgentInfo;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AiExtractStructuredResponse casted = (AiExtractStructuredResponse) o;
return Objects.equals(answer, casted.answer)
&& Objects.equals(createdAt, casted.createdAt)
&& Objects.equals(completionReason, casted.completionReason)
&& Objects.equals(aiAgentInfo, casted.aiAgentInfo);
}

@Override
public int hashCode() {
return Objects.hash(answer, createdAt, completionReason, aiAgentInfo);
}

@Override
public String toString() {
return "AiExtractStructuredResponse{"
+ "answer='"
+ answer
+ '\''
+ ", "
+ "createdAt='"
+ createdAt
+ '\''
+ ", "
+ "completionReason='"
+ completionReason
+ '\''
+ ", "
+ "aiAgentInfo='"
+ aiAgentInfo
+ '\''
+ "}";
}

public static class AiExtractStructuredResponseBuilder {

protected final AiExtractResponse answer;

protected final String createdAt;

protected String completionReason;

protected AiAgentInfo aiAgentInfo;

public AiExtractStructuredResponseBuilder(AiExtractResponse answer, String createdAt) {
this.answer = answer;
this.createdAt = createdAt;
}

public AiExtractStructuredResponseBuilder completionReason(String completionReason) {
this.completionReason = completionReason;
return this;
}

public AiExtractStructuredResponseBuilder aiAgentInfo(AiAgentInfo aiAgentInfo) {
this.aiAgentInfo = aiAgentInfo;
return this;
}

public AiExtractStructuredResponse build() {
return new AiExtractStructuredResponse(this);
}
}
}
6 changes: 3 additions & 3 deletions src/test/java/com/box/sdkgen/test/ai/AiITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import com.box.sdkgen.schemas.aiask.AiAskModeField;
import com.box.sdkgen.schemas.aidialoguehistory.AiDialogueHistory;
import com.box.sdkgen.schemas.aiextract.AiExtract;
import com.box.sdkgen.schemas.aiextractresponse.AiExtractResponse;
import com.box.sdkgen.schemas.aiextractstructured.AiExtractStructured;
import com.box.sdkgen.schemas.aiextractstructured.AiExtractStructuredFieldsField;
import com.box.sdkgen.schemas.aiextractstructured.AiExtractStructuredFieldsOptionsField;
import com.box.sdkgen.schemas.aiextractstructured.AiExtractStructuredMetadataTemplateField;
import com.box.sdkgen.schemas.aiextractstructuredresponse.AiExtractStructuredResponse;
import com.box.sdkgen.schemas.aiitembase.AiItemBase;
import com.box.sdkgen.schemas.aiitembase.AiItemBaseTypeField;
import com.box.sdkgen.schemas.airesponse.AiResponse;
Expand Down Expand Up @@ -191,7 +191,7 @@ public void testAiExtractStructuredWithFields() {
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar.")));
FileFull file = uploadedFiles.getEntries().get(0);
delayInSeconds(5);
AiExtractResponse response =
AiExtractStructuredResponse response =
client
.getAi()
.createAiExtractStructured(
Expand Down Expand Up @@ -314,7 +314,7 @@ public void testAiExtractStructuredWithMetadataTemplate() {
"books")))
.build()))
.build());
AiExtractResponse response =
AiExtractStructuredResponse response =
client
.getAi()
.createAiExtractStructured(
Expand Down

0 comments on commit d6ad69f

Please sign in to comment.