-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat_test.go
65 lines (62 loc) · 1.54 KB
/
chat_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
59
60
61
62
63
64
65
package groq_test
import (
"context"
"encoding/json"
"net/http"
"testing"
"github.com/conneroisu/groq-go"
"github.com/conneroisu/groq-go/pkg/models"
"github.com/conneroisu/groq-go/pkg/test"
"github.com/conneroisu/groq-go/pkg/tools"
"github.com/stretchr/testify/assert"
)
func TestChat(t *testing.T) {
ctx := context.Background()
a := assert.New(t)
ts := test.NewTestServer()
returnObj := groq.ChatCompletionResponse{
ID: "chatcmpl-123",
Object: "chat.completion.chunk",
Created: 1693721698,
Model: "llama3-groq-70b-8192-tool-use-preview",
Choices: []groq.ChatCompletionChoice{
{
Index: 0,
Message: groq.ChatCompletionMessage{
Role: groq.ChatMessageRoleAssistant,
Content: "Hello!",
},
},
},
}
ts.RegisterHandler("/v1/chat/completions", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
jsval, err := json.Marshal(returnObj)
a.NoError(err)
_, err = w.Write(jsval)
if err != nil {
t.Fatal(err)
}
})
testS := ts.GroqTestServer()
testS.Start()
client, err := groq.NewClient(
test.GetTestToken(),
groq.WithBaseURL(testS.URL+"/v1"),
)
a.NoError(err)
resp, err := client.CreateChatCompletion(ctx, groq.ChatCompletionRequest{
Model: models.ModelLlama3Groq70B8192ToolUsePreview,
Messages: []groq.ChatCompletionMessage{
{
Role: groq.ChatMessageRoleUser,
Content: "Hello!",
},
},
MaxTokens: 2000,
Tools: []tools.Tool{},
})
a.NoError(err)
a.NotEmpty(resp.Choices[0].Message.Content)
}