From 61e3c042b4de338339496cb5d637bd509a980aee Mon Sep 17 00:00:00 2001 From: bigbrother666sh Date: Thu, 10 Oct 2024 20:23:58 +0800 Subject: [PATCH] repair openai wrapper --- core/llms/openai_wrapper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/llms/openai_wrapper.py b/core/llms/openai_wrapper.py index 9dfb39b..ceb7a4e 100644 --- a/core/llms/openai_wrapper.py +++ b/core/llms/openai_wrapper.py @@ -29,8 +29,10 @@ def openai_llm(messages: list, model: str, logger=None, **kwargs) -> str: logger.warning(f'{e}\nRetrying in 60 second...') time.sleep(60) response = client.chat.completions.create(messages=messages, model=model, **kwargs) - if 'choices' not in response: - logger.warning(f'openai_llm warning: {response}') + if response and response.choices: + return response.choices[0].message.content + else: + logger.error(f'after many try, llm error: {response}') return "" except Exception as e: if logger: