Skip to content

Commit 5d70745

Browse files
committed
Add convenience outputText property in Responses response
1 parent d6f755f commit 5d70745

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Sources/OpenAI/Responses/ResponsesResponse.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ public extension Responses {
8686
public let truncation: TruncationStrategy?
8787
public let usage: Usage
8888

89+
/// Convenience property that contains the aggregated text output from all `output_text`
90+
/// items in the `output` array, if any are present.
91+
public var outputText: String? {
92+
output.reduce(into: "") { partialResult, output in
93+
if output.type == "message" {
94+
partialResult += output.content.reduce(into: "") { contentPartialResult, content in
95+
if content.type == "output_text" {
96+
contentPartialResult += content.text
97+
}
98+
}
99+
}
100+
}
101+
}
102+
89103
public struct IncompleteDetails: Decodable, Sendable {
90104
public let reason: String
91105
}

0 commit comments

Comments
 (0)