Skip to content

Commit 98285ef

Browse files
feat: add confidence scores for structured extract (box/box-openapi#582) (#1379)
1 parent a11c3dc commit 98285ef

3 files changed

Lines changed: 19 additions & 3 deletions

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": "10.3.0" }
1+
{ "engineHash": "f9e2519", "specHash": "ccdb456", "version": "10.3.0" }

BoxSdkGen/Sources/Schemas/AiExtractStructured/AiExtractStructured.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class AiExtractStructured: Codable, RawJSONReadable {
66
case items
77
case metadataTemplate = "metadata_template"
88
case fields
9+
case includeConfidenceScore = "include_confidence_score"
910
case aiAgent = "ai_agent"
1011
}
1112

@@ -29,6 +30,9 @@ public class AiExtractStructured: Codable, RawJSONReadable {
2930
/// For your request to work, you must provide either `metadata_template` or `fields`, but not both.
3031
public let fields: [AiExtractStructuredFieldsField]?
3132

33+
/// A flag to indicate whether confidence scores for every extracted field should be returned.
34+
public let includeConfidenceScore: Bool?
35+
3236
public let aiAgent: AiExtractStructuredAgent?
3337

3438
/// Initializer for a AiExtractStructured.
@@ -39,11 +43,13 @@ public class AiExtractStructured: Codable, RawJSONReadable {
3943
/// For your request to work, you must provide either `metadata_template` or `fields`, but not both.
4044
/// - fields: The fields to be extracted from the provided items.
4145
/// For your request to work, you must provide either `metadata_template` or `fields`, but not both.
46+
/// - includeConfidenceScore: A flag to indicate whether confidence scores for every extracted field should be returned.
4247
/// - aiAgent:
43-
public init(items: [AiItemBase], metadataTemplate: AiExtractStructuredMetadataTemplateField? = nil, fields: [AiExtractStructuredFieldsField]? = nil, aiAgent: AiExtractStructuredAgent? = nil) {
48+
public init(items: [AiItemBase], metadataTemplate: AiExtractStructuredMetadataTemplateField? = nil, fields: [AiExtractStructuredFieldsField]? = nil, includeConfidenceScore: Bool? = nil, aiAgent: AiExtractStructuredAgent? = nil) {
4449
self.items = items
4550
self.metadataTemplate = metadataTemplate
4651
self.fields = fields
52+
self.includeConfidenceScore = includeConfidenceScore
4753
self.aiAgent = aiAgent
4854
}
4955

@@ -52,6 +58,7 @@ public class AiExtractStructured: Codable, RawJSONReadable {
5258
items = try container.decode([AiItemBase].self, forKey: .items)
5359
metadataTemplate = try container.decodeIfPresent(AiExtractStructuredMetadataTemplateField.self, forKey: .metadataTemplate)
5460
fields = try container.decodeIfPresent([AiExtractStructuredFieldsField].self, forKey: .fields)
61+
includeConfidenceScore = try container.decodeIfPresent(Bool.self, forKey: .includeConfidenceScore)
5562
aiAgent = try container.decodeIfPresent(AiExtractStructuredAgent.self, forKey: .aiAgent)
5663
}
5764

@@ -60,6 +67,7 @@ public class AiExtractStructured: Codable, RawJSONReadable {
6067
try container.encode(items, forKey: .items)
6168
try container.encodeIfPresent(metadataTemplate, forKey: .metadataTemplate)
6269
try container.encodeIfPresent(fields, forKey: .fields)
70+
try container.encodeIfPresent(includeConfidenceScore, forKey: .includeConfidenceScore)
6371
try container.encodeIfPresent(aiAgent, forKey: .aiAgent)
6472
}
6573

BoxSdkGen/Sources/Schemas/AiExtractStructuredResponse/AiExtractStructuredResponse.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class AiExtractStructuredResponse: Codable, RawJSONReadable {
66
case answer
77
case createdAt = "created_at"
88
case completionReason = "completion_reason"
9+
case confidenceScore = "confidence_score"
910
case aiAgentInfo = "ai_agent_info"
1011
}
1112

@@ -26,6 +27,9 @@ public class AiExtractStructuredResponse: Codable, RawJSONReadable {
2627
/// The reason the response finishes.
2728
public let completionReason: String?
2829

30+
/// The confidence score numeric values for each extracted field as a JSON dictionary. This can be empty if no field could be extracted.
31+
public let confidenceScore: [String: AnyCodable]?
32+
2933
public let aiAgentInfo: AiAgentInfo?
3034

3135
/// Initializer for a AiExtractStructuredResponse.
@@ -34,11 +38,13 @@ public class AiExtractStructuredResponse: Codable, RawJSONReadable {
3438
/// - answer:
3539
/// - createdAt: The ISO date formatted timestamp of when the answer to the prompt was created.
3640
/// - completionReason: The reason the response finishes.
41+
/// - confidenceScore: The confidence score numeric values for each extracted field as a JSON dictionary. This can be empty if no field could be extracted.
3742
/// - aiAgentInfo:
38-
public init(answer: AiExtractResponse, createdAt: Date, completionReason: String? = nil, aiAgentInfo: AiAgentInfo? = nil) {
43+
public init(answer: AiExtractResponse, createdAt: Date, completionReason: String? = nil, confidenceScore: [String: AnyCodable]? = nil, aiAgentInfo: AiAgentInfo? = nil) {
3944
self.answer = answer
4045
self.createdAt = createdAt
4146
self.completionReason = completionReason
47+
self.confidenceScore = confidenceScore
4248
self.aiAgentInfo = aiAgentInfo
4349
}
4450

@@ -47,6 +53,7 @@ public class AiExtractStructuredResponse: Codable, RawJSONReadable {
4753
answer = try container.decode(AiExtractResponse.self, forKey: .answer)
4854
createdAt = try container.decodeDateTime(forKey: .createdAt)
4955
completionReason = try container.decodeIfPresent(String.self, forKey: .completionReason)
56+
confidenceScore = try container.decodeIfPresent([String: AnyCodable].self, forKey: .confidenceScore)
5057
aiAgentInfo = try container.decodeIfPresent(AiAgentInfo.self, forKey: .aiAgentInfo)
5158
}
5259

@@ -55,6 +62,7 @@ public class AiExtractStructuredResponse: Codable, RawJSONReadable {
5562
try container.encode(answer, forKey: .answer)
5663
try container.encodeDateTime(field: createdAt, forKey: .createdAt)
5764
try container.encodeIfPresent(completionReason, forKey: .completionReason)
65+
try container.encodeIfPresent(confidenceScore, forKey: .confidenceScore)
5866
try container.encodeIfPresent(aiAgentInfo, forKey: .aiAgentInfo)
5967
}
6068

0 commit comments

Comments
 (0)