-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
142 lines (130 loc) · 3.79 KB
/
main.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"flag"
"fmt"
"os"
"github.com/rossheat/openai-tune/cancel"
"github.com/rossheat/openai-tune/create"
"github.com/rossheat/openai-tune/get"
"github.com/rossheat/openai-tune/list"
"github.com/rossheat/openai-tune/option"
"github.com/rossheat/openai-tune/upload"
"github.com/rossheat/openai-tune/utils"
)
func PrintUsage() {
fmt.Println("Usage:")
fmt.Println(" openai-tune upload -file <path-to-jsonl-file> Upload a JSONL file for fine-tuning")
fmt.Println(" openai-tune upload -list List all uploaded files")
fmt.Println(" openai-tune create -file-id <file-id> -model <model-name> Create a fine-tuning job with default settings")
fmt.Println(" openai-tune create -config <path-to-yaml> Create a fine-tuning job with custom settings")
fmt.Println(" openai-tune list [-limit <n>] [-after <job-id>] List fine-tuning jobs")
fmt.Println(" openai-tune get <job-id> Get information about a specific fine-tuning job")
fmt.Println(" openai-tune cancel <job-id> Cancel a fine-tuning job")
os.Exit(1)
}
func main() {
uploadCmd := flag.NewFlagSet("upload", flag.ExitOnError)
uploadFile := uploadCmd.String("file", "", "JSONL data file to upload")
uploadList := uploadCmd.Bool("list", false, "list all uploaded files with purpose 'fine-tune'")
createCmd := flag.NewFlagSet("create", flag.ExitOnError)
createFileID := createCmd.String("file-id", "", "File ID of JSONL data file uploaded to OpenAI")
createModel := createCmd.String("model", "gpt-4o-mini-2024-07-18", "Model to fine-tune (only used with -file-id)")
configFile := createCmd.String("config", "", "YAML file containing your custom fine-tune settings")
if len(os.Args) < 2 {
PrintUsage()
}
openAIAPIKey, err := utils.GetOpenAIAPIKeyFromEnv()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
switch os.Args[1] {
case "upload":
uploadCmd.Parse(os.Args[2:])
if (*uploadFile == "") == (!*uploadList) {
fmt.Println("please specify either -file or -list")
uploadCmd.PrintDefaults()
os.Exit(1)
}
options := option.Upload{
File: *uploadFile,
OpenAIAPIKey: openAIAPIKey,
}
if *uploadList {
err := upload.List(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
} else {
err := upload.Upload(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
case "create":
createCmd.Parse(os.Args[2:])
if (*createFileID == "") == (*configFile == "") {
fmt.Println("please specify either -file-id or -config")
createCmd.PrintDefaults()
os.Exit(1)
}
options := option.Create{
FileID: *createFileID,
Model: *createModel,
ConfigFile: *configFile,
OpenAIAPIKey: openAIAPIKey,
}
err := create.Create(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case "list":
listCmd := flag.NewFlagSet("list", flag.ExitOnError)
limit := listCmd.Int("limit", 0, "Number of fine-tuning jobs to retrieve")
after := listCmd.String("after", "", "Retrieve jobs after this job ID")
listCmd.Parse(os.Args[2:])
options := option.List{
OpenAIAPIKey: openAIAPIKey,
Limit: *limit,
After: *after,
}
err := list.List(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case "get":
if len(os.Args) != 3 {
fmt.Println("please provide a job ID")
os.Exit(1)
}
options := option.Job{
JobID: os.Args[2],
OpenAIAPIKey: openAIAPIKey,
}
err := get.Get(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case "cancel":
if len(os.Args) != 3 {
fmt.Println("please provide a job ID")
os.Exit(1)
}
options := option.Job{
JobID: os.Args[2],
OpenAIAPIKey: openAIAPIKey,
}
err := cancel.Cancel(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
default:
PrintUsage()
}
}