Skip to content

Commit 3f5e195

Browse files
Merge pull request #130 from jamesrochabrun/jroch-tests-textoutput
Support for text output + tests
2 parents 0a2a810 + 4f98837 commit 3f5e195

File tree

3 files changed

+1064
-8
lines changed

3 files changed

+1064
-8
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,10 @@ public struct ResponseModel: Decodable {
14321432

14331433
/// A unique identifier representing your end-user.
14341434
public let user: String?
1435+
1436+
/// Convenience property that aggregates all text output from output_text items in the output array.
1437+
/// Similar to the outputText property in Python and JavaScript SDKs.
1438+
public var outputText: String?
14351439
}
14361440
```
14371441

Sources/OpenAI/Public/ResponseModels/Response/ResponseModel.swift

+20
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ public struct ResponseModel: Decodable {
9393
/// A unique identifier representing your end-user.
9494
public let user: String?
9595

96+
/// Convenience property that aggregates all text output from output_text items in the output array.
97+
/// Similar to the outputText property in Python and JavaScript SDKs.
98+
public var outputText: String? {
99+
let outputTextItems = output.compactMap { outputItem -> String? in
100+
switch outputItem {
101+
case .message(let message):
102+
return message.content.compactMap { contentItem -> String? in
103+
switch contentItem {
104+
case .outputText(let outputText):
105+
return outputText.text
106+
}
107+
}.joined()
108+
default:
109+
return nil
110+
}
111+
}
112+
113+
return outputTextItems.isEmpty ? nil : outputTextItems.joined()
114+
}
115+
96116
public struct ErrorObject: Decodable {
97117

98118
/// The error code for the response.

0 commit comments

Comments
 (0)