Skip to content

Commit 516420f

Browse files
authored
bugfix: reslove core dump of stream chat completion request for VLM. (#333)
1 parent c383cb9 commit 516420f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

xllm/api_service/chat_service_impl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ bool send_delta_to_client_brpc(
344344
std::shared_ptr<StreamOutputParser> stream_parser = nullptr) {
345345
auto& response = call->response();
346346

347-
if (output.outputs.size() > 0) {
347+
if (stream_parser && output.outputs.size() > 0) {
348348
stream_parser->check_resize_for_index(output.outputs.size() - 1);
349349
}
350350
// send delta to client
@@ -371,7 +371,7 @@ bool send_delta_to_client_brpc(
371371

372372
// Handle reasoning text
373373
if (!cur_text.empty()) {
374-
if (stream_parser->is_reasoning()) {
374+
if (stream_parser && stream_parser->is_reasoning()) {
375375
auto parser = stream_parser->get_reasoning_parser(index);
376376
auto result = parser->parse_stream_chunk(cur_text);
377377
if (result.normal_text.has_value()) {
@@ -392,7 +392,7 @@ bool send_delta_to_client_brpc(
392392

393393
if (!cur_text.empty()) {
394394
// Handle tool call text
395-
if (stream_parser->is_tool_call()) {
395+
if (stream_parser && stream_parser->is_tool_call()) {
396396
if (!process_tool_call_stream(call,
397397
stream_parser,
398398
index,
@@ -422,7 +422,7 @@ bool send_delta_to_client_brpc(
422422
// Handle finish reason
423423
if (seq_output.finish_reason.has_value()) {
424424
// Check for unstreamed tool args before sending finish reason
425-
if (stream_parser->get_has_tool_call(index)) {
425+
if (stream_parser && stream_parser->get_has_tool_call(index)) {
426426
if (!check_for_unstreamed_tool_args(
427427
call, stream_parser, index, request_id, created_time, model)) {
428428
return false;
@@ -438,7 +438,7 @@ bool send_delta_to_client_brpc(
438438
choice->set_index(index);
439439
choice->mutable_delta();
440440

441-
if (stream_parser->get_has_tool_call(index) &&
441+
if (stream_parser && stream_parser->get_has_tool_call(index) &&
442442
seq_output.finish_reason.value() == "stop") {
443443
choice->set_finish_reason("tool_calls");
444444
} else {
@@ -615,7 +615,8 @@ void ChatServiceImpl::process_async_impl(std::shared_ptr<ChatCall> call) {
615615
request_params.chat_template_kwargs, reasoning_parser_format_);
616616

617617
std::shared_ptr<StreamOutputParser> stream_parser;
618-
if (request_params.streaming) {
618+
if (request_params.streaming && (!tool_call_parser_format_.empty() ||
619+
!reasoning_parser_format_.empty())) {
619620
stream_parser =
620621
std::make_shared<StreamOutputParser>(request_params.tools,
621622
tool_call_parser_format_,

0 commit comments

Comments
 (0)