openai_speech2text.py 1.1 KB

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