Skip to content

Commit

Permalink
feat: controller for get debugging key
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Jul 26, 2024
1 parent 7de9d7e commit 9e60d83
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package controllers

import (
"github.com/gin-gonic/gin"
Expand Down
7 changes: 7 additions & 0 deletions internal/server/controllers/health_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package controllers

import "github.com/gin-gonic/gin"

func HealthCheck(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package controllers

import (
"github.com/gin-gonic/gin"
Expand All @@ -7,32 +7,6 @@ import (
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/requests"
)

func HealthCheck(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
}

func InvokeTool(c *gin.Context) {
type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeTool]

BindRequest[request](
c,
func(itr request) {
service.InvokeTool(&itr, c)
},
)
}

func ValidateToolCredentials(c *gin.Context) {
type request = plugin_entities.InvokePluginRequest[requests.RequestValidateToolCredentials]

BindRequest[request](
c,
func(itr request) {
service.ValidateToolCredentials(&itr, c)
},
)
}

func InvokeLLM(c *gin.Context) {
type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeLLM]

Expand Down
15 changes: 15 additions & 0 deletions internal/server/controllers/remote_debugging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package controllers

import (
"github.com/gin-gonic/gin"
"github.com/langgenius/dify-plugin-daemon/internal/service"
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/requests"
)

func GetRemoteDebuggingKey(c *gin.Context) {
BindRequest[requests.RequestGetRemoteDebuggingKey](
c, func(request requests.RequestGetRemoteDebuggingKey) {
c.JSON(200, service.GetRemoteDebuggingKey(request.TenantID))
},
)
}
30 changes: 30 additions & 0 deletions internal/server/controllers/tool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package controllers

import (
"github.com/gin-gonic/gin"
"github.com/langgenius/dify-plugin-daemon/internal/service"
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/requests"
)

func InvokeTool(c *gin.Context) {
type request = plugin_entities.InvokePluginRequest[requests.RequestInvokeTool]

BindRequest[request](
c,
func(itr request) {
service.InvokeTool(&itr, c)
},
)
}

func ValidateToolCredentials(c *gin.Context) {
type request = plugin_entities.InvokePluginRequest[requests.RequestValidateToolCredentials]

BindRequest[request](
c,
func(itr request) {
service.ValidateToolCredentials(&itr, c)
},
)
}
28 changes: 17 additions & 11 deletions internal/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@ import (
"fmt"

"github.com/gin-gonic/gin"
"github.com/langgenius/dify-plugin-daemon/internal/server/controllers"
"github.com/langgenius/dify-plugin-daemon/internal/types/app"
)

func server(config *app.Config) {
engine := gin.Default()

engine.GET("/health/check", HealthCheck)
engine.POST("/plugin/tool/invoke", CheckingKey(config.PluginInnerApiKey), InvokeTool)
engine.POST("/plugin/tool/validate_credentials", CheckingKey(config.PluginInnerApiKey), ValidateToolCredentials)
engine.POST("/plugin/llm/invoke", CheckingKey(config.PluginInnerApiKey), InvokeLLM)
engine.POST("/plugin/text_embedding/invoke", CheckingKey(config.PluginInnerApiKey), InvokeTextEmbedding)
engine.POST("/plugin/rerank/invoke", CheckingKey(config.PluginInnerApiKey), InvokeRerank)
engine.POST("/plugin/tts/invoke", CheckingKey(config.PluginInnerApiKey), InvokeTTS)
engine.POST("/plugin/speech2text/invoke", CheckingKey(config.PluginInnerApiKey), InvokeSpeech2Text)
engine.POST("/plugin/moderation/invoke", CheckingKey(config.PluginInnerApiKey), InvokeModeration)
engine.POST("/plugin/model/validate_provider_credentials", CheckingKey(config.PluginInnerApiKey), ValidateProviderCredentials)
engine.POST("/plugin/model/validate_model_credentials", CheckingKey(config.PluginInnerApiKey), ValidateModelCredentials)
engine.GET("/health/check", controllers.HealthCheck)

engine.POST("/plugin/tool/invoke", CheckingKey(config.PluginInnerApiKey), controllers.InvokeTool)
engine.POST("/plugin/tool/validate_credentials", CheckingKey(config.PluginInnerApiKey), controllers.ValidateToolCredentials)
engine.POST("/plugin/llm/invoke", CheckingKey(config.PluginInnerApiKey), controllers.InvokeLLM)
engine.POST("/plugin/text_embedding/invoke", CheckingKey(config.PluginInnerApiKey), controllers.InvokeTextEmbedding)
engine.POST("/plugin/rerank/invoke", CheckingKey(config.PluginInnerApiKey), controllers.InvokeRerank)
engine.POST("/plugin/tts/invoke", CheckingKey(config.PluginInnerApiKey), controllers.InvokeTTS)
engine.POST("/plugin/speech2text/invoke", CheckingKey(config.PluginInnerApiKey), controllers.InvokeSpeech2Text)
engine.POST("/plugin/moderation/invoke", CheckingKey(config.PluginInnerApiKey), controllers.InvokeModeration)
engine.POST("/plugin/model/validate_provider_credentials", CheckingKey(config.PluginInnerApiKey), controllers.ValidateProviderCredentials)
engine.POST("/plugin/model/validate_model_credentials", CheckingKey(config.PluginInnerApiKey), controllers.ValidateModelCredentials)

if config.PluginRemoteInstallingEnabled {
engine.POST("/plugin/debugging/key", CheckingKey(config.PluginInnerApiKey), controllers.GetRemoteDebuggingKey)
}

engine.Run(fmt.Sprintf(":%d", config.SERVER_PORT))
}
24 changes: 24 additions & 0 deletions internal/service/debugging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package service

import (
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager/remote_manager"
"github.com/langgenius/dify-plugin-daemon/internal/types/entities"
)

func GetRemoteDebuggingKey(tenant_id string) entities.Response {
type response struct {
Key string `json:"key"`
}

key, err := remote_manager.GetConnectionKey(remote_manager.ConnectionInfo{
TenantId: tenant_id,
})

if err != nil {
return *entities.NewErrorResponse(-500, err.Error())
}

return *entities.NewSuccessResponse(response{
Key: key,
})
}
5 changes: 5 additions & 0 deletions internal/types/entities/requests/debugging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package requests

type RequestGetRemoteDebuggingKey struct {
TenantID string `json:"tenant_id" validate:"required"`
}

0 comments on commit 9e60d83

Please sign in to comment.