sku.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package llm
  2. import (
  3. "reflect"
  4. "yunion.io/x/jsonutils"
  5. "yunion.io/x/pkg/gotypes"
  6. "yunion.io/x/pkg/util/sets"
  7. "yunion.io/x/onecloud/pkg/apis"
  8. computeapi "yunion.io/x/onecloud/pkg/apis/compute"
  9. )
  10. var (
  11. LLM_SKU_BASE_NETWORK_TYPES = sets.NewString(
  12. string(computeapi.NETWORK_TYPE_HOSTLOCAL),
  13. string(computeapi.NETWORK_TYPE_GUEST),
  14. )
  15. )
  16. func IsLLMSkuBaseNetworkType(t string) bool {
  17. return LLM_SKU_BASE_NETWORK_TYPES.Has(t)
  18. }
  19. type HostInfo struct {
  20. HostId string `json:"host_id"`
  21. Host string `json:"host"`
  22. HostAccessIp string `json:"host_access_ip"`
  23. HostEIP string `json:"host_eip"`
  24. }
  25. func init() {
  26. gotypes.RegisterSerializable(reflect.TypeOf(&PortMappings{}), func() gotypes.ISerializable {
  27. return &PortMappings{}
  28. })
  29. gotypes.RegisterSerializable(reflect.TypeOf(&Devices{}), func() gotypes.ISerializable {
  30. return &Devices{}
  31. })
  32. gotypes.RegisterSerializable(reflect.TypeOf(&PortMappingEnvs{}), func() gotypes.ISerializable {
  33. return &PortMappingEnvs{}
  34. })
  35. gotypes.RegisterSerializable(reflect.TypeOf(&Envs{}), func() gotypes.ISerializable {
  36. return &Envs{}
  37. })
  38. }
  39. type PortMappingEnv struct {
  40. Key string `json:"key"`
  41. ValueFrom string `json:"value_from"`
  42. }
  43. type PortMappingEnvs []PortMappingEnv
  44. func (pm PortMappingEnvs) String() string {
  45. return jsonutils.Marshal(pm).String()
  46. }
  47. func (pm PortMappingEnvs) IsZero() bool {
  48. return len(pm) == 0
  49. }
  50. type PortMapping struct {
  51. Protocol string `json:"protocol"`
  52. ContainerPort int `json:"container_port"`
  53. RemoteIps []string `json:"remote_ips"`
  54. FirstPortOffset *int `json:"first_port_offset"`
  55. Envs []computeapi.GuestPortMappingEnv `json:"envs"`
  56. }
  57. type PortMappings []PortMapping
  58. func (s PortMappings) String() string {
  59. return jsonutils.Marshal(s).String()
  60. }
  61. func (s PortMappings) IsZero() bool {
  62. return len(s) == 0
  63. }
  64. type Device struct {
  65. DevType string `json:"dev_type"`
  66. Model string `json:"model"`
  67. DevicePath string `json:"device_path"`
  68. }
  69. type Devices []Device
  70. func (s Devices) String() string {
  71. return jsonutils.Marshal(s).String()
  72. }
  73. func (s Devices) IsZero() bool {
  74. return len(s) == 0
  75. }
  76. type Env struct {
  77. Key string `json:"key"`
  78. Value string `json:"value"`
  79. }
  80. type Envs []Env
  81. func (s Envs) String() string {
  82. return jsonutils.Marshal(s).String()
  83. }
  84. func (s Envs) IsZero() bool {
  85. return len(s) == 0
  86. }
  87. type LLMSkuDetails struct {
  88. apis.SharableVirtualResourceDetails
  89. // 当前大模型套餐包含的实例个数。
  90. LLMCapacity int `json:"llm_capacity"`
  91. Image string `json:"image"`
  92. ImageLabel string `json:"image_label"`
  93. ImageName string `json:"image_name"`
  94. MountedModelDetails []MountedModelInfo `json:"mounted_model_details"`
  95. Template string `json:"template"`
  96. // LLMType 为 SKU 类型(ollama/vllm/dify),与 llm_spec 一起带出
  97. LLMType string `json:"llm_type"`
  98. // LLMSpec 从 SKU 持久化字段带出,保证 list/show 与 create 一致
  99. LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
  100. }
  101. type MountedAppResourceDetails struct {
  102. MountedModels []string `json:"mounted_models"`
  103. }
  104. type LLMSKuBaseCreateInput struct {
  105. apis.SharableVirtualResourceCreateInput
  106. Cpu int `json:"cpu"`
  107. Memory int `json:"memory"`
  108. Bandwidth int `json:"bandwidth"`
  109. Volumes *Volumes `json:"volumes"`
  110. PortMappings *PortMappings `json:"port_mappings"`
  111. Devices *Devices `json:"devices"`
  112. Envs *Envs `json:"envs"`
  113. Properties map[string]string `json:"properties"`
  114. }
  115. type LLMSkuBaseUpdateInput struct {
  116. apis.SharableVirtualResourceBaseUpdateInput
  117. Cpu *int `json:"cpu"`
  118. Memory *int `json:"memory"`
  119. // RequstSyncImage *bool `json:"request_sync_image"`
  120. DiskSize *int `json:"disk_size" yunion-deprecated-by:"disk_size_mb"`
  121. DiskSizeMB *int `json:"disk_size_mb"`
  122. TemplateId *string `json:"template_id"`
  123. StorageType *string `json:"storage_type"`
  124. Volumes *Volumes `json:"volumes"`
  125. Bandwidth *int `json:"bandwidth"`
  126. PortMappings *PortMappings `json:"port_mappings"`
  127. Devices *Devices `json:"devices"`
  128. Envs *Envs `json:"envs"`
  129. Properties map[string]string `json:"properties"`
  130. }
  131. type LLMSkuListInput struct {
  132. apis.SharableVirtualResourceListInput
  133. MountedModelResourceListInput
  134. LLMType string `json:"llm_type"`
  135. LLMTypes []string `json:"llm_types"`
  136. }
  137. type LLMSkuCreateInput struct {
  138. LLMSKuBaseCreateInput
  139. MountedModelResourceCreateInput
  140. LLMImageId string `json:"llm_image_id"`
  141. LLMType string `json:"llm_type"`
  142. // LLMSpec:
  143. // - ollama/vllm: backend builds llm_spec from llm_image_id + mounted_models; for vllm preferred model should be set in llm_spec.vllm.preferred_model.
  144. // - dify: client must send llm_spec with type "dify" and dify payload.
  145. LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
  146. }
  147. type LLMSkuUpdateInput struct {
  148. LLMSkuBaseUpdateInput
  149. MountedModelResourceUpdateInput
  150. LLMImageId string `json:"llm_image_id"`
  151. // LLMSpec:
  152. // - dify: send full spec to update image ids.
  153. // - ollama/vllm: backend may build from llm_image_id/mounted_models; for vllm preferred model should be set in llm_spec.vllm.preferred_model.
  154. LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
  155. }
  156. // type LLMModelCloneInput struct {
  157. // Name string `json:"name"`
  158. // }
  159. // type LLMModelSyncImageRequestTaskInput struct {
  160. // Request bool `json:"request"`
  161. // }
  162. // type DifySkulListInput struct {
  163. // apis.SharableVirtualResourceListInput
  164. // MountedModelResourceListInput
  165. // }
  166. // type DifySkuCreateInput struct {
  167. // LLMSKuBaseCreateInput
  168. // PostgresImageId string `json:"postgres_image_id"`
  169. // RedisImageId string `json:"redis_image_id"`
  170. // NginxImageId string `json:"nginx_image_id"`
  171. // DifyApiImageId string `json:"dify_api_image_id"`
  172. // DifyPluginImageId string `json:"dify_plugin_image_id"`
  173. // DifyWebImageId string `json:"dify_web_image_id"`
  174. // DifySandboxImageId string `json:"dify_sandbox_image_id"`
  175. // DifySSRFImageId string `json:"dify_ssrf_image_id"`
  176. // DifyWeaviateImageId string `json:"dify_weaviate_image_id"`
  177. // }
  178. // type DifySkuUpdateInput struct {
  179. // LLMSkuBaseUpdateInput
  180. // PostgresImageId string `json:"postgres_image_id"`
  181. // RedisImageId string `json:"redis_image_id"`
  182. // NginxImageId string `json:"nginx_image_id"`
  183. // DifyApiImageId string `json:"dify_api_image_id"`
  184. // DifyPluginImageId string `json:"dify_plugin_image_id"`
  185. // DifyWebImageId string `json:"dify_web_image_id"`
  186. // DifySandboxImageId string `json:"dify_sandbox_image_id"`
  187. // DifySSRFImageId string `json:"dify_ssrf_image_id"`
  188. // DifyWeaviateImageId string `json:"dify_weaviate_image_id"`
  189. // }