From 573c7b5d6baaa12ad15b044cd2dd105acd7ce299 Mon Sep 17 00:00:00 2001 From: braisedpork1964 <497494458@qq.com> Date: Thu, 24 Oct 2024 18:50:57 +0800 Subject: [PATCH] update --- lagent/llms/openai.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lagent/llms/openai.py b/lagent/llms/openai.py index e5e202ce..44df2330 100644 --- a/lagent/llms/openai.py +++ b/lagent/llms/openai.py @@ -243,7 +243,7 @@ def _chat(self, messages: List[dict], **gen_params) -> str: response['error']) self.logger.error(errmsg) except Exception as error: - errmsg = str(error) + ' ' + str(traceback.format_exc()) + errmsg = str(error) + '\n' + str(traceback.format_exc()) self.logger.error(errmsg) max_num_retries += 1 @@ -293,10 +293,9 @@ def streaming(raw_response): return yield choice['delta'].get('content', '') except Exception as exc: - print( - f'response {decoded} lead to exception of {str(exc)}' - ) - raise + msg = f'response {decoded} lead to exception of {str(exc)}' + self.logger.error(msg) + raise Exception(msg) from exc assert isinstance(messages, list) @@ -359,7 +358,7 @@ def streaming(raw_response): response['error']) self.logger.error(errmsg) except Exception as error: - errmsg = str(error) + ' ' + str(traceback.format_exc()) + errmsg = str(error) + '\n' + str(traceback.format_exc()) self.logger.error(errmsg) max_num_retries += 1 @@ -694,7 +693,7 @@ async def _chat(self, messages: List[dict], **gen_params) -> str: response['error']) self.logger.error(errmsg) except Exception as error: - errmsg = str(error) + ' ' + str(traceback.format_exc()) + errmsg = str(error) + '\n' + str(traceback.format_exc()) self.logger.error(errmsg) max_num_retries += 1 @@ -743,10 +742,9 @@ async def streaming(raw_response): return yield choice['delta'].get('content', '') except Exception as exc: - self.logger.error( - f'response {decoded} lead to exception of {str(exc)}' - ) - raise + msg = f'response {decoded} lead to exception of {str(exc)}' + self.logger.error(msg) + raise Exception(msg) from exc assert isinstance(messages, list) @@ -814,7 +812,7 @@ async def streaming(raw_response): response['error']) self.logger.error(errmsg) except Exception as error: - errmsg = str(error) + ' ' + str(traceback.format_exc()) + errmsg = str(error) + '\n' + str(traceback.format_exc()) self.logger.error(errmsg) max_num_retries += 1