from pathlib import Path import pytest import torch from transformers import AutoTokenizer from processing_salmonn import SalmonnProcessor ROOT = Path(__file__).resolve().parents[1] @pytest.fixture(scope="module") def processor(): tokenizer = AutoTokenizer.from_pretrained(ROOT, fix_mistral_regex=False) return SalmonnProcessor(tokenizer) def test_basic_audio_request(processor): inputs = processor( audios=torch.zeros(1600), sampling_rate=16000, instruction="Describe the audio.", ) assert inputs["input_ids"].shape[0] == 1 assert inputs["audio_features"].shape == (1, 10, 128) assert inputs["audio_lengths"].tolist() == [10] assert inputs["audio_counts"].tolist() == [1] def test_text_only_context_does_not_add_audio(processor): prompt = processor.build_prompt( "Transcribe the speech.", context=["howes", "wszelaki"], ) assert prompt.count("