controller.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package server
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/langgenius/dify-plugin-daemon/internal/service"
  5. "github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
  6. "github.com/langgenius/dify-plugin-daemon/internal/types/entities/requests"
  7. )
  8. func HealthCheck(c *gin.Context) {
  9. c.JSON(200, gin.H{"status": "ok"})
  10. }
  11. func InvokeTool(c *gin.Context) {
  12. type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeTool]
  13. BindRequest[request](
  14. c,
  15. func(itr request) {
  16. service.InvokeTool(&itr, c)
  17. },
  18. )
  19. }
  20. func ValidateToolCredentials(c *gin.Context) {
  21. type request = plugin_entities.InvokePluginRequest[requests.RequestValidateToolCredentials]
  22. BindRequest[request](
  23. c,
  24. func(itr request) {
  25. service.ValidateToolCredentials(&itr, c)
  26. },
  27. )
  28. }
  29. func InvokeLLM(c *gin.Context) {
  30. type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeLLM]
  31. BindRequest[request](
  32. c,
  33. func(itr request) {
  34. service.InvokeLLM(&itr, c)
  35. },
  36. )
  37. }
  38. func InvokeTextEmbedding(c *gin.Context) {
  39. type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeTextEmbedding]
  40. BindRequest[request](
  41. c,
  42. func(itr request) {
  43. service.InvokeTextEmbedding(&itr, c)
  44. },
  45. )
  46. }
  47. func InvokeRerank(c *gin.Context) {
  48. type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeRerank]
  49. BindRequest[request](
  50. c,
  51. func(itr request) {
  52. service.InvokeRerank(&itr, c)
  53. },
  54. )
  55. }
  56. func InvokeTTS(c *gin.Context) {
  57. type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeTTS]
  58. BindRequest[request](
  59. c,
  60. func(itr request) {
  61. service.InvokeTTS(&itr, c)
  62. },
  63. )
  64. }
  65. func InvokeSpeech2Text(c *gin.Context) {
  66. type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeSpeech2Text]
  67. BindRequest[request](
  68. c,
  69. func(itr request) {
  70. service.InvokeSpeech2Text(&itr, c)
  71. },
  72. )
  73. }
  74. func InvokeModeration(c *gin.Context) {
  75. type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeModeration]
  76. BindRequest[request](
  77. c,
  78. func(itr request) {
  79. service.InvokeModeration(&itr, c)
  80. },
  81. )
  82. }
  83. func ValidateProviderCredentials(c *gin.Context) {
  84. type request = plugin_entities.InvokePluginRequest[requests.RequestValidateProviderCredentials]
  85. BindRequest[request](
  86. c,
  87. func(itr request) {
  88. service.ValidateProviderCredentials(&itr, c)
  89. },
  90. )
  91. }
  92. func ValidateModelCredentials(c *gin.Context) {
  93. type request = plugin_entities.InvokePluginRequest[requests.RequestValidateModelCredentials]
  94. BindRequest[request](
  95. c,
  96. func(itr request) {
  97. service.ValidateModelCredentials(&itr, c)
  98. },
  99. )
  100. }