mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-24 10:24:35 +00:00
server: add data: [DONE] to /chat/completions stream response (#9459)
This commit is contained in:
parent
1f4111e540
commit
dcdcee3a74
@ -2993,6 +2993,8 @@ int main(int argc, char ** argv) {
|
|||||||
}, [&](json error_data) {
|
}, [&](json error_data) {
|
||||||
server_sent_event(sink, "error", 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();
|
sink.done();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -1020,6 +1020,8 @@ async def oai_chat_completions(user_prompt,
|
|||||||
event_data = line.split(': ', 1)
|
event_data = line.split(': ', 1)
|
||||||
assert event_data[0] == 'data', f'Bad event code received: ```{event_data}```'
|
assert event_data[0] == 'data', f'Bad event code received: ```{event_data}```'
|
||||||
chunk_raw = event_data[1]
|
chunk_raw = event_data[1]
|
||||||
|
if chunk_raw == '[DONE]':
|
||||||
|
break
|
||||||
|
|
||||||
chunk = json.loads(chunk_raw)
|
chunk = json.loads(chunk_raw)
|
||||||
assert len(chunk['choices']) == 1, f"no choices provided, line ```{line}```"
|
assert len(chunk['choices']) == 1, f"no choices provided, line ```{line}```"
|
||||||
|
Loading…
Reference in New Issue
Block a user