llm.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package llm
  2. import (
  3. "time"
  4. "yunion.io/x/onecloud/pkg/apis"
  5. computeapi "yunion.io/x/onecloud/pkg/apis/compute"
  6. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  7. )
  8. const (
  9. SERVICE_TYPE = "llm"
  10. )
  11. type LLMBaseListDetails struct {
  12. apis.VirtualResourceDetails
  13. // AccessInfo []AccessInfoListOutput
  14. Volume Volume `json:"volume"`
  15. LLMImage string `json:"llm_image"`
  16. LLMImageLable string `json:"llm_image_lable"`
  17. LLMImageName string `json:"llm_image_name"`
  18. VcpuCount int `json:"vcpu_count"`
  19. VmemSizeMb int `json:"vmem_size_mb"`
  20. Devices *Devices `json:"devices"`
  21. NetworkType string `json:"network_type"`
  22. NetworkId string `json:"network_id"`
  23. Network string `json:"network"`
  24. EffectBandwidthMbps int `json:"effect_bandwidth_mbps"`
  25. StartTime time.Time `json:"start_time"`
  26. LLMStatus string `json:"llm_status"`
  27. Server string `json:"server"`
  28. HostInfo
  29. Zone string `json:"zone"`
  30. ZoneId string `json:"zone_id"`
  31. AdbPublic string `json:"adb_public"`
  32. AdbAccess string `json:"adb_access"`
  33. }
  34. type MountedModelInfo struct {
  35. FullName string `json:"fullname"` // 模型全名,如: qwen3:8b
  36. ModelId string `json:"model_id"` // 模型ID,如: 500a1f067a9f
  37. Id string `json:"id"` // 秒装包的 ID 主键
  38. }
  39. type LLMListDetails struct {
  40. LLMBaseListDetails
  41. LLMSku string `json:"llm_sku"`
  42. LLMType string `json:"llm_type"`
  43. MountedModels []MountedModelInfo `json:"mounted_models"`
  44. }
  45. type LLMBaseCreateInput struct {
  46. apis.VirtualResourceCreateInput
  47. PreferHost string `json:"prefer_host"`
  48. AutoStart bool `json:"auto_start"`
  49. Nets []*computeapi.NetworkConfig `json:"nets"`
  50. BandwidthMB int `json:"bandwidth_mb"`
  51. DebugMode bool `json:"debug_mode"`
  52. RootfsUnlimit bool `json:"rootfs_unlimit"`
  53. }
  54. type LLMCreateInput struct {
  55. LLMBaseCreateInput
  56. LLMSkuId string `json:"llm_sku_id"`
  57. LLMImageId string `json:"llm_image_id"`
  58. LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
  59. }
  60. // LLMUpdateInput is the request body for updating an LLM (including llm_spec overrides).
  61. type LLMUpdateInput struct {
  62. apis.VirtualResourceBaseUpdateInput
  63. InstantModelQuotaGb *int `json:"instant_model_quota_gb,omitempty"`
  64. LLMSpec *LLMSpec `json:"llm_spec,omitempty"`
  65. }
  66. type LLMBaseListInput struct {
  67. apis.VirtualResourceListInput
  68. apis.EnabledResourceBaseListInput
  69. Host string `json:"host"`
  70. Status []string `json:"status"`
  71. NetworkType string `json:"network_type"`
  72. NetworkId string `json:"network_id"`
  73. NoVolume *bool `json:"no_volume"`
  74. ListenPort int `json:"listen_port"`
  75. PublicIp string `json:"public_ip"`
  76. VolumeId string `json:"volume_id"`
  77. Unused *bool `json:"unused"`
  78. }
  79. type LLMListInput struct {
  80. LLMBaseListInput
  81. LLMSku string `json:"llm_sku"`
  82. LLMImage string `json:"llm_image"`
  83. LLMTypes []string `json:"llm_types"` // filter by linked SKU's llm_types (e.g. [dify, openclaw])
  84. LLMType string `json:"llm_type"` // filter by linked SKU's llm_type (e.g. dify)
  85. }
  86. type ModelInfo struct {
  87. // 秒装模型ID
  88. Id string `json:"id"`
  89. // 秒装模型 ModelId
  90. ModelId string `json:"model_id"`
  91. // 秒装模型展示的名称,如: Qwen-7B
  92. DisplayName string `json:"display_name"`
  93. // 秒装模型 tag,如: 7b
  94. Tag string `json:"tag"`
  95. // 秒装模型 LLM 类型
  96. LlmType string `json:"llm_type"`
  97. }
  98. type LLMPerformQuickModelsInput struct {
  99. Models []ModelInfo `json:"models"`
  100. Method TQuickModelMethod `json:"method"`
  101. }
  102. type LLMBatchPerformOutput struct {
  103. Data []LLMPerformOutput `json:"data"`
  104. Task *taskman.STask `json:"task"`
  105. }
  106. type LLMPerformOutput struct {
  107. Id string `json:"id"`
  108. Name string `json:"name"`
  109. RequestStatus int `json:"request_status"`
  110. Msg string `json:"msg"`
  111. TaskId string `json:"task_id"`
  112. }
  113. type LLMSyncModelTaskInput struct {
  114. LLMPerformQuickModelsInput
  115. LLMStatus string `json:"llm_status"`
  116. InstallModelIds []string `json:"install_model_ids"`
  117. InstallDirs []string `json:"install_dirs"`
  118. UninstallModelIds []string `json:"uninstall_model_ids"`
  119. }
  120. type LLMMountDirInfo struct {
  121. ImageId string `json:"image_id"`
  122. Host string `json:"host"`
  123. Container string `json:"container"`
  124. }
  125. func (info LLMMountDirInfo) ToOverlay() apis.ContainerVolumeMountDiskPostOverlay {
  126. // uid := int64(1000)
  127. // gid := int64(1000)
  128. if len(info.ImageId) > 0 {
  129. return apis.ContainerVolumeMountDiskPostOverlay{
  130. Image: &apis.ContainerVolumeMountDiskPostImageOverlay{
  131. Id: info.ImageId,
  132. },
  133. // FsUser: &uid,
  134. // FsGroup: &gid,
  135. }
  136. }
  137. return apis.ContainerVolumeMountDiskPostOverlay{
  138. ContainerTargetDir: info.Container,
  139. HostLowerDir: []string{info.Host},
  140. // FsUser: &uid,
  141. // FsGroup: &gid,
  142. }
  143. }
  144. type LLMSyncStatusInput struct {
  145. }
  146. type LLMRestartInput struct {
  147. }
  148. type LLMRestartTaskInput struct {
  149. LLMId string
  150. ResetDataDisk bool
  151. LLMStatus string
  152. SkuId string
  153. ImageId string
  154. BackupName string
  155. Property []string
  156. RebindVolumeId string
  157. OnlyStop bool
  158. }
  159. type LLMChangeNetworkInput struct {
  160. BandwidthMb int `json:"bandwidth_mb"`
  161. WhitePrefxies []string `json:"white_prefxies"`
  162. }
  163. type LLMVolumeInput struct {
  164. LLMId string `json:"llm_id"`
  165. VolumeId string `json:"volume_id"`
  166. AutoStart bool `json:"auto_start"`
  167. }
  168. type LLMAccessUrlInfo struct {
  169. LoginUrl string `json:"login_url"`
  170. PublicUrl string `json:"public_url"`
  171. InternalUrl string `json:"internal_url"`
  172. }
  173. // LLMAccessInfo is the response for GET /llms/<id>/login-info: login URL and credentials.
  174. type LLMAccessInfo struct {
  175. LLMAccessUrlInfo
  176. Username string `json:"username,omitempty"`
  177. Password string `json:"password,omitempty"`
  178. Extra map[string]string `json:"extra,omitempty"`
  179. }
  180. type LLMProviderModelsInput struct {
  181. URL string `json:"url"`
  182. ProviderType LLMClientType `json:"provider_type"`
  183. }
  184. type LLMProviderModelsOutput struct {
  185. ProviderType LLMClientType `json:"provider_type"`
  186. URL string `json:"url"`
  187. Models []string `json:"models"`
  188. }