Team Ai
Apppublic

Underground-Digital/Workflow-Engine

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
test_speech2text.py46 linesDownload Raw Back to gitee_ai
1import os
2
3import pytest
4
5from core.model_runtime.errors.validate import CredentialsValidateFailedError
6from core.model_runtime.model_providers.gitee_ai.speech2text.speech2text import GiteeAISpeech2TextModel
7
8
9def test_validate_credentials():
10    model = GiteeAISpeech2TextModel()
11
12    with pytest.raises(CredentialsValidateFailedError):
13        model.validate_credentials(
14            model="whisper-base",
15            credentials={"api_key": "invalid_key"},
16        )
17
18    model.validate_credentials(
19        model="whisper-base",
20        credentials={"api_key": os.environ.get("GITEE_AI_API_KEY")},
21    )
22
23
24def test_invoke_model():
25    model = GiteeAISpeech2TextModel()
26
27    # Get the directory of the current file
28    current_dir = os.path.dirname(os.path.abspath(__file__))
29
30    # Get assets directory
31    assets_dir = os.path.join(os.path.dirname(current_dir), "assets")
32
33    # Construct the path to the audio file
34    audio_file_path = os.path.join(assets_dir, "audio.mp3")
35
36    # Open the file and get the file object
37    with open(audio_file_path, "rb") as audio_file:
38        file = audio_file
39
40        result = model.invoke(
41            model="whisper-base", credentials={"api_key": os.environ.get("GITEE_AI_API_KEY")}, file=file
42        )
43
44        assert isinstance(result, str)
45        assert result == "1 2 3 4 5 6 7 8 9 10"
46