| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 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:"-"`
- VllmArg []string `help:"vLLM args in format key=value; use key= for flags without values" 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")
- }
- vllmSpec, err := newVLLMSpecFromArgs(o.PreferredModel, o.VllmArg)
- if err != nil {
- return nil, err
- }
- if vllmSpec != nil {
- spec := &api.LLMSpec{Ollama: nil, Vllm: vllmSpec, 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:"-"`
- VllmArg []string `help:"vLLM args in format key=value; use key= for flags without values" 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
- }
- vllmSpec, err := newVLLMSpecFromArgs(o.PreferredModel, o.VllmArg)
- if err != nil {
- return nil, err
- }
- if vllmSpec != nil {
- spec := &api.LLMSpec{Ollama: nil, Vllm: vllmSpec, 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 LLMProviderModelsOptions struct {
- URL string `help:"provider url, e.g. http://127.0.0.1:11434 or http://127.0.0.1:8000" json:"url"`
- ProviderType string `help:"provider type, use openai for OpenAI-compatible endpoints such as vllm" json:"provider_type" choices:"ollama|openai"`
- }
- func (opts *LLMProviderModelsOptions) GetId() string {
- return ""
- }
- func (opts *LLMProviderModelsOptions) 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
- }
|