Skip to content

Commit 2c6fb22

Browse files
authored
[Update] add finish_reason_confirm tag in OpenAISDKStreaming
1 parent 714b380 commit 2c6fb22

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

opencompass/models/openai_streaming.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self,
5454
stream: bool = True,
5555
stream_chunk_size: int = 1,
5656
timeout: int = 3600,
57+
finish_reason_confirm: bool = True,
5758
max_workers: Optional[int] = None):
5859

5960
super().__init__(
@@ -84,6 +85,7 @@ def __init__(self,
8485
self.stream_chunk_size = stream_chunk_size
8586
self.openai_extra_kwargs = openai_extra_kwargs
8687
self.timeout = timeout
88+
self.finish_reason_confirm = finish_reason_confirm
8789

8890
def _create_fresh_client(self):
8991
"""Create a fresh OpenAI client for each request to avoid
@@ -336,17 +338,18 @@ def log_with_thread(message, level='info'):
336338
# Combine reasoning content and regular content
337339
complete_content = ''.join(completion_chunks)
338340

339-
if finish_reason is None:
340-
elapsed = time.time() - start_time
341-
log_with_thread(
342-
f'Stream ended without finish_reason (possible truncation). '
343-
f'elapsed={elapsed:.1f}s chunks={chunk_count} '
344-
f'content_len={sum(len(x) for x in completion_chunks)} '
345-
f'reasoning_len={len(reasoning_content)}',
346-
'error',
347-
)
348-
raise RuntimeError(
349-
'Streaming ended without finish_reason (truncated).')
341+
if self.finish_reason_confirm:
342+
if finish_reason is None:
343+
elapsed = time.time() - start_time
344+
log_with_thread(
345+
f'Stream ended without finish_reason (truncated). '
346+
f'elapsed={elapsed:.1f}s chunks={chunk_count} '
347+
f'content_len={sum(len(x) for x in completion_chunks)} '
348+
f'reasoning_len={len(reasoning_content)}',
349+
'error',
350+
)
351+
raise RuntimeError(
352+
'Streaming ended without finish_reason (truncated).')
350353

351354
if self.verbose:
352355
log_with_thread(f'Stream processing complete. Content length: '

0 commit comments

Comments
 (0)