forked from yunionio/cloudpods
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm.go
More file actions
231 lines (182 loc) · 5.42 KB
/
Copy pathllm.go
File metadata and controls
231 lines (182 loc) · 5.42 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package llm
import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
api "yunion.io/x/onecloud/pkg/apis/llm"
"yunion.io/x/onecloud/pkg/cloudcommon/cmdline"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type LLMBaseListOptions struct {
options.BaseListOptions
Host string `help:"filter by host"`
LLMStatus []string `help:"filter by server status"`
NetworkType string `help:"filter by network type"`
NetworkId string `help:"filter by network id"`
ListenPort int `help:"filter by listen port"`
PublicIp string `help:"filter by public ip"`
VolumeId string `help:"filter by volume id"`
Unused *bool `help:"filter by unused"`
Used *bool `help:"filter by used"`
}
type LLMListOptions struct {
LLMBaseListOptions
LlmSku string `help:"filter by llm sku"`
LlmImage string `help:"filter by llm image"`
LLMTypes []string `help:"filter by llm types"`
}
func (o *LLMListOptions) Params() (jsonutils.JSONObject, error) {
params, err := options.ListStructToParams(o)
if err != nil {
return nil, err
}
if o.Used != nil {
params.Set("unused", jsonutils.JSONFalse)
}
return params, nil
}
type LLMShowOptions struct {
options.BaseShowOptions
}
func (o *LLMShowOptions) Params() (jsonutils.JSONObject, error) {
return options.StructToParams(o)
}
type LLMBaseCreateOptions struct {
options.BaseCreateOptions
AutoStart bool
ProjectId string
PreferHost string
Net []string `help:"Network descriptions"`
BandwidthMb int
Count int `default:"1" help:"batch create count" json:"-"`
}
type LLMCreateOptions struct {
LLMBaseCreateOptions
LLM_SKU_ID string `help:"llm sku id or name" json:"llm_sku_id"`
PreferredModel string `help:"vLLM preferred model dir name under models path (e.g. Qwen/Qwen2-7B)" json:"-"`
}
func (o *LLMCreateOptions) Params() (jsonutils.JSONObject, error) {
params := jsonutils.Marshal(o).(*jsonutils.JSONDict)
if len(o.Net) > 0 {
nets := make([]*computeapi.NetworkConfig, 0)
for i, n := range o.Net {
net, err := cmdline.ParseNetworkConfig(n, i)
if err != nil {
return nil, errors.Wrapf(err, "parse network config %s", n)
}
nets = append(nets, net)
}
params.Add(jsonutils.Marshal(nets), "nets")
}
if o.PreferredModel != "" {
spec := &api.LLMSpec{
Ollama: nil,
Vllm: &api.LLMSpecVllm{PreferredModel: o.PreferredModel},
Dify: nil,
}
params.Set("llm_spec", jsonutils.Marshal(spec))
}
return params, nil
}
func (o *LLMCreateOptions) GetCountParam() int {
return o.Count
}
type LLMUpdateOptions struct {
options.BaseIdOptions
PreferredModel string `help:"vLLM preferred model dir name under models path (e.g. Qwen/Qwen2-7B); takes effect after pod recreate" json:"-"`
}
func (o *LLMUpdateOptions) GetId() string {
return o.ID
}
func (o *LLMUpdateOptions) Params() (jsonutils.JSONObject, error) {
dict, err := options.StructToParams(o)
if err != nil {
return nil, err
}
if o.PreferredModel != "" {
spec := &api.LLMSpec{
Ollama: nil,
Vllm: &api.LLMSpecVllm{PreferredModel: o.PreferredModel},
Dify: nil,
}
dict.Set("llm_spec", jsonutils.Marshal(spec))
}
return dict, nil
}
type LLMDeleteOptions struct {
options.BaseIdOptions
}
func (o *LLMDeleteOptions) GetId() string {
return o.ID
}
func (o *LLMDeleteOptions) Params() (jsonutils.JSONObject, error) {
return options.StructToParams(o)
}
type LLMStartOptions struct {
options.BaseIdsOptions
}
func (o *LLMStartOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(o), nil
}
type LLMRestartOptions struct {
options.BaseIdsOptions
}
func (o *LLMRestartOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(o), nil
}
type LLMStopOptions struct {
options.BaseIdsOptions
}
func (o *LLMStopOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(o), nil
}
type LLMIdOptions struct {
ID string `help:"llm id" json:"-"`
}
func (opts *LLMIdOptions) GetId() string {
return opts.ID
}
func (opts *LLMIdOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}
type LLMAvailableNetworkOptions struct {
NetworkType string `help:"network server_type filter, e.g. guest|hostlocal"`
VpcId string `help:"vpc id filter"`
}
func (opts *LLMAvailableNetworkOptions) GetId() string {
return ""
}
func (opts *LLMAvailableNetworkOptions) Params() (jsonutils.JSONObject, error) {
return options.StructToParams(opts)
}
type LLMSaveInstantModelOptions struct {
LLMIdOptions
MODEL_ID string `help:"llm model id, e.g. 500a1f067a9f"`
Name string `help:"instant app name, e.g. qwen3:8b"`
AutoRestart bool
}
func (opts *LLMSaveInstantModelOptions) Params() (jsonutils.JSONObject, error) {
input := api.LLMSaveInstantModelInput{
ModelId: opts.MODEL_ID,
ModelFullName: opts.Name,
// AutoRestart: opts.AutoRestart,
}
return jsonutils.Marshal(input), nil
}
type LLMQuickModelsOptions struct {
LLMIdOptions
MODEL []string `help:"model id of instant model, e.g. qwen3:0.6b-251202 or 7f72b5a1-4049-43db-8e91-8dee736ae1ac"`
Method string `help:"install or uninstall" choices:"install|uninstall"`
}
func (opts *LLMQuickModelsOptions) Params() (jsonutils.JSONObject, error) {
params := api.LLMPerformQuickModelsInput{}
for _, mdl := range opts.MODEL {
params.Models = append(params.Models, api.ModelInfo{
Id: mdl,
})
}
if len(opts.Method) > 0 {
params.Method = api.TQuickModelMethod(opts.Method)
}
return jsonutils.Marshal(params), nil
}