Add support for field selection in assistant filtering
- Implemented `select` parameter parsing in `parseAssistantFilter` - Added support for selecting fields via string, string array, or interface array - Enhanced `neo/process.go` to handle flexible field selection - Improved error handling in stream chat processing - Fixed function message handling in message appending
This commit is contained in:
parent
eb814dab05
commit
54e946c61d
4 changed files with 54 additions and 6 deletions
|
|
@ -377,6 +377,13 @@ func (ast *Assistant) streamChat(
|
||||||
Write(c.Writer)
|
Write(c.Writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hook execute error
|
||||||
|
if hookErr != nil {
|
||||||
|
chatMessage.New().Error(hookErr.Error()).Done().Write(c.Writer)
|
||||||
|
done <- true
|
||||||
|
return 0 // break
|
||||||
|
}
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
if res.Output != nil {
|
if res.Output != nil {
|
||||||
chatMessage.New().
|
chatMessage.New().
|
||||||
|
|
|
||||||
|
|
@ -332,8 +332,10 @@ func (m *Message) AppendTo(contents *Contents) *Message {
|
||||||
case "tool_calls":
|
case "tool_calls":
|
||||||
|
|
||||||
// Set function name
|
// Set function name
|
||||||
|
new := false
|
||||||
if name, ok := m.Props["function"].(string); ok && name != "" {
|
if name, ok := m.Props["function"].(string); ok && name != "" {
|
||||||
contents.NewFunction(name, []byte(m.Text))
|
contents.NewFunction(name, []byte(m.Text))
|
||||||
|
new = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set id
|
// Set id
|
||||||
|
|
@ -341,7 +343,9 @@ func (m *Message) AppendTo(contents *Contents) *Message {
|
||||||
contents.SetFunctionID(id)
|
contents.SetFunctionID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
contents.AppendFunction([]byte(m.Text))
|
if !new {
|
||||||
|
contents.AppendFunction([]byte(m.Text))
|
||||||
|
}
|
||||||
return m
|
return m
|
||||||
|
|
||||||
case "loading", "error", "action": // Ignore loading, action and error messages
|
case "loading", "error", "action": // Ignore loading, action and error messages
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/yaoapp/gou/process"
|
"github.com/yaoapp/gou/process"
|
||||||
|
|
@ -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
|
// Parse tags
|
||||||
if tags, ok := params["tags"]; ok {
|
if tags, ok := params["tags"]; ok {
|
||||||
switch v := tags.(type) {
|
switch v := tags.(type) {
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,24 @@ func File(id string, ext string) string {
|
||||||
|
|
||||||
// SpecName 解析名称 root: "/tests/apis" file: "/tests/apis/foo/bar.http.json"
|
// SpecName 解析名称 root: "/tests/apis" file: "/tests/apis/foo/bar.http.json"
|
||||||
func SpecName(root string, file string) string {
|
func SpecName(root string, file string) string {
|
||||||
filename := strings.TrimPrefix(file, root+"/") // "foo/bar.http.json"
|
filename := strings.TrimPrefix(file, root+"/") // "foo/bar.http.json", "foo/bar2.0.http.json"
|
||||||
namer := strings.Split(filename, ".") // ["foo/bar", "http", "json"]
|
parts := strings.Split(filename, "/") // ["foo", "bar.http.json"], ["foo", "bar2.0.http.json"]
|
||||||
nametypes := strings.Split(namer[0], "/") // ["foo", "bar"]
|
basename := parts[len(parts)-1] // "bar.http.json", "bar2.0.http.json"
|
||||||
name := strings.Join(nametypes, ".") // "foo.bar"
|
paths := parts[:len(parts)-1] // ["foo"], ["foo"]
|
||||||
return name
|
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 解析数据处理脚本名称
|
// ScriptName 解析数据处理脚本名称
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue