diff --git a/packages/leann-core/src/leann/chat.py b/packages/leann-core/src/leann/chat.py index 1f870bf..9d874bf 100644 --- a/packages/leann-core/src/leann/chat.py +++ b/packages/leann-core/src/leann/chat.py @@ -834,6 +834,11 @@ class OpenAIChat(LLMInterface): try: response = self.client.chat.completions.create(**params) + print( + f"Total tokens = {response.usage.total_tokens}, prompt tokens = {response.usage.prompt_tokens}, completion tokens = {response.usage.completion_tokens}" + ) + if response.choices[0].finish_reason == "length": + print("The query is exceeding the maximum allowed number of tokens") return response.choices[0].message.content.strip() except Exception as e: logger.error(f"Error communicating with OpenAI: {e}")