Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for field selection in assistant filtering #843

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions neo/assistant/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ func (ast *Assistant) streamChat(
Write(c.Writer)
}

// Hook execute error
if hookErr != nil {
chatMessage.New().Error(hookErr.Error()).Done().Write(c.Writer)
done <- true
return 0 // break
}

// Output
if res.Output != nil {
chatMessage.New().
Expand Down
6 changes: 5 additions & 1 deletion neo/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,20 @@ func (m *Message) AppendTo(contents *Contents) *Message {
case "tool_calls":

// Set function name
new := false
if name, ok := m.Props["function"].(string); ok && name != "" {
contents.NewFunction(name, []byte(m.Text))
new = true
}

// Set id
if id, ok := m.Props["id"].(string); ok && id != "" {
contents.SetFunctionID(id)
}

contents.AppendFunction([]byte(m.Text))
if !new {
contents.AppendFunction([]byte(m.Text))
}
return m

case "loading", "error", "action": // Ignore loading, action and error messages
Expand Down
24 changes: 24 additions & 0 deletions neo/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/gin-gonic/gin"
"github.com/yaoapp/gou/process"
Expand Down Expand Up @@ -295,6 +296,29 @@ func parseAssistantFilter(params map[string]interface{}) store.AssistantFilter {
}
}

// select
if sel, ok := params["select"]; ok {
switch v := sel.(type) {
case []interface{}:
filter.Select = []string{}
for _, field := range v {
switch field.(type) {
case string:
filter.Select = append(filter.Select, field.(string))
case interface{}:
filter.Select = append(filter.Select, fmt.Sprintf("%v", field))
}
}

case []string:
filter.Select = v

case string:
fields := strings.Split(v, ",")
filter.Select = fields
}
}

// Parse tags
if tags, ok := params["tags"]; ok {
switch v := tags.(type) {
Expand Down
23 changes: 18 additions & 5 deletions share/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,24 @@ func File(id string, ext string) string {

// SpecName 解析名称 root: "/tests/apis" file: "/tests/apis/foo/bar.http.json"
func SpecName(root string, file string) string {
filename := strings.TrimPrefix(file, root+"/") // "foo/bar.http.json"
namer := strings.Split(filename, ".") // ["foo/bar", "http", "json"]
nametypes := strings.Split(namer[0], "/") // ["foo", "bar"]
name := strings.Join(nametypes, ".") // "foo.bar"
return name
filename := strings.TrimPrefix(file, root+"/") // "foo/bar.http.json", "foo/bar2.0.http.json"
parts := strings.Split(filename, "/") // ["foo", "bar.http.json"], ["foo", "bar2.0.http.json"]
basename := parts[len(parts)-1] // "bar.http.json", "bar2.0.http.json"
paths := parts[:len(parts)-1] // ["foo"], ["foo"]
for i, path := range paths {
paths[i] = strings.ReplaceAll(path, ".", "_") // ["foo"], ["foo"]
}
names := strings.Split(basename, ".") // ["bar", "http", "json"], ["bar2", "0", "http", "json"]
namelen := len(names)
extcnt := 1
if names[namelen-1] == "yao" || names[namelen-1] == "json" || names[namelen-1] == "jsonc" {
extcnt = 2
}
names = names[:len(names)-extcnt] // ["bar"], ["bar2", "0"]
basename = strings.Join(names, ".") // "bar", "bar2.0"
basename = strings.ReplaceAll(basename, ".", "_") // "bar", "bar2_0"
paths = append(paths, basename) // ["foo", "bar"], ["foo", "bar2_0"]
return strings.Join(paths, ".") // "foo.bar", "foo.bar2_0"
}

// ScriptName 解析数据处理脚本名称
Expand Down