Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion swift/pipelines/infer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _post_process(self, request_info, response, return_cmpl_response: bool = Fal

is_finished = all(response.choices[i].finish_reason for i in range(len(response.choices)))
if 'stream' in response.__class__.__name__.lower():
request_info['response'] += response.choices[0].delta.content
request_info['response'] += response.choices[0].delta.content or ''
else:
request_info['response'] = response.choices[0].message.content
if return_cmpl_response:
Expand Down
27 changes: 27 additions & 0 deletions tests/deploy/test_deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from types import SimpleNamespace

from swift.infer_engine.protocol import ChatCompletionResponseStreamChoice, ChatCompletionStreamResponse, DeltaMessage
from swift.pipelines.infer.deploy import SwiftDeploy


def test_post_process_reasoning_only_stream_chunk():
deploy = object.__new__(SwiftDeploy)
deploy.args = SimpleNamespace()
request_info = {'response': ''}
response = ChatCompletionStreamResponse(
model='test',
choices=[
ChatCompletionResponseStreamChoice(
index=0,
delta=DeltaMessage(content=None, reasoning_content='thinking'),
finish_reason=None,
)
],
)

processed = deploy._post_process(request_info, response)

assert processed is response
assert processed.choices[0].delta.content is None
assert processed.choices[0].delta.reasoning_content == 'thinking'
assert request_info['response'] == ''
Loading