Skip to content

Commit dca5253

Browse files
committed
brain: add method for new thinking approach
For #94.
1 parent aab95b8 commit dca5253

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

brain/brain.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package brain
22

33
import (
44
"context"
5+
"iter"
56

67
"github.com/zephyrtronium/robot/message"
78
"github.com/zephyrtronium/robot/userhash"
@@ -17,11 +18,15 @@ type Interface interface {
1718
// a different tuple has the empty string as its suffix to denote the end
1819
// of the message. The positions of each in the argument are not guaranteed.
1920
//
20-
// Each tuple's prefix has entropy reduction transformations applied.
21-
//
2221
// Tuples in the argument may share storage for prefixes.
2322
Learn(ctx context.Context, tag string, msg *Message, tuples []Tuple) error
2423

24+
// Think iterates all suffixes matching a prefix.
25+
//
26+
// Yielded closures replace id and suffix with successive messages' contents.
27+
// The iterating loop may not call the yielded closure on every iteration.
28+
Think(ctx context.Context, tag string, prefix []string) iter.Seq[func(id, suf *[]byte) error]
29+
2530
// Speak generates a full message and appends it to w.
2631
//
2732
// The prompt is in reverse order and has entropy reduction applied.

brain/braintest/braintest_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package braintest_test
22

33
import (
44
"context"
5+
"iter"
56
"math/rand/v2"
67
"slices"
78
"strings"
@@ -76,6 +77,11 @@ func (m *membrain) Recall(ctx context.Context, tag string, page string, out []br
7677
panic("unimplemented")
7778
}
7879

80+
// Think implements brain.Interface.
81+
func (m *membrain) Think(ctx context.Context, tag string, prefix []string) iter.Seq[func(id *[]byte, suf *[]byte) error] {
82+
panic("unimplemented")
83+
}
84+
7985
func (m *membrain) Speak(ctx context.Context, tag string, prompt []string, w *brain.Builder) error {
8086
m.mu.Lock()
8187
defer m.mu.Unlock()

brain/kvbrain/speak.go

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"iter"
78
"math/rand/v2"
89

910
"github.com/dgraph-io/badger/v4"
@@ -15,6 +16,10 @@ import (
1516

1617
var prependerPool tpool.Pool[deque.Deque[string]]
1718

19+
func (m *Brain) Think(ctx context.Context, tag string, prefix []string) iter.Seq[func(id *[]byte, suf *[]byte) error] {
20+
panic("unimplemented")
21+
}
22+
1823
// Speak generates a full message and appends it to w.
1924
// The prompt is in reverse order and has entropy reduction applied.
2025
func (br *Brain) Speak(ctx context.Context, tag string, prompt []string, w *brain.Builder) error {

brain/learn_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package brain_test
22

33
import (
44
"context"
5+
"iter"
56
"slices"
67
"strconv"
78
"testing"
@@ -32,6 +33,11 @@ func (t *testLearner) Speak(ctx context.Context, tag string, prompt []string, w
3233
panic("unimplemented")
3334
}
3435

36+
// Think implements brain.Interface.
37+
func (t *testLearner) Think(ctx context.Context, tag string, prefix []string) iter.Seq[func(id *[]byte, suf *[]byte) error] {
38+
panic("unimplemented")
39+
}
40+
3541
func (t *testLearner) Recall(ctx context.Context, tag string, page string, out []brain.Message) (n int, next string, err error) {
3642
var k int
3743
if page != "" {

brain/speak_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package brain_test
22

33
import (
44
"context"
5+
"iter"
56
"testing"
67

78
"github.com/google/go-cmp/cmp"
@@ -18,6 +19,10 @@ type testSpeaker struct {
1819
append []byte
1920
}
2021

22+
func (t *testSpeaker) Think(ctx context.Context, tag string, prefix []string) iter.Seq[func(id *[]byte, suf *[]byte) error] {
23+
panic("unimplemented")
24+
}
25+
2126
func (t *testSpeaker) Speak(ctx context.Context, tag string, prompt []string, w *brain.Builder) error {
2227
t.prompt = prompt
2328
w.Append(t.id, t.append)

brain/sqlbrain/speak.go

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sqlbrain
33
import (
44
"context"
55
"fmt"
6+
"iter"
67
"math/rand/v2"
78

89
"zombiezen.com/go/sqlite"
@@ -14,6 +15,10 @@ import (
1415

1516
var prependerPool tpool.Pool[deque.Deque[string]]
1617

18+
func (br *Brain) Think(ctx context.Context, tag string, prefix []string) iter.Seq[func(id *[]byte, suf *[]byte) error] {
19+
panic("unimplemented")
20+
}
21+
1722
// Speak generates a full message and appends it to w.
1823
// The prompt is in reverse order and has entropy reduction applied.
1924
func (br *Brain) Speak(ctx context.Context, tag string, prompt []string, w *brain.Builder) error {

0 commit comments

Comments
 (0)