forked from tmc/langchaingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_reduce_test.go
58 lines (50 loc) · 1.3 KB
/
map_reduce_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package chains
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/tmc/langchaingo/prompts"
"github.com/tmc/langchaingo/schema"
)
func TestMapReduceInputVariables(t *testing.T) {
t.Parallel()
c := MapReduceDocuments{
LLMChain: NewLLMChain(
&testLanguageModel{},
prompts.NewPromptTemplate("{{.text}} {{.foo}}", []string{"text", "foo"}),
),
ReduceChain: NewLLMChain(
&testLanguageModel{},
prompts.NewPromptTemplate("{{.texts}} {{.baz}}", []string{"texts", "baz"}),
),
ReduceDocumentVariableName: "texts",
LLMChainInputVariableName: "text",
InputKey: "input",
}
inputKeys := c.GetInputKeys()
expectedLength := 3
require.Equal(t, expectedLength, len(inputKeys))
}
func TestMapReduce(t *testing.T) {
t.Parallel()
c := NewMapReduceDocuments(
NewLLMChain(
&testLanguageModel{},
prompts.NewPromptTemplate("{{.context}}", []string{"context"}),
),
NewStuffDocuments(
NewLLMChain(
&testLanguageModel{},
prompts.NewPromptTemplate("{{.context}}", []string{"context"}),
),
),
)
result, err := Run(context.Background(), c, []schema.Document{
{PageContent: "foo"},
{PageContent: "boo"},
{PageContent: "zoo"},
{PageContent: "doo"},
})
require.NoError(t, err)
require.Equal(t, "foo\n\nboo\n\nzoo\n\ndoo", result)
}