dify.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package llm
  2. import (
  3. "yunion.io/x/jsonutils"
  4. "yunion.io/x/pkg/errors"
  5. computeapi "yunion.io/x/onecloud/pkg/apis/compute"
  6. api "yunion.io/x/onecloud/pkg/apis/llm"
  7. "yunion.io/x/onecloud/pkg/cloudcommon/cmdline"
  8. "yunion.io/x/onecloud/pkg/mcclient/options"
  9. )
  10. type DifyListOptions struct {
  11. LLMBaseListOptions
  12. DifySku string `help:"filter by dify sku"`
  13. }
  14. func (o *DifyListOptions) Params() (jsonutils.JSONObject, error) {
  15. params, err := options.ListStructToParams(o)
  16. if err != nil {
  17. return nil, err
  18. }
  19. if o.Used != nil {
  20. params.Set("unused", jsonutils.JSONFalse)
  21. }
  22. params.Set("llm_type", jsonutils.NewString(string(api.LLM_CONTAINER_DIFY)))
  23. return params, nil
  24. }
  25. type DifyShowOptions struct {
  26. options.BaseShowOptions
  27. }
  28. func (o *DifyShowOptions) Params() (jsonutils.JSONObject, error) {
  29. return options.StructToParams(o)
  30. }
  31. type DifyCreateOptions struct {
  32. LLMBaseCreateOptions
  33. DIFY_SKU_ID string `help:"dify sku id or name" json:"llm_sku_id"`
  34. }
  35. func (o *DifyCreateOptions) Params() (jsonutils.JSONObject, error) {
  36. params := jsonutils.Marshal(o)
  37. if len(o.Net) > 0 {
  38. nets := make([]*computeapi.NetworkConfig, 0)
  39. for i, n := range o.Net {
  40. net, err := cmdline.ParseNetworkConfig(n, i)
  41. if err != nil {
  42. return nil, errors.Wrapf(err, "parse network config %s", n)
  43. }
  44. nets = append(nets, net)
  45. }
  46. params.(*jsonutils.JSONDict).Add(jsonutils.Marshal(nets), "nets")
  47. }
  48. return params, nil
  49. }
  50. func (o *DifyCreateOptions) GetCountParam() int {
  51. return o.Count
  52. }
  53. type DifyDeleteOptions struct {
  54. options.BaseIdOptions
  55. }
  56. func (o *DifyDeleteOptions) GetId() string {
  57. return o.ID
  58. }
  59. func (o *DifyDeleteOptions) Params() (jsonutils.JSONObject, error) {
  60. return options.StructToParams(o)
  61. }
  62. type DifyStartOptions struct {
  63. options.BaseIdsOptions
  64. }
  65. func (o *DifyStartOptions) Params() (jsonutils.JSONObject, error) {
  66. return jsonutils.Marshal(o), nil
  67. }
  68. type DifyStopOptions struct {
  69. options.BaseIdsOptions
  70. }
  71. func (o *DifyStopOptions) Params() (jsonutils.JSONObject, error) {
  72. return jsonutils.Marshal(o), nil
  73. }