@@ -20,12 +20,12 @@ mod conversions;
20
20
struct OllamaChatStream {
21
21
stream : RefCell < Option < EventSource > > ,
22
22
failure : Option < Error > ,
23
- finished : RefCell < bool > ,
23
+ finished : RefCell < bool > ,
24
24
}
25
25
26
26
impl OllamaChatStream {
27
27
pub fn new ( stream : EventSource ) -> LlmChatStream < Self > {
28
- // Remove EventSource dependency and use direct HTTP response
28
+ println ! ( "OllamaChatStream::new" ) ;
29
29
LlmChatStream :: new ( OllamaChatStream {
30
30
stream : RefCell :: new ( Some ( stream) ) ,
31
31
failure : None ,
@@ -34,6 +34,7 @@ impl OllamaChatStream {
34
34
}
35
35
36
36
pub fn failed ( error : Error ) -> LlmChatStream < Self > {
37
+ println ! ( "OllamaChatStream::failed" ) ;
37
38
LlmChatStream :: new ( OllamaChatStream {
38
39
stream : RefCell :: new ( None ) ,
39
40
failure : Some ( error) ,
@@ -44,25 +45,31 @@ impl OllamaChatStream {
44
45
45
46
impl LlmChatStreamState for OllamaChatStream {
46
47
fn failure ( & self ) -> & Option < Error > {
48
+ println ! ( "OllamaChatStream::failure" ) ;
47
49
& self . failure
48
50
}
49
51
fn is_finished ( & self ) -> bool {
52
+ println ! ( "OllamaChatStream::is_finished" ) ;
50
53
* self . finished . borrow ( )
51
54
}
52
55
53
56
fn set_finished ( & self ) {
57
+ println ! ( "OllamaChatStream::set_finished" ) ;
54
58
* self . finished . borrow_mut ( ) = true ;
55
59
}
56
60
57
61
fn stream ( & self ) -> Ref < Option < EventSource > > {
62
+ println ! ( "OllamaChatStream::stream" ) ;
58
63
self . stream . borrow ( )
59
64
}
60
65
61
66
fn stream_mut ( & self ) -> RefMut < Option < EventSource > > {
67
+ println ! ( "OllamaChatStream::stream_mut" ) ;
62
68
self . stream . borrow_mut ( )
63
69
}
64
70
65
71
fn decode_message ( & self , raw : & str ) -> Result < Option < StreamEvent > , String > {
72
+ println ! ( "OllamaChatStream::decode_message" ) ;
66
73
trace ! ( "Parsing NDJSON line: {raw}" ) ;
67
74
let json: serde_json:: Value = serde_json:: from_str ( raw. trim ( ) )
68
75
. map_err ( |e| format ! ( "JSON parse error: {e}" ) ) ?;
@@ -102,6 +109,7 @@ struct OllamaComponent;
102
109
103
110
impl OllamaComponent {
104
111
fn request ( client : & OllamaApi , request : CompletionsRequest ) -> ChatEvent {
112
+ println ! ( "OllamaComponent::request" ) ;
105
113
match client. send_chat ( request) {
106
114
Ok ( response) => process_response ( response) ,
107
115
Err ( err) => ChatEvent :: Error ( err) ,
@@ -112,6 +120,7 @@ impl OllamaComponent {
112
120
client : & OllamaApi ,
113
121
mut request : CompletionsRequest ,
114
122
) -> LlmChatStream < OllamaChatStream > {
123
+ println ! ( "OllamaComponent::streaming_request" ) ;
115
124
request. stream = Some ( true ) ;
116
125
match client. send_chat_stream ( request) {
117
126
Ok ( stream) => OllamaChatStream :: new ( stream) ,
@@ -124,6 +133,7 @@ impl Guest for OllamaComponent {
124
133
type ChatStream = LlmChatStream < OllamaChatStream > ;
125
134
126
135
fn send ( messages : Vec < Message > , config : Config ) -> ChatEvent {
136
+ println ! ( "OllamaComponent::send" ) ;
127
137
LOGGING_STATE . with_borrow_mut ( |state| state. init ( ) ) ;
128
138
129
139
let client = OllamaApi :: new ( config. model . clone ( ) ) ;
@@ -138,6 +148,7 @@ impl Guest for OllamaComponent {
138
148
tool_results : Vec < ( ToolCall , ToolResult ) > ,
139
149
config : Config ,
140
150
) -> ChatEvent {
151
+ println ! ( "OllamaComponent::continue_" ) ;
141
152
LOGGING_STATE . with_borrow_mut ( |state| state. init ( ) ) ;
142
153
let client = OllamaApi :: new ( config. model . clone ( ) ) ;
143
154
match messages_to_request ( messages, config. clone ( ) ) {
@@ -147,12 +158,14 @@ impl Guest for OllamaComponent {
147
158
}
148
159
149
160
fn stream ( messages : Vec < Message > , config : Config ) -> ChatStream {
150
- ChatStream :: new ( Self :: unwrapped_stream ( messages, config) )
161
+ println ! ( "OllamaComponent::stream" ) ;
162
+ ChatStream :: new ( Self :: unwrapped_stream ( messages, config. clone ( ) ) )
151
163
}
152
164
}
153
165
154
166
impl ExtendedGuest for OllamaComponent {
155
167
fn unwrapped_stream ( messages : Vec < Message > , config : Config ) -> LlmChatStream < OllamaChatStream > {
168
+ println ! ( "OllamaComponent::unwrapped_stream" ) ;
156
169
LOGGING_STATE . with_borrow_mut ( |state| state. init ( ) ) ;
157
170
158
171
let client = OllamaApi :: new ( config. model . clone ( ) ) ;
@@ -163,6 +176,7 @@ impl ExtendedGuest for OllamaComponent {
163
176
}
164
177
165
178
fn retry_prompt ( original_messages : & [ Message ] , partial_result : & [ StreamDelta ] ) -> Vec < Message > {
179
+ println ! ( "OllamaComponent::retry_prompt" ) ;
166
180
let mut extended_messages = Vec :: new ( ) ;
167
181
168
182
extended_messages. push ( Message {
@@ -214,6 +228,11 @@ impl ExtendedGuest for OllamaComponent {
214
228
215
229
extended_messages
216
230
}
231
+
232
+ fn subscribe ( stream : & Self :: ChatStream ) -> Pollable {
233
+ println ! ( "OllamaComponent::subscribe" ) ;
234
+ stream. subscribe ( )
235
+ }
217
236
}
218
237
219
238
type DurableOllamaComponent = DurableLLM < OllamaComponent > ;
0 commit comments