llm_spec.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package llm
  15. import (
  16. "reflect"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/gotypes"
  19. )
  20. // LLMSpec is the flat spec for LLM SKU: optional ollama/vllm/dify payload. Type is on LLMSku.LLMType.
  21. type LLMSpec struct {
  22. Ollama *LLMSpecOllama `json:"ollama,omitempty"`
  23. Vllm *LLMSpecVllm `json:"vllm,omitempty"`
  24. Dify *LLMSpecDify `json:"dify,omitempty"`
  25. ComfyUI *LLMSpecComfyUI `json:"comfyui,omitempty"`
  26. OpenClaw *LLMSpecOpenClaw `json:"openclaw,omitempty"`
  27. }
  28. func (s *LLMSpec) String() string {
  29. return jsonutils.Marshal(s).String()
  30. }
  31. func (s *LLMSpec) IsZero() bool {
  32. if s == nil {
  33. return true
  34. }
  35. return s.Ollama == nil && s.Vllm == nil && s.Dify == nil && s.ComfyUI == nil && s.OpenClaw == nil
  36. }
  37. // LLMSpecOllama holds type-specific fields for ollama SKUs.
  38. type LLMSpecOllama struct {
  39. }
  40. func (s *LLMSpecOllama) String() string {
  41. return jsonutils.Marshal(s).String()
  42. }
  43. func (s *LLMSpecOllama) IsZero() bool {
  44. if s == nil {
  45. return true
  46. }
  47. return false
  48. }
  49. // LLMSpecVllm holds type-specific fields for vllm SKUs (includes PreferredModel).
  50. type LLMSpecVllm struct {
  51. PreferredModel string `json:"preferred_model"`
  52. CustomizedArgs []*VllmCustomizedArg `json:"customized_args,omitempty"`
  53. }
  54. type VllmCustomizedArg struct {
  55. Key string `json:"key"`
  56. Value string `json:"value"`
  57. }
  58. func (s *LLMSpecVllm) String() string {
  59. return jsonutils.Marshal(s).String()
  60. }
  61. func (s *LLMSpecVllm) IsZero() bool {
  62. if s == nil {
  63. return true
  64. }
  65. return s.PreferredModel == "" && len(s.CustomizedArgs) == 0
  66. }
  67. // LLMSpecDify holds type-specific fields for Dify SKUs (multiple image ids + customized envs).
  68. type LLMSpecDify struct {
  69. PostgresImageId string `json:"postgres_image_id"`
  70. RedisImageId string `json:"redis_image_id"`
  71. NginxImageId string `json:"nginx_image_id"`
  72. DifyApiImageId string `json:"dify_api_image_id"`
  73. DifyPluginImageId string `json:"dify_plugin_image_id"`
  74. DifyWebImageId string `json:"dify_web_image_id"`
  75. DifySandboxImageId string `json:"dify_sandbox_image_id"`
  76. DifySSRFImageId string `json:"dify_ssrf_image_id"`
  77. DifyWeaviateImageId string `json:"dify_weaviate_image_id"`
  78. CustomizedEnvs []*DifyCustomizedEnv `json:"customized_envs,omitempty"`
  79. }
  80. func (s *LLMSpecDify) String() string {
  81. return jsonutils.Marshal(s).String()
  82. }
  83. func (s *LLMSpecDify) IsZero() bool {
  84. if s == nil {
  85. return true
  86. }
  87. return s.PostgresImageId == "" && s.RedisImageId == "" && s.NginxImageId == "" &&
  88. s.DifyApiImageId == "" && s.DifyPluginImageId == "" && s.DifyWebImageId == "" &&
  89. s.DifySandboxImageId == "" && s.DifySSRFImageId == "" && s.DifyWeaviateImageId == "" &&
  90. len(s.CustomizedEnvs) == 0
  91. }
  92. type LLMSpecComfyUI struct {
  93. }
  94. func (s *LLMSpecComfyUI) String() string {
  95. return jsonutils.Marshal(s).String()
  96. }
  97. func (s *LLMSpecComfyUI) IsZero() bool {
  98. if s == nil {
  99. return true
  100. }
  101. return false
  102. }
  103. type LLMSpecCredential struct {
  104. Id string `json:"id"`
  105. ExportKeys []string `json:"export_keys"`
  106. }
  107. type LLMSpecOpenClawProvider struct {
  108. Name string `json:"name"`
  109. Credential *LLMSpecCredential `json:"credential"`
  110. }
  111. type LLMSpecOpenClawChannel struct {
  112. Name string `json:"name"`
  113. Credential *LLMSpecCredential `json:"credential"`
  114. }
  115. type LLMSpecOpenClaw struct {
  116. Providers []*LLMSpecOpenClawProvider `json:"providers"`
  117. Channels []*LLMSpecOpenClawChannel `json:"channels"`
  118. WorkspaceTemplates *LLMSpecOpenClawWorkspaceTemplates `json:"workspace_templates"`
  119. }
  120. type LLMSpecOpenClawWorkspaceTemplates struct {
  121. AgentsMD string `json:"agents_md"`
  122. SoulMD string `json:"soul_md"`
  123. UserMD string `json:"user_md"`
  124. }
  125. func init() {
  126. gotypes.RegisterSerializable(reflect.TypeOf(new(LLMSpec)), func() gotypes.ISerializable {
  127. return new(LLMSpec)
  128. })
  129. }