diff --git a/go.mod b/go.mod index 082cb3484..d018c183d 100644 --- a/go.mod +++ b/go.mod @@ -102,6 +102,7 @@ require ( github.com/richardlehane/msoleps v1.0.4 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect + github.com/spf13/cast v1.7.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tcnksm/go-gitconfig v0.1.2 // indirect github.com/tidwall/btree v1.7.0 // indirect diff --git a/go.sum b/go.sum index 09a2c82a7..2efec00f3 100644 --- a/go.sum +++ b/go.sum @@ -160,6 +160,7 @@ github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3x github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= @@ -219,6 +220,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= +github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= diff --git a/neo/assistant/api.go b/neo/assistant/api.go index 260ce88f2..8cad38904 100644 --- a/neo/assistant/api.go +++ b/neo/assistant/api.go @@ -82,6 +82,25 @@ func (ast *Assistant) Chat(ctx context.Context, messages []map[string]interface{ func (ast *Assistant) requestMessages(ctx context.Context, messages []map[string]interface{}) ([]map[string]interface{}, error) { newMessages := []map[string]interface{}{} + + // With Prompts + if ast.Prompts != nil { + for _, prompt := range ast.Prompts { + message := map[string]interface{}{ + "role": prompt.Role, + "content": prompt.Content, + } + + name := ast.Name + if prompt.Name != "" { + name = prompt.Name + } + + message["name"] = name + newMessages = append(newMessages, message) + } + } + length := len(messages) for index, message := range messages { role, ok := message["role"].(string) diff --git a/neo/assistant/load.go b/neo/assistant/load.go index b17e8b02e..99cfb2bed 100644 --- a/neo/assistant/load.go +++ b/neo/assistant/load.go @@ -8,6 +8,7 @@ import ( "time" jsoniter "github.com/json-iterator/go" + "github.com/spf13/cast" "github.com/yaoapp/gou/fs" "github.com/yaoapp/gou/rag/driver" v8 "github.com/yaoapp/gou/runtime/v8" @@ -66,11 +67,27 @@ func LoadBuiltIn() error { assistant.Readonly = true assistant.BuiltIn = true - assistant.Sort = sort + if assistant.Sort == 0 { + assistant.Sort = sort + } if assistant.Tags == nil { assistant.Tags = []string{"Built-in"} } + // Check if the assistant has Built-in tag + hasBuiltIn := false + for _, tag := range assistant.Tags { + if tag == "Built-in" { + hasBuiltIn = true + break + } + } + + // add Built-in tag if not exists + if !hasBuiltIn { + assistant.Tags = append(assistant.Tags, "Built-in") + } + // Save the assistant err = assistant.Save() if err != nil { @@ -284,8 +301,8 @@ func loadMap(data map[string]interface{}) (*Assistant, error) { } // sort - if v, ok := data["sort"].(int); ok { - assistant.Sort = v + if v, has := data["sort"]; has { + assistant.Sort = cast.ToInt(v) } // path