Skip to content
Open
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
1 change: 1 addition & 0 deletions compose/graph_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func (t *taskManager) submit(tasks []*task) error {
i--
t.num++
t.done.Send(currentTask)
continue
}

t.runningTasks[currentTask.nodeKey] = currentTask
Expand Down
11 changes: 9 additions & 2 deletions internal/concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
"fmt"
"reflect"
"strings"
"sync"
"time"

"github.com/cloudwego/eino/internal/generic"
)

var (
concatFuncs = map[reflect.Type]any{
concatFuncsMu sync.RWMutex
concatFuncs = map[reflect.Type]any{
generic.TypeOf[string](): concatStrings,
generic.TypeOf[int8](): useLast[int8],
generic.TypeOf[int16](): useLast[int16],
Expand Down Expand Up @@ -69,11 +71,16 @@ func concatStrings(ss []string) (string, error) {
}

func RegisterStreamChunkConcatFunc[T any](fn func([]T) (T, error)) {
concatFuncsMu.Lock()
concatFuncs[generic.TypeOf[T]()] = fn
concatFuncsMu.Unlock()
}

func GetConcatFunc(typ reflect.Type) func(reflect.Value) (reflect.Value, error) {
if fn, ok := concatFuncs[typ]; ok {
concatFuncsMu.RLock()
fn, ok := concatFuncs[typ]
concatFuncsMu.RUnlock()
if ok {
return func(a reflect.Value) (reflect.Value, error) {
rvs := reflect.ValueOf(fn).Call([]reflect.Value{a})
var err error
Expand Down
13 changes: 11 additions & 2 deletions internal/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,27 @@ package internal
import (
"fmt"
"reflect"
"sync"

"github.com/cloudwego/eino/internal/generic"
)

var mergeFuncs = map[reflect.Type]any{}
var (
mergeFuncsMu sync.RWMutex
mergeFuncs = map[reflect.Type]any{}
)

func RegisterValuesMergeFunc[T any](fn func([]T) (T, error)) {
mergeFuncsMu.Lock()
mergeFuncs[generic.TypeOf[T]()] = fn
mergeFuncsMu.Unlock()
}

func GetMergeFunc(typ reflect.Type) func([]any) (any, error) {
if fn, ok := mergeFuncs[typ]; ok {
mergeFuncsMu.RLock()
fn, ok := mergeFuncs[typ]
mergeFuncsMu.RUnlock()
if ok {
return func(vs []any) (any, error) {
rvs := reflect.MakeSlice(reflect.SliceOf(typ), 0, len(vs))
for _, v := range vs {
Expand Down