fed8b2eed7
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Backend release / release (push) Has been cancelled
Bandit Security Scan / bandit_scan (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / manifest (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / manifest (push) Has been cancelled
Python linting / ruff (push) Has been cancelled
Run python tests with pytest / Run tests and count coverage (3.12) (push) Has been cancelled
React Widget Build / build (push) Has been cancelled
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestCompressionThresholdChecker:
|
|
|
|
def _make_checker(self, pct=0.7):
|
|
from application.api.answer.services.compression.threshold_checker import (
|
|
CompressionThresholdChecker,
|
|
)
|
|
|
|
return CompressionThresholdChecker(threshold_percentage=pct)
|
|
|
|
@patch(
|
|
"application.api.answer.services.compression.threshold_checker.get_token_limit",
|
|
return_value=8000,
|
|
)
|
|
@patch(
|
|
"application.api.answer.services.compression.threshold_checker.TokenCounter.count_message_tokens",
|
|
return_value=6000,
|
|
)
|
|
def test_check_message_tokens_above_threshold(self, mock_count, mock_limit):
|
|
checker = self._make_checker(0.7)
|
|
assert checker.check_message_tokens([{"role": "user"}], "gpt-4") is True
|
|
|
|
@patch(
|
|
"application.api.answer.services.compression.threshold_checker.get_token_limit",
|
|
return_value=8000,
|
|
)
|
|
@patch(
|
|
"application.api.answer.services.compression.threshold_checker.TokenCounter.count_message_tokens",
|
|
return_value=1000,
|
|
)
|
|
def test_check_message_tokens_below_threshold(self, mock_count, mock_limit):
|
|
checker = self._make_checker(0.7)
|
|
assert checker.check_message_tokens([{"role": "user"}], "gpt-4") is False
|
|
|
|
@patch(
|
|
"application.api.answer.services.compression.threshold_checker.TokenCounter.count_message_tokens",
|
|
side_effect=Exception("Token error"),
|
|
)
|
|
def test_check_message_tokens_exception_returns_false(self, mock_count):
|
|
checker = self._make_checker(0.7)
|
|
assert checker.check_message_tokens([], "gpt-4") is False
|