banterbot.extensions package
banterbot.extensions.interface module
banterbot.extensions.option_selector module
banterbot.extensions.prosody_selector module
- class banterbot.extensions.prosody_selector.ProsodySelector(manager: OpenAIModel, voice: AzureNeuralVoiceProfile)[source]
Bases:
object
The ProsodySelector class is responsible for managing prosody selection/extraction for specified instances of the AzureNeuralVoice class. It uses the OpenAI ChatCompletion API to generate prosody settings for a list of sentences.
- _model
The OpenAI model to be used for generating responses.
- Type:
- _openai_manager
An instance of the OpenAIService class.
- Type:
OpenAIService
- _voice
An instance of the AzureNeuralVoice class.
- Type:
AzureNeuralVoice
- _valid
A flag indicating whether the voice styles are not None.
- Type:
bool
- _token_counts
A dictionary to cache the maximum number of tokens for a given number of rows.
- Type:
dict
- _output_patterns
A dictionary to cache the regex patterns matching the expected ChatCompletion output.
- Type:
dict
- _system
A list of system and user messages to be used as a prompt for the ChatCompletion API.
- Type:
list[Message]
- _line_pattern
A regex pattern that matches one line of expected output for the current model.
- Type:
str
- select(sentences: list[str], context: str | None = None, system: str | None = None) str [source]
Extracts prosody settings for a list of sentences by asking the OpenAI ChatCompletion API to pick a set of options. The prompt is set up to force the model to return an exact number of tokens with dummy text preceding it in order to yield consistent results efficiently.
- Parameters:
sentences (list[str]) – The list of sentences to be processed.
context (Optional[str]) – Useful prior conversational context originating from the same response.
system (Optional[str]) – A system prompt to assist the ChatCompletion in picking reactions.
- Returns:
The randomly selected option.
- Return type:
str