Documentation
¶
Overview ¶
Package perception reads how each user turn was said by asking classifiers (alpha).
A Reader goes between the STT service and the user aggregator, and sets each final transcription's Perception from the answers of its sources: a classifier each, with the questions it is asked. Part of expressive conversation (alpha). These types are likely to change between releases.
Index ¶
Constants ¶
const ( // DefaultTextTimeout is how long a transcription waits for a text // classifier's answers by default, counted from when it arrives. DefaultTextTimeout = 500 * time.Millisecond // DefaultAudioTimeout is how long a transcription waits for the answers of // a classifier that hears by default, counted from when the user stops // speaking. DefaultAudioTimeout = 2 * time.Second )
Variables ¶
var ErrInvalidConfig = errors.New("perception: invalid configuration")
ErrInvalidConfig reports a reader or a source that cannot be built as given.
Functions ¶
This section is empty.
Types ¶
type BaseSource ¶
type BaseSource struct {
// contains filtered or unexported fields
}
BaseSource is a source whose questions are known when it is built.
hume, err := perception.NewSource(perception.SourceConfig{
Classifier: audioClassifier,
Questions: []perception.NamedQuestion{{
Name: "hesitation",
Question: perception.Question{
Question: classifier.YesNoQuestion{Instructions: "Does the speaker sound unsure?"},
Description: "The chance the user sounded unsure, from 0 to 1.",
},
}},
})
func NewSource ¶
func NewSource(cfg SourceConfig) (*BaseSource, error)
NewSource builds a source. It fails with ErrInvalidConfig when a name cannot be written in a reading.
func (*BaseSource) Classifier ¶
func (s *BaseSource) Classifier() classifier.Classifier
Classifier is the classifier that answers the questions.
func (*BaseSource) Names ¶
func (s *BaseSource) Names() []string
Names is the names of the signals the source reports.
func (*BaseSource) Questions ¶
func (s *BaseSource) Questions() ([]NamedQuestion, error)
Questions is the questions asked about each turn, by the name of the signal each reports.
func (*BaseSource) Timeout ¶
func (s *BaseSource) Timeout() time.Duration
Timeout is how long a transcription waits for the classifier's answers.
type Config ¶
type Config struct {
// Name is the processor's name. Empty is "PerceptionReader".
Name string
// Sources is the classifiers to ask, each with its questions and its
// timeout. At least one; a classifier goes in one source, and a signal's
// name in one.
Sources []Source
// ReplacePerception makes the reader's reading replace the one a
// transcription carries, such as the STT service's, instead of being added
// to it.
ReplacePerception bool
}
Config configures a Reader.
type NamedQuestion ¶
type NamedQuestion struct {
// Name is the signal's name, as written in a reading: no whitespace, "=",
// ",", "[", "]", "(" or ")".
Name string
Question Question
}
NamedQuestion is a question with the name of the signal it reports.
type Question ¶
type Question struct {
// Question is what the classifier is asked. A choice is reported as its
// likeliest options, a yes/no as its probability and a score as its
// position on the scale.
Question classifier.Question
// Description is a short line telling the LLM how to read the signal, such
// as its range, or empty.
Description string
// MaxLabels is the most options a choice reports, likeliest first. Zero is
// 2; it is at least 1.
MaxLabels int
}
Question is one signal a Reader reports, and the question it asks for it.
type Reader ¶
Reader reads how each user turn was said by asking classifiers.
It goes between the STT service and the user aggregator. Each final transcription gets the classifiers' answers as its Perception, one signal per question, named after it. Every classifier's reading is also broadcast in a frames.PerceptionFrame as soon as it is made, and the signals are declared at start in a frames.PerceptionMetadataFrame.
A text classifier reads each final transcription, with the bot's reply before it. A classifier that can hear, as its SupportsAudio says, hears the user's speech each time they stop: the latest, topped up with the end of what they said before it since the bot last spoke when that is shorter than the classifier answers best. It hears one clip at a time, and of the clips that come while it is busy, only the newest. The transcriptions of that speech wait for its answers, up to its source's timeout after the user stopped.
A reader asks each of its sources about the same turn, all at once, and their signals go in the turn's one reading, in the sources' order. A transcription goes on once every source has read it or run out of time. A source that is late or whose classifier fails leaves its signals out, and a transcription none of them read passes unread. A classifier that cannot be set up leaves the reader unusable.
A transcription that already carries a reading, such as the STT service's, gets the reader's added to it, and the reader declares the signals declared before it together with its own. With Config.ReplacePerception, the reader's reading replaces the one the transcription carries instead.
Turn expressive conversation on with pipeline.Params.EnableExpressiveConversation for the LLM to read the turns:
reader, err := perception.New(perception.Config{Sources: []perception.Source{frustration}})
p := pipeline.New(transport.Input(), stt, reader, userAggregator, llm, ...)
func New ¶
New builds a Reader. It fails with ErrInvalidConfig when there are no sources, or when two report the same signal or ask the same classifier.
func (*Reader) Cleanup ¶
Cleanup stops the reads and the release of the transcriptions held, and cleans the classifiers up.
func (*Reader) ProcessFrame ¶
ProcessFrame reads the user's turns, and keeps the bot's replies to read them against.
type Source ¶
type Source interface {
// Classifier is what answers the questions about each turn.
Classifier() classifier.Classifier
// Questions is the questions asked about each turn, in the order their
// signals are reported. It fails, with an error wrapping
// classifier.ErrClassifier, while they are not known yet.
Questions() ([]NamedQuestion, error)
// Names is the names of the signals the source reports, known before it is
// set up.
Names() []string
// Timeout is how long a transcription waits for the classifier's answers.
Timeout() time.Duration
}
Source is one classifier a Reader asks, and the questions it is asked.
A reader with several sources asks each one about the same turn and writes their answers in one reading, so a signal's name belongs to one source. The classifier says how its source reads: a text classifier reads each final transcription, and one that can hear, as its SupportsAudio says, hears the user's audio.
NewSource builds a source whose questions are known up front. A classifier whose questions are not known until it is set up gets a source of its own that embeds a BaseSource and overrides Questions, and Names to name its signals before then.
type SourceConfig ¶
type SourceConfig struct {
// Classifier is what answers the questions about each turn. Required.
Classifier classifier.Classifier `validate:"required"`
// Questions is the questions, each with the name of the signal it reports.
Questions []NamedQuestion
// Timeout is how long a transcription waits for the classifier's answers.
// Nil is DefaultTextTimeout for a text classifier, counted from when the
// transcription arrives, and DefaultAudioTimeout for one that hears,
// counted from when the user stops speaking.
Timeout *time.Duration
}
SourceConfig configures a BaseSource.