forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fine_tuning_job_test.go
90 lines (74 loc) · 2.4 KB
/
fine_tuning_job_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
package openai_test
import (
"context"
. "github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test/checks"
"encoding/json"
"fmt"
"net/http"
"testing"
)
const testFineTuninigJobID = "fine-tuning-job-id"
// TestFineTuningJob Tests the fine tuning job endpoint of the API using the mocked server.
func TestFineTuningJob(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler(
"/v1/fine_tuning/jobs",
func(w http.ResponseWriter, r *http.Request) {
var resBytes []byte
resBytes, _ = json.Marshal(FineTuningJob{})
fmt.Fprintln(w, string(resBytes))
},
)
server.RegisterHandler(
"/fine_tuning/jobs/"+testFineTuninigJobID+"/cancel",
func(w http.ResponseWriter, r *http.Request) {
resBytes, _ := json.Marshal(FineTuningJob{})
fmt.Fprintln(w, string(resBytes))
},
)
server.RegisterHandler(
"/v1/fine_tuning/jobs/"+testFineTuninigJobID,
func(w http.ResponseWriter, r *http.Request) {
var resBytes []byte
resBytes, _ = json.Marshal(FineTuningJob{})
fmt.Fprintln(w, string(resBytes))
},
)
server.RegisterHandler(
"/v1/fine_tuning/jobs/"+testFineTuninigJobID+"/events",
func(w http.ResponseWriter, r *http.Request) {
resBytes, _ := json.Marshal(FineTuningJobEventList{})
fmt.Fprintln(w, string(resBytes))
},
)
ctx := context.Background()
_, err := client.CreateFineTuningJob(ctx, FineTuningJobRequest{})
checks.NoError(t, err, "CreateFineTuningJob error")
_, err = client.CancelFineTuningJob(ctx, testFineTuninigJobID)
checks.NoError(t, err, "CancelFineTuningJob error")
_, err = client.RetrieveFineTuningJob(ctx, testFineTuninigJobID)
checks.NoError(t, err, "RetrieveFineTuningJob error")
_, err = client.ListFineTuningJobEvents(ctx, testFineTuninigJobID)
checks.NoError(t, err, "ListFineTuningJobEvents error")
_, err = client.ListFineTuningJobEvents(
ctx,
testFineTuninigJobID,
ListFineTuningJobEventsWithAfter("last-event-id"),
)
checks.NoError(t, err, "ListFineTuningJobEvents error")
_, err = client.ListFineTuningJobEvents(
ctx,
testFineTuninigJobID,
ListFineTuningJobEventsWithLimit(10),
)
checks.NoError(t, err, "ListFineTuningJobEvents error")
_, err = client.ListFineTuningJobEvents(
ctx,
testFineTuninigJobID,
ListFineTuningJobEventsWithAfter("last-event-id"),
ListFineTuningJobEventsWithLimit(10),
)
checks.NoError(t, err, "ListFineTuningJobEvents error")
}