-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathconfig_test.go
102 lines (88 loc) · 2.47 KB
/
config_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package openai_test
import (
"testing"
"github.com/sashabaranov/go-openai"
)
func TestGetAzureDeploymentByModel(t *testing.T) {
cases := []struct {
Model string
AzureModelMapperFunc func(model string) string
Expect string
}{
{
Model: "gpt-3.5-turbo",
Expect: "gpt-35-turbo",
},
{
Model: "gpt-3.5-turbo-0301",
Expect: "gpt-35-turbo-0301",
},
{
Model: "text-embedding-ada-002",
Expect: "text-embedding-ada-002",
},
{
Model: "",
Expect: "",
},
{
Model: "models",
Expect: "models",
},
{
Model: "gpt-3.5-turbo",
Expect: "my-gpt35",
AzureModelMapperFunc: func(model string) string {
modelmapper := map[string]string{
"gpt-3.5-turbo": "my-gpt35",
}
if val, ok := modelmapper[model]; ok {
return val
}
return model
},
},
}
for _, c := range cases {
t.Run(c.Model, func(t *testing.T) {
conf := openai.DefaultAzureConfig("", "https://test.openai.azure.com/")
if c.AzureModelMapperFunc != nil {
conf.AzureModelMapperFunc = c.AzureModelMapperFunc
}
actual := conf.GetAzureDeploymentByModel(c.Model)
if actual != c.Expect {
t.Errorf("Expected %s, got %s", c.Expect, actual)
}
})
}
}
func TestDefaultAnthropicConfig(t *testing.T) {
apiKey := "test-key"
baseURL := "https://api.anthropic.com/v1"
config := openai.DefaultAnthropicConfig(apiKey, baseURL)
if config.APIType != openai.APITypeAnthropic {
t.Errorf("Expected APIType to be %v, got %v", openai.APITypeAnthropic, config.APIType)
}
if config.APIVersion != openai.AnthropicAPIVersion {
t.Errorf("Expected APIVersion to be 2023-06-01, got %v", config.APIVersion)
}
if config.BaseURL != baseURL {
t.Errorf("Expected BaseURL to be %v, got %v", baseURL, config.BaseURL)
}
if config.EmptyMessagesLimit != 300 {
t.Errorf("Expected EmptyMessagesLimit to be 300, got %v", config.EmptyMessagesLimit)
}
}
func TestDefaultAnthropicConfigWithEmptyValues(t *testing.T) {
config := openai.DefaultAnthropicConfig("", "")
if config.APIType != openai.APITypeAnthropic {
t.Errorf("Expected APIType to be %v, got %v", openai.APITypeAnthropic, config.APIType)
}
if config.APIVersion != openai.AnthropicAPIVersion {
t.Errorf("Expected APIVersion to be %s, got %v", openai.AnthropicAPIVersion, config.APIVersion)
}
expectedBaseURL := "https://api.anthropic.com/v1"
if config.BaseURL != expectedBaseURL {
t.Errorf("Expected BaseURL to be %v, got %v", expectedBaseURL, config.BaseURL)
}
}