Skip to content

Commit af13512

Browse files
author
Michal Kulakowski
committed
Support finish reason in legacy pipelines
1 parent 26daeb4 commit af13512

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/llm/apis/openai_completions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ std::string OpenAIChatCompletionsHandler::serializeUnaryResponse(ov::genai::Enco
416416
ParsedOutput parsedOutput = parseOutputIfNeeded(tokens);
417417
jsonResponse.StartObject();
418418
// finish_reason: "stop" in regular scenario, "tool_calls" if output contains tool calls
419-
auto finishReason = mapFinishReason(ov::genai::GenerationFinishReason::STOP, !parsedOutput.toolCalls.empty());
419+
auto finishReason = mapFinishReason(results.finish_reasons[index], !parsedOutput.toolCalls.empty());
420420
jsonResponse.FinishReason(finishReason.value_or("unknown"));
421421
// index: integer; Choice index, only n=1 supported anyway
422422
jsonResponse.Index(index++);
@@ -482,7 +482,7 @@ std::string OpenAIChatCompletionsHandler::serializeUnaryResponse(ov::genai::VLMD
482482
ParsedOutput parsedOutput = parseOutputIfNeeded(generatedTokens);
483483
jsonResponse.StartObject();
484484
// finish_reason: "stop" in regular scenario, "tool_calls" if output contains tool calls
485-
auto finishReason = mapFinishReason(ov::genai::GenerationFinishReason::STOP, !parsedOutput.toolCalls.empty());
485+
auto finishReason = mapFinishReason(results.finish_reasons[index], !parsedOutput.toolCalls.empty());
486486
jsonResponse.FinishReason(finishReason.value_or("unknown"));
487487
// index: integer; Choice index, only n=1 supported anyway
488488
jsonResponse.Index(index++);

src/llm/language_model/legacy/servable.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ absl::Status LegacyServable::preparePartialResponse(std::shared_ptr<GenAiServabl
228228
if (!executionContext->lastStreamerCallbackOutput.empty()) {
229229
lastTextChunk = lastTextChunk + executionContext->lastStreamerCallbackOutput;
230230
}
231-
std::string serializedChunk = executionContext->apiHandler->serializeStreamingChunk(lastTextChunk, ov::genai::GenerationFinishReason::STOP);
231+
ov::genai::GenerationFinishReason finishReason = ov::genai::GenerationFinishReason::STOP;
232+
if (!legacyExecutionContext->results.finish_reasons.empty()) {
233+
finishReason = legacyExecutionContext->results.finish_reasons[0];
234+
}
235+
std::string serializedChunk = executionContext->apiHandler->serializeStreamingChunk(lastTextChunk, finishReason);
232236
if (!serializedChunk.empty()) {
233237
executionContext->response = wrapTextInServerSideEventMessage(serializedChunk);
234238
}

src/test/llm/llmnode_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,7 @@ INSTANTIATE_TEST_SUITE_P(
26062606
::testing::Values(
26072607
// params: model name, generate expected output, check logprobs, check finish reason, test speculative decoding, supports empty handshake msg
26082608
TestParameters{"lm_cb_regular", true, true, true, false, true},
2609-
TestParameters{"lm_legacy_regular", false, false, false, false, false},
2609+
TestParameters{"lm_legacy_regular", false, false, true, false, false},
26102610
TestParameters{"vlm_cb_regular", false, true, true, false, true},
26112611
TestParameters{"vlm_legacy_regular", false, false, false, false, false}));
26122612

0 commit comments

Comments
 (0)