mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-16 14:26:52 +08:00
Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@@ -7,26 +7,17 @@ from core.model_runtime.model_providers.openai.speech2text.speech2text import Op
|
||||
from tests.integration_tests.model_runtime.__mock.openai import setup_openai_mock
|
||||
|
||||
|
||||
@pytest.mark.parametrize('setup_openai_mock', [['speech2text']], indirect=True)
|
||||
@pytest.mark.parametrize("setup_openai_mock", [["speech2text"]], indirect=True)
|
||||
def test_validate_credentials(setup_openai_mock):
|
||||
model = OpenAISpeech2TextModel()
|
||||
|
||||
with pytest.raises(CredentialsValidateFailedError):
|
||||
model.validate_credentials(
|
||||
model='whisper-1',
|
||||
credentials={
|
||||
'openai_api_key': 'invalid_key'
|
||||
}
|
||||
)
|
||||
model.validate_credentials(model="whisper-1", credentials={"openai_api_key": "invalid_key"})
|
||||
|
||||
model.validate_credentials(
|
||||
model='whisper-1',
|
||||
credentials={
|
||||
'openai_api_key': os.environ.get('OPENAI_API_KEY')
|
||||
}
|
||||
)
|
||||
model.validate_credentials(model="whisper-1", credentials={"openai_api_key": os.environ.get("OPENAI_API_KEY")})
|
||||
|
||||
@pytest.mark.parametrize('setup_openai_mock', [['speech2text']], indirect=True)
|
||||
|
||||
@pytest.mark.parametrize("setup_openai_mock", [["speech2text"]], indirect=True)
|
||||
def test_invoke_model(setup_openai_mock):
|
||||
model = OpenAISpeech2TextModel()
|
||||
|
||||
@@ -34,23 +25,21 @@ def test_invoke_model(setup_openai_mock):
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Get assets directory
|
||||
assets_dir = os.path.join(os.path.dirname(current_dir), 'assets')
|
||||
assets_dir = os.path.join(os.path.dirname(current_dir), "assets")
|
||||
|
||||
# Construct the path to the audio file
|
||||
audio_file_path = os.path.join(assets_dir, 'audio.mp3')
|
||||
audio_file_path = os.path.join(assets_dir, "audio.mp3")
|
||||
|
||||
# Open the file and get the file object
|
||||
with open(audio_file_path, 'rb') as audio_file:
|
||||
with open(audio_file_path, "rb") as audio_file:
|
||||
file = audio_file
|
||||
|
||||
result = model.invoke(
|
||||
model='whisper-1',
|
||||
credentials={
|
||||
'openai_api_key': os.environ.get('OPENAI_API_KEY')
|
||||
},
|
||||
model="whisper-1",
|
||||
credentials={"openai_api_key": os.environ.get("OPENAI_API_KEY")},
|
||||
file=file,
|
||||
user="abc-123"
|
||||
user="abc-123",
|
||||
)
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert result == '1, 2, 3, 4, 5, 6, 7, 8, 9, 10'
|
||||
assert result == "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"
|
||||
|
||||
Reference in New Issue
Block a user