jonathanjordan21 commited on
Commit
293471e
·
verified ·
1 Parent(s): 6fe3f86

Update networks/huggingface_streamer.py

Browse files
Files changed (1) hide show
  1. networks/huggingface_streamer.py +31 -0
networks/huggingface_streamer.py CHANGED
@@ -176,3 +176,34 @@ class HuggingfaceStreamer:
176
 
177
  if not is_finished:
178
  yield self.message_outputer.output(content="", content_type="Finished")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  if not is_finished:
178
  yield self.message_outputer.output(content="", content_type="Finished")
179
+
180
+
181
+ def ollama_return_generator(self, stream_response):
182
+ is_finished = False
183
+ line_count = 0
184
+ for line in stream_response.iter_lines():
185
+ if line:
186
+ line_count += 1
187
+ else:
188
+ continue
189
+
190
+ content = self.parse_line(line)
191
+
192
+ if content.strip().endswith(self.stop_sequences):
193
+ content_type = "Finished"
194
+ logger.success("\n[Finished]")
195
+ is_finished = True
196
+ else:
197
+ content_type = "Completions"
198
+ if line_count == 1:
199
+ content = content.lstrip()
200
+
201
+ logger.back(content, end="")
202
+
203
+ output = self.message_outputer.output(
204
+ content=content, content_type=content_type
205
+ )
206
+ yield "{" + output + "}"
207
+
208
+ if not is_finished:
209
+ yield "{" + self.message_outputer.output(content="", content_type="Finished") + "}"