-
-
Notifications
You must be signed in to change notification settings - Fork 643
/
conversational_test.go
42 lines (35 loc) · 1.08 KB
/
conversational_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
package agents
import (
"context"
"os"
"regexp"
"testing"
"github.com/stretchr/testify/require"
"github.com/tmc/langchaingo/chains"
"github.com/tmc/langchaingo/llms/openai"
"github.com/tmc/langchaingo/memory"
"github.com/tmc/langchaingo/tools"
)
func TestConversationalWithMemory(t *testing.T) {
t.Parallel()
if openaiKey := os.Getenv("OPENAI_API_KEY"); openaiKey == "" {
t.Skip("OPENAI_API_KEY not set")
}
llm, err := openai.New(openai.WithModel("gpt-4"))
require.NoError(t, err)
executor, err := Initialize(
llm,
[]tools.Tool{tools.Calculator{}},
ConversationalReactDescription,
WithMemory(memory.NewConversationBuffer()),
)
require.NoError(t, err)
_, err = chains.Run(context.Background(), executor, "Hi! my name is Bob and the year I was born is 1987")
require.NoError(t, err)
res, err := chains.Run(context.Background(), executor, "What is the year I was born times 34")
require.NoError(t, err)
expectedRe := "67,?558"
if !regexp.MustCompile(expectedRe).MatchString(res) {
t.Errorf("result does not contain the crrect answer '67558', got: %s", res)
}
}