-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathopenai_test.go
More file actions
47 lines (42 loc) · 1.18 KB
/
Copy pathopenai_test.go
File metadata and controls
47 lines (42 loc) · 1.18 KB
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
package openai
import (
"reflect"
"testing"
"github.com/henomis/lingoose/thread"
"github.com/sashabaranov/go-openai"
)
func TestWithResponseFormatJSONSchema(t *testing.T) {
tests := []struct {
name string
jsonSchema *ResponseFormatJSONSchema
want *ResponseFormatJSONSchema
}{
{
name: "should set JSON schema",
jsonSchema: &ResponseFormatJSONSchema{
Name: "FirstName",
Description: "First of your name",
Strict: true,
},
},
{
name: "should set nil JSON schema",
jsonSchema: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := New().
WithResponseFormatJSONSchema(tt.jsonSchema).
WithResponseFormat(openai.ChatCompletionResponseFormatTypeJSONSchema)
if !reflect.DeepEqual(tt.jsonSchema, o.responseFormatJSONSchema) {
t.Fatalf("New OpenAI WithResponseFormatJSONSchema doesn't set value correctly")
}
myThread := thread.New()
request := o.buildChatCompletionRequest(myThread)
if !reflect.DeepEqual(tt.jsonSchema, request.ResponseFormat.JSONSchema) {
t.Fatalf("New OpenAI WithResponseFormatJSONSchema doesn't generate correct chat request correctly")
}
})
}
}