|
@@ -6,9 +6,9 @@ import (
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_daemon/access_types"
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager"
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/session_manager"
|
|
|
- "github.com/langgenius/dify-plugin-daemon/internal/types/entities/model_entities"
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/requests"
|
|
|
+ "github.com/langgenius/dify-plugin-daemon/internal/types/entities/tool_entities"
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
|
|
|
)
|
|
|
|
|
@@ -34,16 +34,16 @@ func createSession[T any](
|
|
|
return session, nil
|
|
|
}
|
|
|
|
|
|
-func InvokeLLM(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestInvokeLLM],
|
|
|
+func InvokeTool(
|
|
|
+ r *plugin_entities.InvokePluginRequest[requests.RequestInvokeTool],
|
|
|
ctx *gin.Context,
|
|
|
max_timeout_seconds int,
|
|
|
) {
|
|
|
// create session
|
|
|
session, err := createSession(
|
|
|
r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_INVOKE_LLM,
|
|
|
+ access_types.PLUGIN_ACCESS_TYPE_TOOL,
|
|
|
+ access_types.PLUGIN_ACCESS_ACTION_INVOKE_TOOL,
|
|
|
ctx.GetString("cluster_id"),
|
|
|
)
|
|
|
if err != nil {
|
|
@@ -53,185 +53,24 @@ func InvokeLLM(
|
|
|
defer session.Close()
|
|
|
|
|
|
baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.LLMResultChunk], error) {
|
|
|
- return plugin_daemon.InvokeLLM(session, &r.Data)
|
|
|
+ func() (*stream.Stream[tool_entities.ToolResponseChunk], error) {
|
|
|
+ return plugin_daemon.InvokeTool(session, &r.Data)
|
|
|
},
|
|
|
ctx,
|
|
|
max_timeout_seconds,
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-func InvokeTextEmbedding(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestInvokeTextEmbedding],
|
|
|
+func ValidateToolCredentials(
|
|
|
+ r *plugin_entities.InvokePluginRequest[requests.RequestValidateToolCredentials],
|
|
|
ctx *gin.Context,
|
|
|
max_timeout_seconds int,
|
|
|
) {
|
|
|
// create session
|
|
|
session, err := createSession(
|
|
|
r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_INVOKE_TEXT_EMBEDDING,
|
|
|
- ctx.GetString("cluster_id"))
|
|
|
- if err != nil {
|
|
|
- ctx.JSON(500, gin.H{"error": err.Error()})
|
|
|
- return
|
|
|
- }
|
|
|
- defer session.Close()
|
|
|
-
|
|
|
- baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.TextEmbeddingResult], error) {
|
|
|
- return plugin_daemon.InvokeTextEmbedding(session, &r.Data)
|
|
|
- },
|
|
|
- ctx,
|
|
|
- max_timeout_seconds,
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-func InvokeRerank(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestInvokeRerank],
|
|
|
- ctx *gin.Context,
|
|
|
- max_timeout_seconds int,
|
|
|
-) {
|
|
|
- // create session
|
|
|
- session, err := createSession(
|
|
|
- r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_INVOKE_RERANK,
|
|
|
- ctx.GetString("cluster_id"),
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- ctx.JSON(500, gin.H{"error": err.Error()})
|
|
|
- return
|
|
|
- }
|
|
|
- defer session.Close()
|
|
|
-
|
|
|
- baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.RerankResult], error) {
|
|
|
- return plugin_daemon.InvokeRerank(session, &r.Data)
|
|
|
- },
|
|
|
- ctx,
|
|
|
- max_timeout_seconds,
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-func InvokeTTS(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestInvokeTTS],
|
|
|
- ctx *gin.Context,
|
|
|
- max_timeout_seconds int,
|
|
|
-) {
|
|
|
- // create session
|
|
|
- session, err := createSession(
|
|
|
- r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_INVOKE_TTS,
|
|
|
- ctx.GetString("cluster_id"),
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- ctx.JSON(500, gin.H{"error": err.Error()})
|
|
|
- return
|
|
|
- }
|
|
|
- defer session.Close()
|
|
|
-
|
|
|
- baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.TTSResult], error) {
|
|
|
- return plugin_daemon.InvokeTTS(session, &r.Data)
|
|
|
- },
|
|
|
- ctx,
|
|
|
- max_timeout_seconds,
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-func InvokeSpeech2Text(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestInvokeSpeech2Text],
|
|
|
- ctx *gin.Context,
|
|
|
- max_timeout_seconds int,
|
|
|
-) {
|
|
|
- // create session
|
|
|
- session, err := createSession(
|
|
|
- r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_INVOKE_SPEECH2TEXT,
|
|
|
- ctx.GetString("cluster_id"),
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- ctx.JSON(500, gin.H{"error": err.Error()})
|
|
|
- return
|
|
|
- }
|
|
|
- defer session.Close()
|
|
|
-
|
|
|
- baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.Speech2TextResult], error) {
|
|
|
- return plugin_daemon.InvokeSpeech2Text(session, &r.Data)
|
|
|
- },
|
|
|
- ctx,
|
|
|
- max_timeout_seconds,
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-func InvokeModeration(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestInvokeModeration],
|
|
|
- ctx *gin.Context,
|
|
|
- max_timeout_seconds int,
|
|
|
-) {
|
|
|
- // create session
|
|
|
- session, err := createSession(
|
|
|
- r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_INVOKE_MODERATION,
|
|
|
- ctx.GetString("cluster_id"),
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- ctx.JSON(500, gin.H{"error": err.Error()})
|
|
|
- return
|
|
|
- }
|
|
|
- defer session.Close()
|
|
|
-
|
|
|
- baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.ModerationResult], error) {
|
|
|
- return plugin_daemon.InvokeModeration(session, &r.Data)
|
|
|
- },
|
|
|
- ctx,
|
|
|
- max_timeout_seconds,
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-func ValidateProviderCredentials(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestValidateProviderCredentials],
|
|
|
- ctx *gin.Context,
|
|
|
- max_timeout_seconds int,
|
|
|
-) {
|
|
|
- // create session
|
|
|
- session, err := createSession(
|
|
|
- r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_VALIDATE_PROVIDER_CREDENTIALS,
|
|
|
- ctx.GetString("cluster_id"),
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- ctx.JSON(500, gin.H{"error": err.Error()})
|
|
|
- return
|
|
|
- }
|
|
|
- defer session.Close()
|
|
|
-
|
|
|
- baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.ValidateCredentialsResult], error) {
|
|
|
- return plugin_daemon.ValidateProviderCredentials(session, &r.Data)
|
|
|
- },
|
|
|
- ctx,
|
|
|
- max_timeout_seconds,
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-func ValidateModelCredentials(
|
|
|
- r *plugin_entities.InvokePluginRequest[requests.RequestValidateModelCredentials],
|
|
|
- ctx *gin.Context,
|
|
|
- max_timeout_seconds int,
|
|
|
-) {
|
|
|
- // create session
|
|
|
- session, err := createSession(
|
|
|
- r,
|
|
|
- access_types.PLUGIN_ACCESS_TYPE_MODEL,
|
|
|
- access_types.PLUGIN_ACCESS_ACTION_VALIDATE_MODEL_CREDENTIALS,
|
|
|
+ access_types.PLUGIN_ACCESS_TYPE_TOOL,
|
|
|
+ access_types.PLUGIN_ACCESS_ACTION_VALIDATE_TOOL_CREDENTIALS,
|
|
|
ctx.GetString("cluster_id"),
|
|
|
)
|
|
|
if err != nil {
|
|
@@ -241,8 +80,8 @@ func ValidateModelCredentials(
|
|
|
defer session.Close()
|
|
|
|
|
|
baseSSEService(
|
|
|
- func() (*stream.Stream[model_entities.ValidateCredentialsResult], error) {
|
|
|
- return plugin_daemon.ValidateModelCredentials(session, &r.Data)
|
|
|
+ func() (*stream.Stream[tool_entities.ValidateCredentialsResult], error) {
|
|
|
+ return plugin_daemon.ValidateToolCredentials(session, &r.Data)
|
|
|
},
|
|
|
ctx,
|
|
|
max_timeout_seconds,
|