openai_speech2text.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import re
  2. from typing import Any, List, Literal, Union
  3. from core.model_runtime.errors.invoke import InvokeAuthorizationError
  4. from openai._types import NOT_GIVEN, FileTypes, NotGiven
  5. from openai.resources.audio.transcriptions import Transcriptions
  6. from openai.types.audio.transcription import Transcription
  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. )