Skip to content

Commit f2b5569

Browse files
committed
test: add integration test for function call (#429)(#432)
1 parent df10cf3 commit f2b5569

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

api_integration_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"os"
1010
"testing"
1111

12+
"github.com/sashabaranov/go-openai"
1213
. "github.com/sashabaranov/go-openai"
1314
"github.com/sashabaranov/go-openai/internal/test/checks"
15+
"github.com/sashabaranov/go-openai/jsonschema"
1416
)
1517

1618
func TestAPI(t *testing.T) {
@@ -100,6 +102,37 @@ func TestAPI(t *testing.T) {
100102
if counter == 0 {
101103
t.Error("Stream did not return any responses")
102104
}
105+
106+
_, err = c.CreateChatCompletion(
107+
context.Background(),
108+
openai.ChatCompletionRequest{
109+
Model: openai.GPT3Dot5Turbo,
110+
Messages: []openai.ChatCompletionMessage{
111+
{
112+
Role: openai.ChatMessageRoleUser,
113+
Content: "What is the weather like in Boston?",
114+
},
115+
},
116+
Functions: []openai.FunctionDefinition{{
117+
Name: "get_current_weather",
118+
Parameters: jsonschema.Definition{
119+
Type: jsonschema.Object,
120+
Properties: map[string]jsonschema.Definition{
121+
"location": {
122+
Type: jsonschema.String,
123+
Description: "The city and state, e.g. San Francisco, CA",
124+
},
125+
"unit": {
126+
Type: jsonschema.String,
127+
Enum: []string{"celsius", "fahrenheit"},
128+
},
129+
},
130+
Required: []string{"location"},
131+
},
132+
}},
133+
},
134+
)
135+
checks.NoError(t, err, "CreateChatCompletion (with functions) returned error")
103136
}
104137

105138
func TestAPIError(t *testing.T) {

0 commit comments

Comments
 (0)