-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
57 lines (52 loc) · 1.21 KB
/
client_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
package anthropic_test
import (
"io"
"testing"
"github.com/cubeofcube-dev/go-anthropic"
)
func TestCreateMessages(t *testing.T) {
cli := anthropic.NewClient()
model := anthropic.MODEL_CLAUDE_3_SONNET
content := anthropic.MessageContentText{Type: "text", Text: "Ping"}
max_tokens := 9
t.Run("Messages", func(t *testing.T) {
messages := anthropic.MessagesRequest{
Model: model,
Messages: []anthropic.Message{
{Role: "user", Content: []anthropic.MessageContent{&content}},
},
MaxTokens: max_tokens,
}
_, err := cli.CreateMessages(messages)
if err != nil {
t.Errorf("CreateMessages() error = %v", err)
return
}
})
t.Run("Messages Stream", func(t *testing.T) {
messages := anthropic.MessagesRequest{
Model: model,
Messages: []anthropic.Message{
{Role: "user", Content: []anthropic.MessageContent{&content}},
},
MaxTokens: max_tokens,
Stream: true,
}
stream, err := cli.CreateMessagesStream(messages)
if err != nil {
t.Errorf("CreateMessagesStream() error = %v", err)
return
}
defer stream.Close()
for {
_, err := stream.Recv()
if err != nil {
if err == io.EOF {
break
}
t.Errorf("Recv() error = %v", err)
return
}
}
})
}