Skip to content

Commit 062f5a7

Browse files
committed
šŸ› Unit test: throws an exception when there are more tokens available #954
1 parent f338cfb commit 062f5a7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ā€Žtest/sdk/core/models/test_openai_long_context_model.pyā€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,13 @@ def test_truncation_strategies_comparison(long_context_model):
223223
assert start_result != end_result
224224
assert start_result != middle_result
225225
assert end_result != middle_result
226+
227+
228+
def test_prepare_long_text_message_insufficient_tokens(long_context_model):
229+
"""Test that ValueError is raised when there are insufficient tokens available"""
230+
# Mock count_tokens to return high values that exceed max_context_tokens
231+
long_context_model.count_tokens = MagicMock(side_effect=[50000, 40000, 1000]) # system + user + content
232+
long_context_model.max_context_tokens = 80000 # Less than required (50000 + 40000 + 100)
233+
234+
with pytest.raises(ValueError, match="Insufficient tokens available"):
235+
long_context_model.prepare_long_text_message("content", "system prompt", "user prompt")

0 commit comments

Comments
Ā (0)