openai
__all__ = ['OpenAiAudioTranscriptionDriver']
module-attribute
Bases:
BaseAudioTranscriptionDriver
Source Code in griptape/drivers/audio_transcription/openai_audio_transcription_driver.py
@define class OpenAiAudioTranscriptionDriver(BaseAudioTranscriptionDriver): api_type: Optional[str] = field(default=openai.api_type, kw_only=True) api_version: Optional[str] = field(default=openai.api_version, kw_only=True, metadata={"serializable": True}) base_url: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": True}) api_key: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": False}) organization: Optional[str] = field(default=openai.organization, kw_only=True, metadata={"serializable": True}) _client: Optional[openai.OpenAI] = field( default=None, kw_only=True, alias="client", metadata={"serializable": False} ) @lazy_property() def client(self) -> openai.OpenAI: return openai.OpenAI(api_key=self.api_key, base_url=self.base_url, organization=self.organization) def try_run(self, audio: AudioArtifact, prompts: Optional[list[str]] = None) -> TextArtifact: additional_params = {} if prompts is not None: additional_params["prompt"] = ", ".join(prompts) transcription = self.client.audio.transcriptions.create( # Even though we're not actually providing a file to the client, the API still requires that we send a file # name. We set the file name to use the same format as the audio file so that the API can reject # it if the format is unsupported. model=self.model, file=(f"a.{audio.format}", io.BytesIO(audio.value)), response_format="json", **additional_params, ) return TextArtifact(value=transcription.text)
_client = field(default=None, kw_only=True, alias='client', metadata={'serializable': False})
class-attribute instance-attributeapi_key = field(default=None, kw_only=True, metadata={'serializable': False})
class-attribute instance-attributeapi_type = field(default=openai.api_type, kw_only=True)
class-attribute instance-attributeapi_version = field(default=openai.api_version, kw_only=True, metadata={'serializable': True})
class-attribute instance-attributebase_url = field(default=None, kw_only=True, metadata={'serializable': True})
class-attribute instance-attributeorganization = field(default=openai.organization, kw_only=True, metadata={'serializable': True})
class-attribute instance-attribute
client()
Source Code in griptape/drivers/audio_transcription/openai_audio_transcription_driver.py
@lazy_property() def client(self) -> openai.OpenAI: return openai.OpenAI(api_key=self.api_key, base_url=self.base_url, organization=self.organization)
try_run(audio, prompts=None)
Source Code in griptape/drivers/audio_transcription/openai_audio_transcription_driver.py
def try_run(self, audio: AudioArtifact, prompts: Optional[list[str]] = None) -> TextArtifact: additional_params = {} if prompts is not None: additional_params["prompt"] = ", ".join(prompts) transcription = self.client.audio.transcriptions.create( # Even though we're not actually providing a file to the client, the API still requires that we send a file # name. We set the file name to use the same format as the audio file so that the API can reject # it if the format is unsupported. model=self.model, file=(f"a.{audio.format}", io.BytesIO(audio.value)), response_format="json", **additional_params, ) return TextArtifact(value=transcription.text)
- On this page
- client()
- try_run(audio, prompts=None)
Could this page be better? Report a problem or suggest an addition!