Skip to content

Commit ec3924c

Browse files
MaiziXiaostephen-nju
authored andcommitted
[Bug] Concat OpenaiSDK reasoning content (open-compass#2041)
* [Bug] Concat OpenaiSDK reasoning content * [Bug] Concat OpenaiSDK reasoning content * update * update
1 parent 1a6c92d commit ec3924c

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

opencompass/models/openai_api.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,18 +661,32 @@ def _generate(self,
661661
pass # noqa F841
662662

663663
# Check if response is empty or content is empty
664-
if not responses.choices or not responses.choices[
665-
0].message.content:
664+
if (not responses.choices or not responses.choices[0].message
665+
or not responses.choices[0].message.content):
666666
self.logger.error(
667-
'API response is empty, it might be due to excessive '
668-
'input length or an internal server error '
669-
'from your API provider.')
667+
'Failed to extract content from the responses. '
668+
'Please check the API response for detail information.'
669+
'API responses: %s',
670+
responses,
671+
)
670672
num_retries += 1
671673
# Continue to retry instead of returning empty response
672674
continue
673-
# If the model has reasoning_content, concat it
674-
# with the content
675-
if hasattr(responses.choices[0].message, 'reasoning_content'):
675+
676+
# Concat Reasoning Content and tags to content
677+
if (hasattr(responses.choices[0].message, 'reasoning_content')
678+
and responses.choices[0].message.reasoning_content):
679+
if self.verbose:
680+
self.logger.info(
681+
'Follow'
682+
'vllm/reasoning/deepseek_r1_reasoning_parser'
683+
'to parse the reasoning content and tags'
684+
'Reasoning Content: %s, \n'
685+
'Tags: %s, \n'
686+
'Content: %s',
687+
responses.choices[0].message.reasoning_content,
688+
self.think_tag,
689+
responses.choices[0].message.content)
676690
return (responses.choices[0].message.reasoning_content +
677691
self.think_tag +
678692
responses.choices[0].message.content)

0 commit comments

Comments
 (0)