We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8b5445e commit 226bc25Copy full SHA for 226bc25
1 file changed
Tool/Sources/ChatBasic/ChatAgent.swift
@@ -42,3 +42,27 @@ public protocol ChatAgent {
42
func send(_ request: Request) async -> AsyncThrowingStream<Response, any Error>
43
}
44
45
+public extension AsyncThrowingStream<ChatAgentResponse, any Error> {
46
+ func asTexts() async throws -> [String] {
47
+ var result = [String]()
48
+ var text = ""
49
+ for try await response in self {
50
+ switch response {
51
+ case let .content(.text(content)):
52
+ text += content
53
+ case .startNewMessage:
54
+ if !text.isEmpty {
55
+ result.append(text)
56
+ text = ""
57
+ }
58
+ default:
59
+ break
60
61
62
63
64
65
+ return result
66
67
+}
68
+
0 commit comments