@@ -19,14 +19,13 @@ extension GenKit.Message.Content {
1919 init ? ( _ content: Llama . ChatResponse . CompletionMessage . Content ) {
2020 if let text = content. text {
2121 self = . text( text)
22- }
23- if let reasoning = content. reasoning {
22+ } else if let reasoning = content. reasoning {
2423 self = . text( reasoning)
25- }
26- if let answer = content. answer {
24+ } else if let answer = content. answer {
2725 self = . text( answer)
26+ } else {
27+ return nil
2828 }
29- return nil
3029 }
3130}
3231
@@ -62,24 +61,25 @@ extension GenKit.Message.FinishReason {
6261
6362extension GenKit . Message {
6463 mutating func patch( with resp: Llama . ChatStreamResponse ) {
64+ var contents = self . contents ?? [ ]
6565
66- // Get the last item in the contents array so it can be patched
67- if var contents = self . contents {
68- if resp. event. event_type == " text " {
69- if case . text( let text) = contents. last, let delta = resp. event. delta. text {
70- if let patched = GenKit . patch ( string: text, with: delta) {
71- contents [ contents. count- 1 ] = . text( patched)
72- self . contents = contents
73- }
66+ if resp. event. event_type == " progress " {
67+ if case . text( let text) = contents. last, let delta = resp. event. delta. text {
68+ if let patched = GenKit . patch ( string: text, with: delta) {
69+ contents [ contents. count- 1 ] = . text( patched)
7470 }
71+ } else if let delta = resp. event. delta. text {
72+ contents. append ( . text( delta) )
7573 }
76- if resp. event. event_type == " reasoning " {
77- print ( " not implemented " )
78- }
79- if resp. event. event_type == " function " {
80- print ( " not implemented " )
81- }
8274 }
75+ if resp. event. event_type == " reasoning " {
76+ print ( " not implemented " )
77+ }
78+ if resp. event. event_type == " function " {
79+ print ( " not implemented " )
80+ }
81+
82+ self . contents = ( contents. isEmpty) ? nil : contents
8383
8484 // Patch remaining properties
8585 self . toolCalls = [ ]
0 commit comments