Skip to content

Commit 9f2424a

Browse files
authored
Merge pull request #5 from anon998/stop-stream
Stop generating tokens when the stream is closed.
2 parents b6f536d + 3a079d5 commit 9f2424a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

examples/server/server.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ bool parse_options_completion(json body, llama_server_context& llama, Response &
668668
std::string tmp_stop =
669669
std::accumulate(llama.params.antiprompt.begin(), llama.params.antiprompt.end(),
670670
std::string{}, [](std::string a, std::string b) {
671-
return a + (a != "" ? ", \"" : "") + b + "\"";
671+
return a + (a != "" ? ", \"" : "\"") + b + "\"";
672672
});
673673

674674
fprintf(stderr,
@@ -860,7 +860,12 @@ int main(int argc, char **argv)
860860
data.dump(llama.json_indent, ' ', false,
861861
json::error_handler_t::replace) +
862862
"\n\n";
863-
sink.write(str.data(), str.size());
863+
if (!sink.write(str.data(), str.size())) {
864+
if (llama.verbose) {
865+
fprintf(stderr, "stream closed\n");
866+
}
867+
return false;
868+
}
864869
}
865870

866871
sink.done();

0 commit comments

Comments
 (0)