Merge pull request #832 from trheyi/main
Enhance tag parsing flexibility in Assistant loading
This commit is contained in:
commit
2f230b007a
1 changed files with 26 additions and 2 deletions
|
|
@ -365,8 +365,32 @@ func loadMap(data map[string]interface{}) (*Assistant, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tags
|
// tags
|
||||||
if v, ok := data["tags"].([]string); ok {
|
if v, has := data["tags"]; has {
|
||||||
assistant.Tags = v
|
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
|
// options
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue