Skip to content

Commit

Permalink
feat: add plugin tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Oct 22, 2024
1 parent 605a8c6 commit 1d945ef
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 58 deletions.
49 changes: 49 additions & 0 deletions internal/types/entities/plugin_entities/plugin_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,55 @@ const (
PluginType DifyManifestType = "plugin"
)

type PluginTag string

const (
PLUGIN_TAG_SEARCH PluginTag = "search"
PLUGIN_TAG_IMAGE PluginTag = "image"
PLUGIN_TAG_VIDEOS PluginTag = "videos"
PLUGIN_TAG_WEATHER PluginTag = "weather"
PLUGIN_TAG_FINANCE PluginTag = "finance"
PLUGIN_TAG_DESIGN PluginTag = "design"
PLUGIN_TAG_TRAVEL PluginTag = "travel"
PLUGIN_TAG_SOCIAL PluginTag = "social"
PLUGIN_TAG_NEWS PluginTag = "news"
PLUGIN_TAG_MEDICAL PluginTag = "medical"
PLUGIN_TAG_PRODUCTIVITY PluginTag = "productivity"
PLUGIN_TAG_EDUCATION PluginTag = "education"
PLUGIN_TAG_BUSINESS PluginTag = "business"
PLUGIN_TAG_ENTERTAINMENT PluginTag = "entertainment"
PLUGIN_TAG_UTILITIES PluginTag = "utilities"
PLUGIN_TAG_OTHER PluginTag = "other"
)

func isPluginTag(fl validator.FieldLevel) bool {
value := fl.Field().String()
switch value {
case string(PLUGIN_TAG_SEARCH),
string(PLUGIN_TAG_IMAGE),
string(PLUGIN_TAG_VIDEOS),
string(PLUGIN_TAG_WEATHER),
string(PLUGIN_TAG_FINANCE),
string(PLUGIN_TAG_DESIGN),
string(PLUGIN_TAG_TRAVEL),
string(PLUGIN_TAG_SOCIAL),
string(PLUGIN_TAG_NEWS),
string(PLUGIN_TAG_MEDICAL),
string(PLUGIN_TAG_PRODUCTIVITY),
string(PLUGIN_TAG_EDUCATION),
string(PLUGIN_TAG_BUSINESS),
string(PLUGIN_TAG_ENTERTAINMENT),
string(PLUGIN_TAG_UTILITIES),
string(PLUGIN_TAG_OTHER):
return true
}
return false
}

func init() {
validators.GlobalEntitiesValidator.RegisterValidation("plugin_tag", isPluginTag)
}

type PluginPermissionRequirement struct {
Tool *PluginPermissionToolRequirement `json:"tool,omitempty" yaml:"tool,omitempty" validate:"omitempty"`
Model *PluginPermissionModelRequirement `json:"model,omitempty" yaml:"model,omitempty" validate:"omitempty"`
Expand Down
58 changes: 0 additions & 58 deletions internal/types/entities/plugin_entities/tool_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,51 +114,6 @@ func init() {
validators.GlobalEntitiesValidator.RegisterValidation("json_schema", isJSONSchema)
}

type PluginTag string

const (
PLUGIN_TAG_SEARCH PluginTag = "search"
PLUGIN_TAG_IMAGE PluginTag = "image"
PLUGIN_TAG_VIDEOS PluginTag = "videos"
PLUGIN_TAG_WEATHER PluginTag = "weather"
PLUGIN_TAG_FINANCE PluginTag = "finance"
PLUGIN_TAG_DESIGN PluginTag = "design"
PLUGIN_TAG_TRAVEL PluginTag = "travel"
PLUGIN_TAG_SOCIAL PluginTag = "social"
PLUGIN_TAG_NEWS PluginTag = "news"
PLUGIN_TAG_MEDICAL PluginTag = "medical"
PLUGIN_TAG_PRODUCTIVITY PluginTag = "productivity"
PLUGIN_TAG_EDUCATION PluginTag = "education"
PLUGIN_TAG_BUSINESS PluginTag = "business"
PLUGIN_TAG_ENTERTAINMENT PluginTag = "entertainment"
PLUGIN_TAG_UTILITIES PluginTag = "utilities"
PLUGIN_TAG_OTHER PluginTag = "other"
)

func isPluginTag(fl validator.FieldLevel) bool {
value := fl.Field().String()
switch value {
case string(PLUGIN_TAG_SEARCH),
string(PLUGIN_TAG_IMAGE),
string(PLUGIN_TAG_VIDEOS),
string(PLUGIN_TAG_WEATHER),
string(PLUGIN_TAG_FINANCE),
string(PLUGIN_TAG_DESIGN),
string(PLUGIN_TAG_TRAVEL),
string(PLUGIN_TAG_SOCIAL),
string(PLUGIN_TAG_NEWS),
string(PLUGIN_TAG_MEDICAL),
string(PLUGIN_TAG_PRODUCTIVITY),
string(PLUGIN_TAG_EDUCATION),
string(PLUGIN_TAG_BUSINESS),
string(PLUGIN_TAG_ENTERTAINMENT),
string(PLUGIN_TAG_UTILITIES),
string(PLUGIN_TAG_OTHER):
return true
}
return false
}

type ToolProviderIdentity struct {
Author string `json:"author" validate:"required"`
Name string `json:"name" validate:"required"`
Expand Down Expand Up @@ -332,19 +287,6 @@ func init() {
},
)

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

validators.GlobalEntitiesValidator.RegisterValidation("is_basic_type", isBasicType)
}

Expand Down

0 comments on commit 1d945ef

Please sign in to comment.