test_speech2text.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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={
  11. "api_key": "invalid_key"
  12. },
  13. )
  14. model.validate_credentials(
  15. model="iic/SenseVoiceSmall",
  16. credentials={
  17. "api_key": os.environ.get("API_KEY")
  18. },
  19. )
  20. def test_invoke_model():
  21. model = SiliconflowSpeech2TextModel()
  22. # Get the directory of the current file
  23. current_dir = os.path.dirname(os.path.abspath(__file__))
  24. # Get assets directory
  25. assets_dir = os.path.join(os.path.dirname(current_dir), "assets")
  26. # Construct the path to the audio file
  27. audio_file_path = os.path.join(assets_dir, "audio.mp3")
  28. # Open the file and get the file object
  29. with open(audio_file_path, "rb") as audio_file:
  30. file = audio_file
  31. result = model.invoke(
  32. model="iic/SenseVoiceSmall",
  33. credentials={
  34. "api_key": os.environ.get("API_KEY")
  35. },
  36. file=file
  37. )
  38. assert isinstance(result, str)
  39. assert result == '1,2,3,4,5,6,7,8,9,10.'