mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
* handover final summary to Zephyr deployment * fix display error * push new summary feature * fix failing test case * Added markdown support for final summary * update UI render issue * retain sentence tokenizer call --------- Co-authored-by: Koper <andreas@monadical.com>
105 lines
3.5 KiB
Python
105 lines
3.5 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
|
@pytest.mark.asyncio
|
|
async def setup_database():
|
|
from reflector.settings import settings
|
|
from tempfile import NamedTemporaryFile
|
|
|
|
with NamedTemporaryFile() as f:
|
|
settings.DATABASE_URL = f"sqlite:///{f.name}"
|
|
from reflector.db import engine, metadata
|
|
|
|
metadata.create_all(bind=engine)
|
|
|
|
yield
|
|
|
|
|
|
@pytest.fixture
|
|
def dummy_processors():
|
|
with patch(
|
|
"reflector.processors.transcript_topic_detector.TranscriptTopicDetectorProcessor.get_topic"
|
|
) as mock_topic, patch(
|
|
"reflector.processors.transcript_final_title.TranscriptFinalTitleProcessor.get_title"
|
|
) as mock_title, patch(
|
|
"reflector.processors.transcript_final_long_summary.TranscriptFinalLongSummaryProcessor.get_long_summary"
|
|
) as mock_long_summary, patch(
|
|
"reflector.processors.transcript_final_short_summary.TranscriptFinalShortSummaryProcessor.get_short_summary"
|
|
) as mock_short_summary, patch(
|
|
"reflector.processors.transcript_translator.TranscriptTranslatorProcessor.get_translation"
|
|
) as mock_translate:
|
|
mock_topic.return_value = {"title": "LLM TITLE", "summary": "LLM SUMMARY"}
|
|
mock_title.return_value = {"title": "LLM TITLE"}
|
|
mock_long_summary.return_value = "LLM LONG SUMMARY"
|
|
mock_short_summary.return_value = {"short_summary": "LLM SHORT SUMMARY"}
|
|
mock_translate.return_value = "Bonjour le monde"
|
|
yield mock_translate, mock_topic, mock_title, mock_long_summary, mock_short_summary # noqa
|
|
|
|
|
|
@pytest.fixture
|
|
async def dummy_transcript():
|
|
from reflector.processors.audio_transcript import AudioTranscriptProcessor
|
|
from reflector.processors.types import AudioFile, Transcript, Word
|
|
|
|
class TestAudioTranscriptProcessor(AudioTranscriptProcessor):
|
|
async def _transcript(self, data: AudioFile):
|
|
source_language = self.get_pref("audio:source_language", "en")
|
|
print("transcripting", source_language)
|
|
print("pipeline", self.pipeline)
|
|
print("prefs", self.pipeline.prefs)
|
|
|
|
return Transcript(
|
|
text="Hello world.",
|
|
words=[
|
|
Word(start=0.0, end=1.0, text="Hello"),
|
|
Word(start=1.0, end=2.0, text=" world."),
|
|
],
|
|
)
|
|
|
|
with patch(
|
|
"reflector.processors.audio_transcript_auto"
|
|
".AudioTranscriptAutoProcessor.get_instance"
|
|
) as mock_audio:
|
|
mock_audio.return_value = TestAudioTranscriptProcessor()
|
|
yield
|
|
|
|
|
|
@pytest.fixture
|
|
async def dummy_llm():
|
|
from reflector.llm.base import LLM
|
|
|
|
class TestLLM(LLM):
|
|
def __init__(self):
|
|
self.model_name = "DUMMY MODEL"
|
|
self.llm_tokenizer = "DUMMY TOKENIZER"
|
|
|
|
with patch("reflector.llm.base.LLM.get_instance") as mock_llm:
|
|
mock_llm.return_value = TestLLM()
|
|
yield
|
|
|
|
|
|
@pytest.fixture
|
|
def nltk():
|
|
with patch("reflector.llm.base.LLM.ensure_nltk") as mock_nltk:
|
|
mock_nltk.return_value = "NLTK PACKAGE"
|
|
yield
|
|
|
|
|
|
@pytest.fixture
|
|
def ensure_casing():
|
|
with patch("reflector.llm.base.LLM.ensure_casing") as mock_casing:
|
|
mock_casing.return_value = "LLM TITLE"
|
|
yield
|
|
|
|
|
|
@pytest.fixture
|
|
def sentence_tokenize():
|
|
with patch(
|
|
"reflector.processors.TranscriptFinalLongSummaryProcessor" ".sentence_tokenize"
|
|
) as mock_sent_tokenize:
|
|
mock_sent_tokenize.return_value = ["LLM LONG SUMMARY"]
|
|
yield
|