@@ -11,6 +11,7 @@ import Combine
1111actor OllamaChatService {
1212 private( set) var messages : [ APIChatMessage ] = [ ]
1313 private let currentResponseSubject : PassthroughSubject < String , Never > = . init( )
14+ private let answeringSubject : PassthroughSubject < Bool , Never > = . init( )
1415
1516 func sendMessage( model: String , userInput: String , images: [ NSImage ] ? , showThink: Bool ,
1617 predict: Double ? = nil , temperature: Double ? = nil ) async throws -> AsyncStream < String > {
@@ -55,6 +56,9 @@ actor OllamaChatService {
5556 let stream = AsyncStream { continuation in
5657 Task {
5758 do {
59+ //start thinking
60+ self . sendToAnsweringSubject ( true )
61+
5862 for try await line in bytesStream. lines {
5963 guard let data = line. data ( using: . utf8) ,
6064 let json = try ? JSONSerialization . jsonObject ( with: data) as? [ String : Any ] ,
@@ -76,6 +80,9 @@ actor OllamaChatService {
7680 let finalMessage = APIChatMessage ( role: " assistant " , content: assistantContent, images: nil , options: nil , assistantThink: assistantThink)
7781 messages. append ( finalMessage)
7882
83+ //end thinking
84+ self . sendToAnsweringSubject ( false )
85+
7986 #if DEBUG
8087 debugPrint ( assistantThink)
8188 debugPrint ( " Request options: \( options) " )
@@ -95,10 +102,18 @@ actor OllamaChatService {
95102 currentResponseSubject. send ( value)
96103 }
97104
105+ private func sendToAnsweringSubject( _ value: Bool ) {
106+ answeringSubject. send ( value)
107+ }
108+
98109 public func currentResponsePublisher( ) -> AnyPublisher < String , Never > {
99110 return currentResponseSubject. eraseToAnyPublisher ( )
100111 }
101112
113+ public func answeringPublisher( ) -> AnyPublisher < Bool , Never > {
114+ return answeringSubject. eraseToAnyPublisher ( )
115+ }
116+
102117 ///Convert NSImage array to Base64 String array
103118 private func nsImageArrayToBase64Array( _ images: [ NSImage ] ? ) async -> [ String ] ? {
104119 var base64Strings : [ String ] = [ ]
0 commit comments