Team Ai
Apppublic

Underground-Digital/Workflow-Engine

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
test_speech2text.py46 linesDownload Raw Back to openai
1import os2 3import pytest4 5from core.model_runtime.errors.validate import CredentialsValidateFailedError6from core.model_runtime.model_providers.openai.speech2text.speech2text import OpenAISpeech2TextModel7from tests.integration_tests.model_runtime.__mock.openai import setup_openai_mock8 9 10@pytest.mark.parametrize("setup_openai_mock", [["speech2text"]], indirect=True)11def test_validate_credentials(setup_openai_mock):12    model = OpenAISpeech2TextModel()13 14    with pytest.raises(CredentialsValidateFailedError):15        model.validate_credentials(model="whisper-1", credentials={"openai_api_key": "invalid_key"})16 17    model.validate_credentials(model="whisper-1", credentials={"openai_api_key": os.environ.get("OPENAI_API_KEY")})18 19 20@pytest.mark.parametrize("setup_openai_mock", [["speech2text"]], indirect=True)21def test_invoke_model(setup_openai_mock):22    model = OpenAISpeech2TextModel()23 24    # Get the directory of the current file25    current_dir = os.path.dirname(os.path.abspath(__file__))26 27    # Get assets directory28    assets_dir = os.path.join(os.path.dirname(current_dir), "assets")29 30    # Construct the path to the audio file31    audio_file_path = os.path.join(assets_dir, "audio.mp3")32 33    # Open the file and get the file object34    with open(audio_file_path, "rb") as audio_file:35        file = audio_file36 37        result = model.invoke(38            model="whisper-1",39            credentials={"openai_api_key": os.environ.get("OPENAI_API_KEY")},40            file=file,41            user="abc-123",42        )43 44        assert isinstance(result, str)45        assert result == "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"46