test_speech2text.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import pytest
  3. from core.model_runtime.errors.validate import CredentialsValidateFailedError
  4. from core.model_runtime.model_providers.gitee_ai.speech2text.speech2text import GiteeAISpeech2TextModel
  5. def test_validate_credentials():
  6. model = GiteeAISpeech2TextModel()
  7. with pytest.raises(CredentialsValidateFailedError):
  8. model.validate_credentials(
  9. model="whisper-base",
  10. credentials={"api_key": "invalid_key"},
  11. )
  12. model.validate_credentials(
  13. model="whisper-base",
  14. credentials={"api_key": os.environ.get("GITEE_AI_API_KEY")},
  15. )
  16. def test_invoke_model():
  17. model = GiteeAISpeech2TextModel()
  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="whisper-base", credentials={"api_key": os.environ.get("GITEE_AI_API_KEY")}, file=file
  29. )
  30. assert isinstance(result, str)
  31. assert result == "1 2 3 4 5 6 7 8 9 10"