openai_speech2text.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import re
  2. from typing import Any, Literal, Union
  3. from openai._types import NOT_GIVEN, FileTypes, NotGiven
  4. from openai.resources.audio.transcriptions import Transcriptions
  5. from openai.types.audio.transcription import Transcription
  6. from core.model_runtime.errors.invoke import InvokeAuthorizationError
  7. class MockSpeech2TextClass:
  8. def speech2text_create(
  9. self: Transcriptions,
  10. *,
  11. file: FileTypes,
  12. model: Union[str, Literal["whisper-1"]],
  13. language: str | NotGiven = NOT_GIVEN,
  14. prompt: str | NotGiven = NOT_GIVEN,
  15. response_format: Literal["json", "text", "srt", "verbose_json", "vtt"] | NotGiven = NOT_GIVEN,
  16. temperature: float | NotGiven = NOT_GIVEN,
  17. **kwargs: Any,
  18. ) -> Transcription:
  19. if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", str(self._client.base_url)):
  20. raise InvokeAuthorizationError("Invalid base url")
  21. if len(self._client.api_key) < 18:
  22. raise InvokeAuthorizationError("Invalid API key")
  23. return Transcription(text="1, 2, 3, 4, 5, 6, 7, 8, 9, 10")