Spaces:
Runtime error
Runtime error
:zap: [Enhance] Remove leading whitespaces of first response
Browse files
networks/message_streamer.py
CHANGED
@@ -130,13 +130,17 @@ class MessageStreamer:
|
|
130 |
if self.model in self.STOP_SEQUENCES_MAP.keys():
|
131 |
final_content = final_content.replace(self.stop_sequences, "")
|
132 |
|
|
|
133 |
final_output["choices"][0]["message"]["content"] = final_content
|
134 |
return final_output
|
135 |
|
136 |
def chat_return_generator(self, stream_response):
|
137 |
is_finished = False
|
|
|
138 |
for line in stream_response.iter_lines():
|
139 |
-
if
|
|
|
|
|
140 |
continue
|
141 |
|
142 |
content = self.parse_line(line)
|
@@ -147,6 +151,8 @@ class MessageStreamer:
|
|
147 |
is_finished = True
|
148 |
else:
|
149 |
content_type = "Completions"
|
|
|
|
|
150 |
logger.back(content, end="")
|
151 |
|
152 |
output = self.message_outputer.output(
|
|
|
130 |
if self.model in self.STOP_SEQUENCES_MAP.keys():
|
131 |
final_content = final_content.replace(self.stop_sequences, "")
|
132 |
|
133 |
+
final_content = final_content.strip()
|
134 |
final_output["choices"][0]["message"]["content"] = final_content
|
135 |
return final_output
|
136 |
|
137 |
def chat_return_generator(self, stream_response):
|
138 |
is_finished = False
|
139 |
+
line_count = 0
|
140 |
for line in stream_response.iter_lines():
|
141 |
+
if line:
|
142 |
+
line_count += 1
|
143 |
+
else:
|
144 |
continue
|
145 |
|
146 |
content = self.parse_line(line)
|
|
|
151 |
is_finished = True
|
152 |
else:
|
153 |
content_type = "Completions"
|
154 |
+
if line_count == 1:
|
155 |
+
content = content.lstrip()
|
156 |
logger.back(content, end="")
|
157 |
|
158 |
output = self.message_outputer.output(
|