Skip to content

Commit

Permalink
Enhance tag parsing flexibility in Assistant loading
Browse files Browse the repository at this point in the history
- Improved tag handling in loadMap to support multiple input types
- Added support for parsing tags from []interface{}, string, and other JSON-compatible formats
- Utilized jsoniter for robust type conversion and marshaling
- Increased robustness of tag loading process for diverse input scenarios

This change enhances the flexibility of tag parsing during Assistant initialization, allowing more versatile data input methods.
  • Loading branch information
trheyi committed Jan 26, 2025
1 parent 2a5ccb0 commit d8b0703
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions neo/assistant/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,32 @@ func loadMap(data map[string]interface{}) (*Assistant, error) {
}

// tags
if v, ok := data["tags"].([]string); ok {
assistant.Tags = v
if v, has := data["tags"]; has {
switch vv := v.(type) {
case []string:
assistant.Tags = vv
case []interface{}:
var tags []string
for _, tag := range vv {
tags = append(tags, cast.ToString(tag))
}
assistant.Tags = tags

case interface{}:
raw, err := jsoniter.Marshal(vv)
if err != nil {
return nil, err
}
var tags []string
err = jsoniter.Unmarshal(raw, &tags)
if err != nil {
return nil, err
}
assistant.Tags = tags

case string:
assistant.Tags = []string{vv}
}
}

// options
Expand Down

0 comments on commit d8b0703

Please sign in to comment.