Skip to content

Commit 0af6362

Browse files
committed
wip
1 parent 2a5781b commit 0af6362

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/server/server-context.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,10 +2654,12 @@ static std::unique_ptr<server_res_generator> handle_completions_impl(
26542654
}
26552655

26562656
// next responses are streamed
2657+
// to be sent immediately
2658+
json first_result_json = first_result->to_json();
26572659
if (res_type == TASK_RESPONSE_TYPE_ANTHROPIC) {
2658-
res->data = format_anthropic_sse(first_result->to_json());
2660+
res->data = format_anthropic_sse(first_result_json);
26592661
} else {
2660-
res->data = format_oai_sse(first_result->to_json()); // to be sent immediately
2662+
res->data = format_oai_sse(first_result_json);
26612663
}
26622664
res->status = 200;
26632665
res->content_type = "text/event-stream";
@@ -2698,8 +2700,8 @@ static std::unique_ptr<server_res_generator> handle_completions_impl(
26982700
}
26992701

27002702
// send the results
2701-
json res_json = result->to_json();
27022703
if (result->is_error()) {
2704+
json res_json = result->to_json();
27032705
if (res_type == TASK_RESPONSE_TYPE_ANTHROPIC) {
27042706
output = format_anthropic_sse({
27052707
{"event", "error"},
@@ -2716,6 +2718,7 @@ static std::unique_ptr<server_res_generator> handle_completions_impl(
27162718
|| dynamic_cast<server_task_result_cmpl_final*>(result.get()) != nullptr
27172719
);
27182720
result->update(states[result->get_index()]); // update generation state
2721+
json res_json = result->to_json();
27192722
if (res_type == TASK_RESPONSE_TYPE_ANTHROPIC) {
27202723
output = format_anthropic_sse(res_json);
27212724
} else {

0 commit comments

Comments
 (0)