Files
openai/fine_tuning_job_test.go
zeekayandHanzo Dev 88762272c3 refactor(module): declare own import path github.com/hanzoai/go-openai
The fork kept the upstream module path (module github.com/sashabaranov/
go-openai), so every consumer could only reach it through a
"replace github.com/sashabaranov/go-openai => github.com/hanzoai/go-openai"
directive — and Go replace directives do NOT propagate to consumers, so each
downstream repo had to copy the same replace or fail to compile against
fork-only fields (e.g. ReasoningContent). That is the opposite of one-and-
only-one-way.

Declare the fork's OWN module path so it can be required directly and inherited
transitively. Package name stays 'openai' (import identifier unchanged); only
the module path + internal self-imports (/internal, /jsonschema) are renamed.
Upstream issue-URL comments are left intact as attribution. Builds + vets clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-17 21:55:51 -07:00

107 lines
3.0 KiB
Go

package openai_test
import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/hanzoai/go-openai"
"github.com/hanzoai/go-openai/internal/test/checks"
)
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, _ *http.Request) {
resBytes, _ := json.Marshal(openai.FineTuningJob{
Object: "fine_tuning.job",
ID: testFineTuninigJobID,
Model: "davinci-002",
CreatedAt: 1692661014,
FinishedAt: 1692661190,
FineTunedModel: "ft:davinci-002:my-org:custom_suffix:7q8mpxmy",
OrganizationID: "org-123",
ResultFiles: []string{"file-abc123"},
Status: "succeeded",
ValidationFile: "",
TrainingFile: "file-abc123",
Hyperparameters: openai.Hyperparameters{
Epochs: "auto",
LearningRateMultiplier: "auto",
BatchSize: "auto",
},
TrainedTokens: 5768,
})
fmt.Fprintln(w, string(resBytes))
},
)
server.RegisterHandler(
"/v1/fine_tuning/jobs/"+testFineTuninigJobID+"/cancel",
func(w http.ResponseWriter, _ *http.Request) {
resBytes, _ := json.Marshal(openai.FineTuningJob{})
fmt.Fprintln(w, string(resBytes))
},
)
server.RegisterHandler(
"/v1/fine_tuning/jobs/"+testFineTuninigJobID,
func(w http.ResponseWriter, _ *http.Request) {
var resBytes []byte
resBytes, _ = json.Marshal(openai.FineTuningJob{})
fmt.Fprintln(w, string(resBytes))
},
)
server.RegisterHandler(
"/v1/fine_tuning/jobs/"+testFineTuninigJobID+"/events",
func(w http.ResponseWriter, _ *http.Request) {
resBytes, _ := json.Marshal(openai.FineTuningJobEventList{})
fmt.Fprintln(w, string(resBytes))
},
)
ctx := context.Background()
_, err := client.CreateFineTuningJob(ctx, openai.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,
openai.ListFineTuningJobEventsWithAfter("last-event-id"),
)
checks.NoError(t, err, "ListFineTuningJobEvents error")
_, err = client.ListFineTuningJobEvents(
ctx,
testFineTuninigJobID,
openai.ListFineTuningJobEventsWithLimit(10),
)
checks.NoError(t, err, "ListFineTuningJobEvents error")
_, err = client.ListFineTuningJobEvents(
ctx,
testFineTuninigJobID,
openai.ListFineTuningJobEventsWithAfter("last-event-id"),
openai.ListFineTuningJobEventsWithLimit(10),
)
checks.NoError(t, err, "ListFineTuningJobEvents error")
}