Skip to content

Commit e8435d0

Browse files
feat(boxsdkgen): add confidence scores for structured extract (box/box-openapi#582) (#1320)
1 parent 00305a0 commit e8435d0

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "f9e2519", "specHash": "f8fb08c", "version": "4.3.0" }
1+
{ "engineHash": "f9e2519", "specHash": "ccdb456", "version": "4.3.0" }

src/sdk-gen/schemas/aiExtractStructured.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export interface AiExtractStructured {
7575
* The fields to be extracted from the provided items.
7676
* For your request to work, you must provide either `metadata_template` or `fields`, but not both. */
7777
readonly fields?: readonly AiExtractStructuredFieldsField[];
78+
/**
79+
* A flag to indicate whether confidence scores for every extracted field should be returned. */
80+
readonly includeConfidenceScore?: boolean;
7881
readonly aiAgent?: AiExtractStructuredAgent;
7982
readonly rawData?: SerializedData;
8083
}
@@ -282,6 +285,7 @@ export function serializeAiExtractStructured(
282285
): SerializedData {
283286
return serializeAiExtractStructuredFieldsField(item);
284287
}) as readonly any[]),
288+
['include_confidence_score']: val.includeConfidenceScore,
285289
['ai_agent']:
286290
val.aiAgent == void 0
287291
? val.aiAgent
@@ -332,6 +336,19 @@ export function deserializeAiExtractStructured(
332336
return deserializeAiExtractStructuredFieldsField(itm);
333337
}) as readonly any[])
334338
: [];
339+
if (
340+
!(val.include_confidence_score == void 0) &&
341+
!sdIsBoolean(val.include_confidence_score)
342+
) {
343+
throw new BoxSdkError({
344+
message:
345+
'Expecting boolean for "include_confidence_score" of type "AiExtractStructured"',
346+
});
347+
}
348+
const includeConfidenceScore: undefined | boolean =
349+
val.include_confidence_score == void 0
350+
? void 0
351+
: val.include_confidence_score;
335352
const aiAgent: undefined | AiExtractStructuredAgent =
336353
val.ai_agent == void 0
337354
? void 0
@@ -340,6 +357,7 @@ export function deserializeAiExtractStructured(
340357
items: items,
341358
metadataTemplate: metadataTemplate,
342359
fields: fields,
360+
includeConfidenceScore: includeConfidenceScore,
343361
aiAgent: aiAgent,
344362
} satisfies AiExtractStructured;
345363
}

src/sdk-gen/schemas/aiExtractStructuredResponse.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export interface AiExtractStructuredResponse {
2323
/**
2424
* The reason the response finishes. */
2525
readonly completionReason?: string;
26+
/**
27+
* The confidence score numeric values for each extracted field as a JSON dictionary. This can be empty if no field could be extracted. */
28+
readonly confidenceScore?: {
29+
readonly [key: string]: any;
30+
};
2631
readonly aiAgentInfo?: AiAgentInfo;
2732
readonly rawData?: SerializedData;
2833
}
@@ -33,6 +38,19 @@ export function serializeAiExtractStructuredResponse(
3338
['answer']: serializeAiExtractResponse(val.answer),
3439
['created_at']: serializeDateTime(val.createdAt),
3540
['completion_reason']: val.completionReason,
41+
['confidence_score']:
42+
val.confidenceScore == void 0
43+
? val.confidenceScore
44+
: (Object.fromEntries(
45+
Object.entries(val.confidenceScore).map(([k, v]: [string, any]) => [
46+
k,
47+
(function (v: any): any {
48+
return v;
49+
})(v),
50+
])
51+
) as {
52+
readonly [key: string]: any;
53+
}),
3654
['ai_agent_info']:
3755
val.aiAgentInfo == void 0
3856
? val.aiAgentInfo
@@ -78,6 +96,33 @@ export function deserializeAiExtractStructuredResponse(
7896
}
7997
const completionReason: undefined | string =
8098
val.completion_reason == void 0 ? void 0 : val.completion_reason;
99+
if (!(val.confidence_score == void 0) && !sdIsMap(val.confidence_score)) {
100+
throw new BoxSdkError({
101+
message:
102+
'Expecting object for "confidence_score" of type "AiExtractStructuredResponse"',
103+
});
104+
}
105+
const confidenceScore:
106+
| undefined
107+
| {
108+
readonly [key: string]: any;
109+
} =
110+
val.confidence_score == void 0
111+
? void 0
112+
: sdIsMap(val.confidence_score)
113+
? (Object.fromEntries(
114+
Object.entries(val.confidence_score).map(
115+
([k, v]: [string, any]) => [
116+
k,
117+
(function (v: any): any {
118+
return v;
119+
})(v),
120+
]
121+
)
122+
) as {
123+
readonly [key: string]: any;
124+
})
125+
: {};
81126
const aiAgentInfo: undefined | AiAgentInfo =
82127
val.ai_agent_info == void 0
83128
? void 0
@@ -86,6 +131,7 @@ export function deserializeAiExtractStructuredResponse(
86131
answer: answer,
87132
createdAt: createdAt,
88133
completionReason: completionReason,
134+
confidenceScore: confidenceScore,
89135
aiAgentInfo: aiAgentInfo,
90136
} satisfies AiExtractStructuredResponse;
91137
}

0 commit comments

Comments
 (0)