From e2826a6f536b373309c055271044a15c1ba17a79 Mon Sep 17 00:00:00 2001 From: MaiziXiao Date: Thu, 24 Apr 2025 09:47:25 +0000 Subject: [PATCH] [Bug] Concat OpenaiSDK reasoning content --- opencompass/models/openai_api.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/opencompass/models/openai_api.py b/opencompass/models/openai_api.py index 6ef11b8f..45d1a42c 100644 --- a/opencompass/models/openai_api.py +++ b/opencompass/models/openai_api.py @@ -661,18 +661,22 @@ class OpenAISDK(OpenAI): pass # noqa F841 # Check if response is empty or content is empty - if not responses.choices or not responses.choices[ - 0].message.content: + if (not responses.choices or not responses.choices[0].message + or not responses.choices[0].message.content): + # self.logger.info('API responses: %s', responses) self.logger.error( - 'API response is empty, it might be due to excessive ' - 'input length or an internal server error ' - 'from your API provider.') + 'Failed to extract content from the responses. ' + 'Please check the API response for detail information.' + 'API responses: %s', + responses, + ) num_retries += 1 # Continue to retry instead of returning empty response continue - # If the model has reasoning_content, concat it - # with the content - if hasattr(responses.choices[0].message, 'reasoning_content'): + + # Concat Reasoning Content and tags to content + if (hasattr(responses.choices[0].message, 'reasoning_content') + and responses.choices[0].message.reasoning_content): return (responses.choices[0].message.reasoning_content + self.think_tag + responses.choices[0].message.content)