Enhance tag parsing flexibility in Assistant loading
- 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.
This commit is contained in:
parent
2a5ccb0e2d
commit
d8b070338f
1 changed files with 26 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue