-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
brain: remove separate Learner and Speaker interfaces
For #94.
- Loading branch information
1 parent
0d04fc7
commit aab95b8
Showing
19 changed files
with
94 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
package brain | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zephyrtronium/robot/message" | ||
"github.com/zephyrtronium/robot/userhash" | ||
) | ||
|
||
// Brain is a combined [Learner] and [Speaker]. | ||
type Brain interface { | ||
Learner | ||
Speaker | ||
// Interface is a store of learned messages which can reproduce them by parts. | ||
// | ||
// It must be safe to call all methods of a brain concurrently with each other. | ||
type Interface interface { | ||
// Learn records a set of tuples. | ||
// | ||
// One tuple has an empty prefix to denote the start of the message, and | ||
// a different tuple has the empty string as its suffix to denote the end | ||
// of the message. The positions of each in the argument are not guaranteed. | ||
// | ||
// Each tuple's prefix has entropy reduction transformations applied. | ||
// | ||
// Tuples in the argument may share storage for prefixes. | ||
Learn(ctx context.Context, tag string, msg *Message, tuples []Tuple) error | ||
|
||
// Speak generates a full message and appends it to w. | ||
// | ||
// The prompt is in reverse order and has entropy reduction applied. | ||
Speak(ctx context.Context, tag string, prompt []string, w *Builder) error | ||
|
||
// Forget forgets everything learned from a single given message. | ||
// If nothing has been learned from the message, it must prevent anything | ||
// from being learned from a message with that ID. | ||
Forget(ctx context.Context, tag, id string) error | ||
|
||
// Recall reads out messages the brain knows. | ||
// At minimum, the message ID and text of each message must be retrieved; | ||
// other fields may be filled if they are available. | ||
// | ||
// Repeated calls using the pagination token returned from the previous | ||
// must yield every message that the brain had recorded at the time of the | ||
// first call exactly once. Messages learned after the first call of an | ||
// enumeration are read at most once. | ||
// | ||
// The first call of an enumeration uses an empty pagination token as input. | ||
// If the returned pagination token is empty, it is interpreted as the end | ||
// of the enumeration. | ||
Recall(ctx context.Context, tag, page string, out []Message) (n int, next string, err error) | ||
} | ||
|
||
// Message is the message type used by a [Brain]. | ||
// Message is the message type used by a [Interface]. | ||
type Message = message.Received[userhash.Hash] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.