Enhance Assistant Filtering with Multi-Type Support
- Added a new `Types` field to the `AssistantFilter` struct to allow filtering by multiple types using an IN query. - Updated the `GetAssistants` function to apply the new multi-type filter alongside the existing single type filter. - Modified the OpenAPI endpoint to support the new `types` query parameter for better flexibility in assistant retrieval. - Ensured backward compatibility by setting a default type when neither `type` nor `types` is specified. - Updated related documentation and tests to reflect the changes in filtering capabilities.
This commit is contained in:
parent
111fc28634
commit
ff412da7b3
5 changed files with 197 additions and 176 deletions
|
|
@ -174,7 +174,8 @@ const (
|
||||||
// Used for filtering and pagination when retrieving assistant lists
|
// Used for filtering and pagination when retrieving assistant lists
|
||||||
type AssistantFilter struct {
|
type AssistantFilter struct {
|
||||||
Tags []string `json:"tags,omitempty"` // Filter by tags
|
Tags []string `json:"tags,omitempty"` // Filter by tags
|
||||||
Type string `json:"type,omitempty"` // Filter by type
|
Type string `json:"type,omitempty"` // Filter by type (single value)
|
||||||
|
Types []string `json:"types,omitempty"` // Filter by types (multiple values, IN query)
|
||||||
Keywords string `json:"keywords,omitempty"` // Search in name and description
|
Keywords string `json:"keywords,omitempty"` // Search in name and description
|
||||||
Connector string `json:"connector,omitempty"` // Filter by connector
|
Connector string `json:"connector,omitempty"` // Filter by connector
|
||||||
AssistantID string `json:"assistant_id,omitempty"` // Filter by assistant ID
|
AssistantID string `json:"assistant_id,omitempty"` // Filter by assistant ID
|
||||||
|
|
|
||||||
|
|
@ -353,11 +353,16 @@ func (store *Xun) GetAssistants(filter types.AssistantFilter, locale ...string)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply type filter if provided
|
// Apply type filter if provided (single value)
|
||||||
if filter.Type != "" {
|
if filter.Type != "" {
|
||||||
qb.Where("type", filter.Type)
|
qb.Where("type", filter.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply types filter if provided (multiple values, IN query)
|
||||||
|
if len(filter.Types) > 0 {
|
||||||
|
qb.WhereIn("type", filter.Types)
|
||||||
|
}
|
||||||
|
|
||||||
// Apply connector filter if provided
|
// Apply connector filter if provided
|
||||||
if filter.Connector != "" {
|
if filter.Connector != "" {
|
||||||
qb.Where("connector", filter.Connector)
|
qb.Where("connector", filter.Connector)
|
||||||
|
|
|
||||||
336
data/bindata.go
336
data/bindata.go
File diff suppressed because it is too large
Load diff
|
|
@ -78,12 +78,24 @@ func ListAssistants(c *gin.Context) {
|
||||||
// Parse filter parameters
|
// Parse filter parameters
|
||||||
keywords := strings.TrimSpace(c.Query("keywords"))
|
keywords := strings.TrimSpace(c.Query("keywords"))
|
||||||
typeParam := strings.TrimSpace(c.Query("type"))
|
typeParam := strings.TrimSpace(c.Query("type"))
|
||||||
if typeParam == "" {
|
|
||||||
typeParam = "assistant" // Default type
|
|
||||||
}
|
|
||||||
connector := strings.TrimSpace(c.Query("connector"))
|
connector := strings.TrimSpace(c.Query("connector"))
|
||||||
assistantID := strings.TrimSpace(c.Query("assistant_id"))
|
assistantID := strings.TrimSpace(c.Query("assistant_id"))
|
||||||
|
|
||||||
|
// Parse types (multiple, comma-separated for IN query)
|
||||||
|
var types []string
|
||||||
|
if typesParam := c.Query("types"); typesParam != "" {
|
||||||
|
types = strings.Split(typesParam, ",")
|
||||||
|
// Trim spaces
|
||||||
|
for i, t := range types {
|
||||||
|
types[i] = strings.TrimSpace(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set default type only if neither type nor types is specified
|
||||||
|
if typeParam == "" && len(types) == 0 {
|
||||||
|
typeParam = "assistant" // Default type
|
||||||
|
}
|
||||||
|
|
||||||
// Parse assistant IDs (multiple)
|
// Parse assistant IDs (multiple)
|
||||||
var assistantIDs []string
|
var assistantIDs []string
|
||||||
if assistantIDsParam := c.Query("assistant_ids"); assistantIDsParam != "" {
|
if assistantIDsParam := c.Query("assistant_ids"); assistantIDsParam != "" {
|
||||||
|
|
@ -131,6 +143,7 @@ func ListAssistants(c *gin.Context) {
|
||||||
PageSize: pagesize,
|
PageSize: pagesize,
|
||||||
Keywords: keywords,
|
Keywords: keywords,
|
||||||
Type: typeParam,
|
Type: typeParam,
|
||||||
|
Types: types,
|
||||||
Connector: connector,
|
Connector: connector,
|
||||||
AssistantID: assistantID,
|
AssistantID: assistantID,
|
||||||
AssistantIDs: assistantIDs,
|
AssistantIDs: assistantIDs,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ type AssistantFilterParams struct {
|
||||||
Page int
|
Page int
|
||||||
PageSize int
|
PageSize int
|
||||||
Keywords string
|
Keywords string
|
||||||
Type string
|
Type string // Single type filter
|
||||||
|
Types []string // Multiple types filter (IN query)
|
||||||
Connector string
|
Connector string
|
||||||
AssistantID string
|
AssistantID string
|
||||||
AssistantIDs []string
|
AssistantIDs []string
|
||||||
|
|
@ -70,6 +71,7 @@ func BuildAssistantFilter(params AssistantFilterParams) agenttypes.AssistantFilt
|
||||||
Keywords: params.Keywords,
|
Keywords: params.Keywords,
|
||||||
Tags: params.Tags,
|
Tags: params.Tags,
|
||||||
Type: params.Type,
|
Type: params.Type,
|
||||||
|
Types: params.Types,
|
||||||
Connector: params.Connector,
|
Connector: params.Connector,
|
||||||
AssistantID: params.AssistantID,
|
AssistantID: params.AssistantID,
|
||||||
AssistantIDs: params.AssistantIDs,
|
AssistantIDs: params.AssistantIDs,
|
||||||
|
|
@ -79,8 +81,8 @@ func BuildAssistantFilter(params AssistantFilterParams) agenttypes.AssistantFilt
|
||||||
Automated: params.Automated,
|
Automated: params.Automated,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default type if not specified
|
// Set default type if not specified (only when Types is also empty)
|
||||||
if filter.Type == "" {
|
if filter.Type == "" && len(filter.Types) == 0 {
|
||||||
filter.Type = "assistant"
|
filter.Type = "assistant"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue