Documentation
¶
Overview ¶
Package reader reads how each user turn was meant, from its words, with the tone reader model (alpha).
The model (https://huggingface.co/pipecat-ai/tone-models) reads one turn of text, with the turn before it, and returns the speaker's emotion, whether the turn is sarcastic, the move it makes and whether it is only a listening sound, each with a calibrated confidence. It runs on the CPU in a few milliseconds, through the ONNX runtime.
Part of expressive conversation (alpha). These types are likely to change between releases.
Index ¶
Constants ¶
const ( // Repo is the Hugging Face repository the tone models are released in. Repo = "pipecat-ai/tone-models" // Revision is the reader's release the reader downloads by default. Revision = "reader-rc2" )
Variables ¶
var ErrPrecision = errors.New("reader: unknown precision")
ErrPrecision is returned for a precision the model is not released in.
Functions ¶
This section is empty.
Types ¶
type BackchannelTag ¶
BackchannelTag is whether the turn is only a listening sound.
type Config ¶
type Config struct {
// Name is the processor's name. Empty is "ToneReader".
Name string
// Revision is the model's release on Hugging Face, such as "reader-rc2".
// Empty is Revision.
Revision string
// ModelDir is a folder to load the model from instead of downloading one,
// laid out as a release's "reader" folder. Revision is then unused.
ModelDir string
// Precision is the weights to load. Empty is FP16.
Precision Precision `validate:"omitempty,oneof=fp16 fp32"`
// Threads is the CPU threads for one read. Zero is 4.
Threads int `validate:"min=0"`
// CacheDir is where a downloaded model is kept. Empty is Hugging Face's own
// cache, ~/.cache/huggingface/hub.
CacheDir string
}
Config configures a Reader. The zero value downloads the default release at FP16 and reads with four threads.
type EmotionTag ¶
type EmotionTag struct {
Label string
Intensity string
// Confidence is the likeliest label's probability.
Confidence float64
// Probabilities is every emotion's probability, in the model's order.
Probabilities []Probability
}
EmotionTag is the feeling the turn's words show.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the reader's model, on the CPU.
func DownloadModel ¶
func DownloadModel( ctx context.Context, revision string, precision Precision, threads int, cacheDir string, ) (*Model, error)
DownloadModel loads the model's release from Hugging Face, downloading its files into cacheDir the first time. An empty cacheDir is Hugging Face's own cache.
func LoadModel ¶
LoadModel loads the model from a folder holding its config.json, tokenizer.json and ONNX file, using threads CPU threads for one read.
type MoveTag ¶
type MoveTag struct {
Label string
Confidence float64
Probabilities []Probability
}
MoveTag is what the turn does, such as asking or answering.
type Probability ¶
Probability is one label's probability.
type Reader ¶
Reader reads how each user turn was meant.
It goes between the STT service and the user aggregator. Each final transcription is read, with the bot's reply before it, and the reading is set as its Perception: the turn's "emotion", its two likeliest labels with their confidences, and its "sarcasm", the chance it is sarcastic. The transcription waits for the read, a few milliseconds.
The model loads while the pipeline is set up, once a process, and every reader shares it. The first load downloads it from Hugging Face, which holds the pipeline's start, so download it ahead, such as when building the image. A model that cannot be loaded is reported as an error that leaves the reader unusable, and transcriptions pass through unread.
Turn expressive conversation on with pipeline.Params.EnableExpressiveConversation for the LLM to read the turns:
pipeline.New(transport.Input(), stt, toneReader, userAggregator, llm, ...)
func (*Reader) ProcessFrame ¶
ProcessFrame reads final transcriptions, and keeps the bot's replies to read them against.
type SarcasmTag ¶
type SarcasmTag struct {
Sarcastic bool
// Probability is the calibrated chance it is sarcastic.
Probability float64
}
SarcasmTag is whether the turn is sarcastic.
type Tags ¶
type Tags struct {
Emotion EmotionTag
Move MoveTag
Sarcasm SarcasmTag
Backchannel BackchannelTag
}
Tags is what the model reads of one turn.