Merge pull request #832 from trheyi/main

Enhance tag parsing flexibility in Assistant loading
This commit is contained in:
Max 2025-01-26 15:55:35 +08:00 committed by GitHub
commit 2f230b007a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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