mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 02:14:23 +00:00
- Ship tiktoken's cl100k_base inside the package and build the encoding from it, so token counting never downloads anything. - Default EMBEDDINGS_CACHE_DIR to <data home>/models instead of FastEmbed's temp dir, and read tokenizer.json and repo metadata from that cache, so a model downloads once and survives reboots. - TTS_PROVIDER=none and STT_PROVIDER=none switch the speech features off: the endpoints return 404, audio files fail to ingest with a clear message, /api/config reports tts_available/stt_available, and the UI hides the Speak and microphone buttons. - Drop the Google Fonts Roboto import from the web UI. - prefetch-models fills the cache the app reads; verify-offline checks the packaged encoding. - Docs: new Air-Gapped Deployment guide, settings and cache notes.
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from docsgpt.stt.stt_creator import STTCreator
|
|
|
|
|
|
@pytest.fixture
|
|
def stt_creator():
|
|
return STTCreator()
|
|
|
|
|
|
def test_create_openai_stt(stt_creator):
|
|
with patch.dict(STTCreator.stt_providers, {"openai": MagicMock()}):
|
|
mock_openai_stt = STTCreator.stt_providers["openai"]
|
|
instance = MagicMock()
|
|
mock_openai_stt.return_value = instance
|
|
|
|
result = stt_creator.create_stt("openai", "arg1", language="en")
|
|
|
|
mock_openai_stt.assert_called_once_with("arg1", language="en")
|
|
assert result == instance
|
|
|
|
|
|
def test_create_faster_whisper_stt(stt_creator):
|
|
with patch.dict(STTCreator.stt_providers, {"faster_whisper": MagicMock()}):
|
|
mock_faster_whisper_stt = STTCreator.stt_providers["faster_whisper"]
|
|
instance = MagicMock()
|
|
mock_faster_whisper_stt.return_value = instance
|
|
|
|
result = stt_creator.create_stt("faster_whisper", model_size="base")
|
|
|
|
mock_faster_whisper_stt.assert_called_once_with(model_size="base")
|
|
assert result == instance
|
|
|
|
|
|
def test_invalid_stt_type(stt_creator):
|
|
with pytest.raises(ValueError) as excinfo:
|
|
stt_creator.create_stt("unknown_stt")
|
|
assert "No stt class found" in str(excinfo.value)
|
|
|
|
|
|
def test_stt_type_case_insensitivity(stt_creator):
|
|
with patch.dict(STTCreator.stt_providers, {"openai": MagicMock()}):
|
|
mock_openai_stt = STTCreator.stt_providers["openai"]
|
|
instance = MagicMock()
|
|
mock_openai_stt.return_value = instance
|
|
|
|
result = stt_creator.create_stt("OpEnAi")
|
|
|
|
mock_openai_stt.assert_called_once_with()
|
|
assert result == instance
|
|
|
|
|
|
@pytest.mark.parametrize("value", ["none", "NONE", " none ", "", None])
|
|
def test_is_enabled_false_when_switched_off(value):
|
|
assert STTCreator.is_enabled(value) is False
|
|
|
|
|
|
@pytest.mark.parametrize("value", ["openai", "faster_whisper"])
|
|
def test_is_enabled_for_a_provider(value):
|
|
assert STTCreator.is_enabled(value) is True
|
|
|
|
|
|
def test_stt_providers_integrity(stt_creator):
|
|
providers = stt_creator.stt_providers
|
|
assert "openai" in providers
|
|
assert "faster_whisper" in providers
|
|
assert callable(providers["openai"])
|
|
assert callable(providers["faster_whisper"])
|