-
Notifications
You must be signed in to change notification settings - Fork 251
Mkulakow/legacy pipeline finish reason #4169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -409,17 +409,18 @@ std::string OpenAIChatCompletionsHandler::serializeUnaryResponse(ov::genai::Enco | |
|
|
||
| // choices: array of size N, where N is related to n request parameter | ||
| jsonResponse.StartArray("choices"); | ||
| int index = 0; | ||
| for (int i = 0; i < results.tokens.size(); i++) { | ||
| for (size_t i = 0; i < results.tokens.size(); ++i) { | ||
| const std::vector<int64_t>& tokens = results.tokens[i]; | ||
| SPDLOG_LOGGER_TRACE(llm_calculator_logger, "Generated tokens: {}", tokens); | ||
| ParsedOutput parsedOutput = parseOutputIfNeeded(tokens); | ||
| jsonResponse.StartObject(); | ||
| // finish_reason: "stop" in regular scenario, "tool_calls" if output contains tool calls | ||
| auto finishReason = mapFinishReason(ov::genai::GenerationFinishReason::STOP, !parsedOutput.toolCalls.empty()); | ||
| const ov::genai::GenerationFinishReason finishReasonRaw = | ||
| (!results.finish_reasons.empty()) ? results.finish_reasons[0] : ov::genai::GenerationFinishReason::STOP; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add comment that we access [0] because we always use generate with batch=1 |
||
| auto finishReason = mapFinishReason(finishReasonRaw, !parsedOutput.toolCalls.empty()); | ||
| jsonResponse.FinishReason(finishReason.value_or("unknown")); | ||
| // index: integer; Choice index, only n=1 supported anyway | ||
| jsonResponse.Index(index++); | ||
| jsonResponse.Index(static_cast<int>(i)); | ||
|
|
||
| if (endpoint == Endpoint::CHAT_COMPLETIONS) { | ||
| jsonResponse.MessageObject(parsedOutput); | ||
|
|
@@ -481,7 +482,9 @@ std::string OpenAIChatCompletionsHandler::serializeUnaryResponse(ov::genai::VLMD | |
| ParsedOutput parsedOutput = parseOutputIfNeeded(generatedTokens); | ||
| jsonResponse.StartObject(); | ||
| // finish_reason: "stop" in regular scenario, "tool_calls" if output contains tool calls | ||
| auto finishReason = mapFinishReason(ov::genai::GenerationFinishReason::STOP, !parsedOutput.toolCalls.empty()); | ||
| const ov::genai::GenerationFinishReason finishReasonRaw = | ||
| (!results.finish_reasons.empty()) ? results.finish_reasons[0] : ov::genai::GenerationFinishReason::STOP; | ||
| auto finishReason = mapFinishReason(finishReasonRaw, !parsedOutput.toolCalls.empty()); | ||
| jsonResponse.FinishReason(finishReason.value_or("unknown")); | ||
| // index: integer; Choice index, only n=1 supported anyway | ||
| jsonResponse.Index(index++); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -649,10 +649,17 @@ std::string OpenAIResponsesHandler::serializeUnaryResponse(ov::genai::EncodedRes | |
| usage.promptTokens = results.perf_metrics.get_num_input_tokens(); | ||
| usage.completionTokens = results.perf_metrics.get_num_generated_tokens(); | ||
| std::vector<ParsedOutput> parsedOutputs; | ||
| ov::genai::GenerationFinishReason responsesFinishReason = ov::genai::GenerationFinishReason::STOP; | ||
| for (const auto& tokens : results.tokens) { | ||
| parsedOutputs.push_back(parseOutputIfNeeded(tokens)); | ||
| } | ||
| return serializeUnaryResponseImpl(parsedOutputs); | ||
| for (const auto& finishReason : results.finish_reasons) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have different implementation than chat/completions? cant we just take [0]? I think we also have batch size=1 here always |
||
| if (finishReason == ov::genai::GenerationFinishReason::LENGTH) { | ||
| responsesFinishReason = ov::genai::GenerationFinishReason::LENGTH; | ||
| break; | ||
| } | ||
| } | ||
| return serializeUnaryResponseImpl(parsedOutputs, responsesFinishReason); | ||
| } | ||
|
|
||
| std::string OpenAIResponsesHandler::serializeUnaryResponse(ov::genai::VLMDecodedResults& results, const std::string& textResponse) { | ||
|
|
@@ -673,7 +680,14 @@ std::string OpenAIResponsesHandler::serializeUnaryResponse(ov::genai::VLMDecoded | |
| parsedOutputs.push_back(std::move(output)); | ||
| } | ||
| } | ||
| return serializeUnaryResponseImpl(parsedOutputs); | ||
| ov::genai::GenerationFinishReason responsesFinishReason = ov::genai::GenerationFinishReason::STOP; | ||
| for (const auto& finishReason : results.finish_reasons) { | ||
| if (finishReason == ov::genai::GenerationFinishReason::LENGTH) { | ||
| responsesFinishReason = ov::genai::GenerationFinishReason::LENGTH; | ||
| break; | ||
| } | ||
| } | ||
| return serializeUnaryResponseImpl(parsedOutputs, responsesFinishReason); | ||
| } | ||
|
|
||
| // --- Streaming event building blocks --- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,7 +229,11 @@ absl::Status LegacyServable::preparePartialResponse(std::shared_ptr<GenAiServabl | |
| if (!executionContext->lastStreamerCallbackOutput.empty()) { | ||
| lastTextChunk = lastTextChunk + executionContext->lastStreamerCallbackOutput; | ||
| } | ||
| std::string serializedChunk = executionContext->apiHandler->serializeStreamingChunk(lastTextChunk, ov::genai::GenerationFinishReason::STOP); | ||
| ov::genai::GenerationFinishReason finishReason = ov::genai::GenerationFinishReason::STOP; | ||
| if (!legacyExecutionContext->results.finish_reasons.empty()) { | ||
| finishReason = legacyExecutionContext->results.finish_reasons[0]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isnt 0 finish reasons internal error here? should we throw if it happens? |
||
| } | ||
| std::string serializedChunk = executionContext->apiHandler->serializeStreamingChunk(lastTextChunk, finishReason); | ||
| if (!serializedChunk.empty()) { | ||
| executionContext->response = wrapTextInServerSideEventMessage(serializedChunk); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to have results.finish_reasons.empty() ? in which situations?