Movatterモバイル変換


[0]ホーム

URL:


Skip to content

OpenAIVoiceModelProvider

OpenAIVoiceModelProvider

Bases:VoiceModelProvider

A voice model provider that uses OpenAI models.

Source code insrc/agents/voice/models/openai_model_provider.py
classOpenAIVoiceModelProvider(VoiceModelProvider):"""A voice model provider that uses OpenAI models."""def__init__(self,*,api_key:str|None=None,base_url:str|None=None,openai_client:AsyncOpenAI|None=None,organization:str|None=None,project:str|None=None,)->None:"""Create a new OpenAI voice model provider.        Args:            api_key: The API key to use for the OpenAI client. If not provided, we will use the                default API key.            base_url: The base URL to use for the OpenAI client. If not provided, we will use the                default base URL.            openai_client: An optional OpenAI client to use. If not provided, we will create a new                OpenAI client using the api_key and base_url.            organization: The organization to use for the OpenAI client.            project: The project to use for the OpenAI client.        """ifopenai_clientisnotNone:assertapi_keyisNoneandbase_urlisNone,("Don't provide api_key or base_url if you provide openai_client")self._client:AsyncOpenAI|None=openai_clientelse:self._client=Noneself._stored_api_key=api_keyself._stored_base_url=base_urlself._stored_organization=organizationself._stored_project=project# We lazy load the client in case you never actually use OpenAIProvider(). Otherwise# AsyncOpenAI() raises an error if you don't have an API key set.def_get_client(self)->AsyncOpenAI:ifself._clientisNone:self._client=_openai_shared.get_default_openai_client()orAsyncOpenAI(api_key=self._stored_api_keyor_openai_shared.get_default_openai_key(),base_url=self._stored_base_url,organization=self._stored_organization,project=self._stored_project,http_client=shared_http_client(),)returnself._clientdefget_stt_model(self,model_name:str|None)->STTModel:"""Get a speech-to-text model by name.        Args:            model_name: The name of the model to get.        Returns:            The speech-to-text model.        """returnOpenAISTTModel(model_nameorDEFAULT_STT_MODEL,self._get_client())defget_tts_model(self,model_name:str|None)->TTSModel:"""Get a text-to-speech model by name.        Args:            model_name: The name of the model to get.        Returns:            The text-to-speech model.        """returnOpenAITTSModel(model_nameorDEFAULT_TTS_MODEL,self._get_client())

__init__

__init__(*,api_key:str|None=None,base_url:str|None=None,openai_client:AsyncOpenAI|None=None,organization:str|None=None,project:str|None=None,)->None

Create a new OpenAI voice model provider.

Parameters:

NameTypeDescriptionDefault
api_keystr | None

The API key to use for the OpenAI client. If not provided, we will use thedefault API key.

None
base_urlstr | None

The base URL to use for the OpenAI client. If not provided, we will use thedefault base URL.

None
openai_clientAsyncOpenAI | None

An optional OpenAI client to use. If not provided, we will create a newOpenAI client using the api_key and base_url.

None
organizationstr | None

The organization to use for the OpenAI client.

None
projectstr | None

The project to use for the OpenAI client.

None
Source code insrc/agents/voice/models/openai_model_provider.py
def__init__(self,*,api_key:str|None=None,base_url:str|None=None,openai_client:AsyncOpenAI|None=None,organization:str|None=None,project:str|None=None,)->None:"""Create a new OpenAI voice model provider.    Args:        api_key: The API key to use for the OpenAI client. If not provided, we will use the            default API key.        base_url: The base URL to use for the OpenAI client. If not provided, we will use the            default base URL.        openai_client: An optional OpenAI client to use. If not provided, we will create a new            OpenAI client using the api_key and base_url.        organization: The organization to use for the OpenAI client.        project: The project to use for the OpenAI client.    """ifopenai_clientisnotNone:assertapi_keyisNoneandbase_urlisNone,("Don't provide api_key or base_url if you provide openai_client")self._client:AsyncOpenAI|None=openai_clientelse:self._client=Noneself._stored_api_key=api_keyself._stored_base_url=base_urlself._stored_organization=organizationself._stored_project=project

get_stt_model

get_stt_model(model_name:str|None)->STTModel

Get a speech-to-text model by name.

Parameters:

NameTypeDescriptionDefault
model_namestr | None

The name of the model to get.

required

Returns:

TypeDescription
STTModel

The speech-to-text model.

Source code insrc/agents/voice/models/openai_model_provider.py
defget_stt_model(self,model_name:str|None)->STTModel:"""Get a speech-to-text model by name.    Args:        model_name: The name of the model to get.    Returns:        The speech-to-text model.    """returnOpenAISTTModel(model_nameorDEFAULT_STT_MODEL,self._get_client())

get_tts_model

get_tts_model(model_name:str|None)->TTSModel

Get a text-to-speech model by name.

Parameters:

NameTypeDescriptionDefault
model_namestr | None

The name of the model to get.

required

Returns:

TypeDescription
TTSModel

The text-to-speech model.

Source code insrc/agents/voice/models/openai_model_provider.py
defget_tts_model(self,model_name:str|None)->TTSModel:"""Get a text-to-speech model by name.    Args:        model_name: The name of the model to get.    Returns:        The text-to-speech model.    """returnOpenAITTSModel(model_nameorDEFAULT_TTS_MODEL,self._get_client())

[8]ページ先頭

©2009-2025 Movatter.jp