mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 23:32:39 +00:00
fix: handle None values in token counter
- Update sum_cached_prompt_tokens to handle None values gracefully - Add unit tests for token counting with None values - Fixes #2197 Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
17
tests/utilities/test_token_process.py
Normal file
17
tests/utilities/test_token_process.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import unittest
|
||||
from crewai.agents.agent_builder.utilities.base_token_process import TokenProcess
|
||||
|
||||
|
||||
class TestTokenProcess(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.token_process = TokenProcess()
|
||||
|
||||
def test_sum_cached_prompt_tokens_with_none(self):
|
||||
initial_tokens = self.token_process.cached_prompt_tokens
|
||||
self.token_process.sum_cached_prompt_tokens(None)
|
||||
self.assertEqual(self.token_process.cached_prompt_tokens, initial_tokens)
|
||||
|
||||
def test_sum_cached_prompt_tokens_with_int(self):
|
||||
initial_tokens = self.token_process.cached_prompt_tokens
|
||||
self.token_process.sum_cached_prompt_tokens(5)
|
||||
self.assertEqual(self.token_process.cached_prompt_tokens, initial_tokens + 5)
|
||||
Reference in New Issue
Block a user