test_speech2text.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. import pytest
  3. from core.model_runtime.errors.validate import CredentialsValidateFailedError
  4. from core.model_runtime.model_providers.siliconflow.speech2text.speech2text import SiliconflowSpeech2TextModel
  5. def test_validate_credentials():
  6. model = SiliconflowSpeech2TextModel()
  7. with pytest.raises(CredentialsValidateFailedError):
  8. model.validate_credentials(
  9. model="iic/SenseVoiceSmall",
  10. credentials={"api_key": "invalid_key"},
  11. )
  12. model.validate_credentials(
  13. model="iic/SenseVoiceSmall",
  14. credentials={"api_key": os.environ.get("API_KEY")},
  15. )
  16. def test_invoke_model():
  17. model = SiliconflowSpeech2TextModel()
  18. # Get the directory of the current file
  19. current_dir = os.path.dirname(os.path.abspath(__file__))
  20. # Get assets directory
  21. assets_dir = os.path.join(os.path.dirname(current_dir), "assets")
  22. # Construct the path to the audio file
  23. audio_file_path = os.path.join(assets_dir, "audio.mp3")
  24. # Open the file and get the file object
  25. with open(audio_file_path, "rb") as audio_file:
  26. file = audio_file
  27. result = model.invoke(
  28. model="iic/SenseVoiceSmall", credentials={"api_key": os.environ.get("API_KEY")}, file=file
  29. )
  30. assert isinstance(result, str)
  31. assert result == "1,2,3,4,5,6,7,8,9,10."