test_speech2text.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import os
  2. from pathlib import Path
  3. import pytest
  4. from core.model_runtime.errors.validate import CredentialsValidateFailedError
  5. from core.model_runtime.model_providers.gpustack.speech2text.speech2text import GPUStackSpeech2TextModel
  6. def test_validate_credentials():
  7. model = GPUStackSpeech2TextModel()
  8. with pytest.raises(CredentialsValidateFailedError):
  9. model.validate_credentials(
  10. model="faster-whisper-medium",
  11. credentials={
  12. "endpoint_url": "invalid_url",
  13. "api_key": "invalid_api_key",
  14. },
  15. )
  16. model.validate_credentials(
  17. model="faster-whisper-medium",
  18. credentials={
  19. "endpoint_url": os.environ.get("GPUSTACK_SERVER_URL"),
  20. "api_key": os.environ.get("GPUSTACK_API_KEY"),
  21. },
  22. )
  23. def test_invoke_model():
  24. model = GPUStackSpeech2TextModel()
  25. # Get the directory of the current file
  26. current_dir = os.path.dirname(os.path.abspath(__file__))
  27. # Get assets directory
  28. assets_dir = os.path.join(os.path.dirname(current_dir), "assets")
  29. # Construct the path to the audio file
  30. audio_file_path = os.path.join(assets_dir, "audio.mp3")
  31. file = Path(audio_file_path).read_bytes()
  32. result = model.invoke(
  33. model="faster-whisper-medium",
  34. credentials={
  35. "endpoint_url": os.environ.get("GPUSTACK_SERVER_URL"),
  36. "api_key": os.environ.get("GPUSTACK_API_KEY"),
  37. },
  38. file=file,
  39. )
  40. assert isinstance(result, str)
  41. assert result == "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"