Skip to content

Commit d3132ec

Browse files
committed
fix: finish reason and chunk send
1 parent 102f88e commit d3132ec

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

veadk/models/ark_transform.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ def stream_event_to_chunk(
269269
we use our own implementation to support the responses api.
270270
"""
271271
choices = []
272-
model_response = None
273272

274273
if isinstance(event, ResponseTextDeltaEvent):
275274
delta = Message(content=event.delta)
@@ -279,18 +278,23 @@ def stream_event_to_chunk(
279278
model_response = ModelResponse(
280279
stream=True, choices=choices, model=model, id=str(uuid.uuid4())
281280
)
281+
for chunk, _ in _model_response_to_chunk(model_response):
282+
# delta text, not finish
283+
yield model_response, chunk, None
282284
elif isinstance(event, ResponseCompletedEvent):
283285
response = event.response
284286
model_response = self.transform_response(response, stream=True)
285287
model_response = fix_model_response(model_response)
288+
289+
for chunk, finish_reason in _model_response_to_chunk(model_response):
290+
if isinstance(chunk, TextChunk):
291+
yield model_response, None, finish_reason
292+
else:
293+
yield model_response, chunk, finish_reason
286294
else:
287295
# Ignore other event types like ResponseOutputItemAddedEvent, etc.
288296
pass
289297

290-
if model_response:
291-
for chunk, finish_reason in _model_response_to_chunk(model_response):
292-
yield model_response, chunk, finish_reason
293-
294298

295299
def fix_model_response(model_response: ModelResponse) -> ModelResponse:
296300
"""

0 commit comments

Comments
 (0)