server: add data: [DONE] to /chat/completions stream response

This commit is contained in:
VoidIsVoid 2024-09-13 11:09:41 +08:00 committed by Gimling
parent 78203641fe
commit 8f358c4c94
2 changed files with 4 additions and 0 deletions

View file

@ -2986,6 +2986,8 @@ int main(int argc, char ** argv) {
}, [&](json error_data) {
server_sent_event(sink, "error", error_data);
});
static const std::string ev_done = "data: [DONE]\n\n";
sink.write(ev_done.data(), ev_done.size());
sink.done();
return true;
};

View file

@ -1020,6 +1020,8 @@ async def oai_chat_completions(user_prompt,
event_data = line.split(': ', 1)
assert event_data[0] == 'data', f'Bad event code received: ```{event_data}```'
chunk_raw = event_data[1]
if chunk_raw == '[DONE]':
break
chunk = json.loads(chunk_raw)
assert len(chunk['choices']) == 1, f"no choices provided, line ```{line}```"