Skip to content

Commit

Permalink
feat: add tool selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Sep 4, 2024
1 parent 3603a9c commit ea61dc3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
49 changes: 43 additions & 6 deletions internal/types/entities/plugin_entities/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import (
type ConfigType string

const (
CONFIG_TYPE_SECRET_INPUT ConfigType = SECRET_INPUT
CONFIG_TYPE_TEXT_INPUT ConfigType = TEXT_INPUT
CONFIG_TYPE_SELECT ConfigType = SELECT
CONFIG_TYPE_BOOLEAN ConfigType = BOOLEAN
CONFIG_TYPE_MODEL_CONFIG ConfigType = MODEL_CONFIG
CONFIG_TYPE_APP_SELECTOR ConfigType = APP_SELECTOR
CONFIG_TYPE_SECRET_INPUT ConfigType = SECRET_INPUT
CONFIG_TYPE_TEXT_INPUT ConfigType = TEXT_INPUT
CONFIG_TYPE_SELECT ConfigType = SELECT
CONFIG_TYPE_BOOLEAN ConfigType = BOOLEAN
CONFIG_TYPE_MODEL_CONFIG ConfigType = MODEL_CONFIG
CONFIG_TYPE_APP_SELECTOR ConfigType = APP_SELECTOR
CONFIG_TYPE_TOOL_SELECTOR ConfigType = TOOL_SELECTOR
)

type ModelConfigScope string

const (
MODEL_CONFIG_SCOPE_ALL ModelConfigScope = "all"
MODEL_CONFIG_SCOPE_LLM ModelConfigScope = "llm"
MODEL_CONFIG_SCOPE_TEXT_EMBEDDING ModelConfigScope = "text-embedding"
MODEL_CONFIG_SCOPE_RERANK ModelConfigScope = "rerank"
Expand All @@ -39,6 +41,15 @@ const (
APP_SELECTOR_SCOPE_COMPLETION AppSelectorScope = "completion"
)

type ToolSelectorScope string

const (
TOOL_SELECTOR_SCOPE_ALL ToolSelectorScope = "all"
TOOL_SELECTOR_SCOPE_PLUGIN ToolSelectorScope = "plugin"
TOOL_SELECTOR_SCOPE_API ToolSelectorScope = "api"
TOOL_SELECTOR_SCOPE_WORKFLOW ToolSelectorScope = "workflow"
)

func isCredentialType(fl validator.FieldLevel) bool {
value := fl.Field().String()
switch value {
Expand Down Expand Up @@ -84,6 +95,17 @@ func isAppSelectorScope(fl validator.FieldLevel) bool {
return false
}

func isToolSelectorScope(fl validator.FieldLevel) bool {
value := fl.Field().String()
switch value {
case string(TOOL_SELECTOR_SCOPE_ALL),
string(TOOL_SELECTOR_SCOPE_PLUGIN),
string(TOOL_SELECTOR_SCOPE_API),
string(TOOL_SELECTOR_SCOPE_WORKFLOW):
return true
}
return false
}
func isScope(fl validator.FieldLevel) bool {
// get parent and check if it's a provider config
parent := fl.Parent().Interface()
Expand All @@ -93,6 +115,8 @@ func isScope(fl validator.FieldLevel) bool {
return isAppSelectorScope(fl)
} else if provider_config.Type == CONFIG_TYPE_MODEL_CONFIG {
return isModelConfigScope(fl)
} else if provider_config.Type == CONFIG_TYPE_TOOL_SELECTOR {
return isToolSelectorScope(fl)
} else {
return false
}
Expand Down Expand Up @@ -143,6 +167,19 @@ func init() {
return t
},
)

validators.GlobalEntitiesValidator.RegisterValidation("is_tool_selector_scope", isToolSelectorScope)
validators.GlobalEntitiesValidator.RegisterTranslation(
"is_tool_selector_scope",
translator,
func(ut ut.Translator) error {
return ut.Add("is_tool_selector_scope", "{0} is not a valid tool selector scope", true)
},
func(ut ut.Translator, fe validator.FieldError) string {
t, _ := ut.T("is_tool_selector_scope", fe.Field())
return t
},
)
}

type ProviderConfig struct {
Expand Down
19 changes: 10 additions & 9 deletions internal/types/entities/plugin_entities/constant.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package plugin_entities

const (
SECRET_INPUT = "secret-input"
TEXT_INPUT = "text-input"
SELECT = "select"
STRING = "string"
NUMBER = "number"
FILE = "file"
BOOLEAN = "boolean"
APP_SELECTOR = "app-selector"
MODEL_CONFIG = "model-config"
SECRET_INPUT = "secret-input"
TEXT_INPUT = "text-input"
SELECT = "select"
STRING = "string"
NUMBER = "number"
FILE = "file"
BOOLEAN = "boolean"
APP_SELECTOR = "app-selector"
MODEL_CONFIG = "model-config"
TOOL_SELECTOR = "tool-selector"
)
20 changes: 11 additions & 9 deletions internal/types/entities/plugin_entities/tool_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ type ToolParameterOption struct {
type ToolParameterType string

const (
TOOL_PARAMETER_TYPE_STRING ToolParameterType = STRING
TOOL_PARAMETER_TYPE_NUMBER ToolParameterType = NUMBER
TOOL_PARAMETER_TYPE_BOOLEAN ToolParameterType = BOOLEAN
TOOL_PARAMETER_TYPE_SELECT ToolParameterType = SELECT
TOOL_PARAMETER_TYPE_SECRET_INPUT ToolParameterType = SECRET_INPUT
TOOL_PARAMETER_TYPE_FILE ToolParameterType = FILE
TOOL_PARAMETER_TYPE_APP_SELECTOR ToolParameterType = APP_SELECTOR
TOOL_PARAMETER_TYPE_MODEL_CONFIG ToolParameterType = MODEL_CONFIG
TOOL_PARAMETER_TYPE_STRING ToolParameterType = STRING
TOOL_PARAMETER_TYPE_NUMBER ToolParameterType = NUMBER
TOOL_PARAMETER_TYPE_BOOLEAN ToolParameterType = BOOLEAN
TOOL_PARAMETER_TYPE_SELECT ToolParameterType = SELECT
TOOL_PARAMETER_TYPE_SECRET_INPUT ToolParameterType = SECRET_INPUT
TOOL_PARAMETER_TYPE_FILE ToolParameterType = FILE
TOOL_PARAMETER_TYPE_APP_SELECTOR ToolParameterType = APP_SELECTOR
TOOL_PARAMETER_TYPE_MODEL_CONFIG ToolParameterType = MODEL_CONFIG
TOOL_PARAMETER_TYPE_TOOL_SELECTOR ToolParameterType = TOOL_SELECTOR
)

func isToolParameterType(fl validator.FieldLevel) bool {
Expand All @@ -46,7 +47,8 @@ func isToolParameterType(fl validator.FieldLevel) bool {
string(TOOL_PARAMETER_TYPE_SECRET_INPUT),
string(TOOL_PARAMETER_TYPE_FILE),
string(TOOL_PARAMETER_TYPE_APP_SELECTOR),
string(TOOL_PARAMETER_TYPE_MODEL_CONFIG):
string(TOOL_PARAMETER_TYPE_MODEL_CONFIG),
string(TOOL_PARAMETER_TYPE_TOOL_SELECTOR):
return true
}
return false
Expand Down

0 comments on commit ea61dc3

Please sign in to comment.