Skip to content

Commit

Permalink
feat: remove node/graph cb
Browse files Browse the repository at this point in the history
  • Loading branch information
meguminnnnnnnnn committed Dec 18, 2024
1 parent 25d5162 commit 3c01c4c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 34 deletions.
14 changes: 4 additions & 10 deletions compose/graph_call_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ type Option struct {
options []any
handler []callbacks.Handler

nodeHandler []callbacks.Handler // deprecated
keys []string
keys []string

graphHandler []callbacks.Handler // deprecated
maxRunSteps int
maxRunSteps int
}

// DesignateNode set the key of the node which will be used to.
Expand Down Expand Up @@ -136,16 +134,12 @@ func WithCallbacks(cbs ...callbacks.Handler) Option {

// Deprecated: use WithCallbacks and perform the type checking for component within it instead
func WithNodeCallbacks(cbs ...callbacks.Handler) Option {
return Option{
nodeHandler: cbs,
}
return WithCallbacks(cbs...)
}

// Deprecated: use WithCallbacks and perform the type checking for component within it instead
func WithGraphCallbacks(cbs ...callbacks.Handler) Option {
return Option{
graphHandler: cbs,
}
return WithCallbacks(cbs...)
}

// Deprecated: use WithRuntimeMaxSteps directly instead.
Expand Down
3 changes: 1 addition & 2 deletions compose/graph_call_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func TestCallOption(t *testing.T) {
WithChatModelOption(
model.WithTopP(1.0),
),
WithGraphCallbacks(),
WithNodeCallbacks(callbacks.NewHandlerBuilder().
WithCallbacks(callbacks.NewHandlerBuilder().
OnStartFn(func(ctx context.Context, info *callbacks.RunInfo, input callbacks.CallbackInput) context.Context {
startCnt++
return context.WithValue(ctx, sessionKey, "start")
Expand Down
13 changes: 0 additions & 13 deletions compose/graph_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,19 +510,6 @@ func initNodeCallbacks(ctx context.Context, key string, info *nodeInfo, meta *ex

var cbs []callbacks.Handler
for i := range opts {
if len(opts[i].nodeHandler) != 0 {
if len(opts[i].keys) == 0 {
cbs = append(cbs, opts[i].nodeHandler...)
} else {
for _, k := range opts[i].keys {
if k == key {
cbs = append(cbs, opts[i].nodeHandler...)
break
}
}
}
}

if len(opts[i].handler) != 0 {
if len(opts[i].keys) == 0 {
cbs = append(cbs, opts[i].handler...)
Expand Down
10 changes: 5 additions & 5 deletions compose/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestGraphWithImplementableType(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, ErrExceedMaxSteps, err)

_, err = r.Invoke(ctx, "how are you", WithGraphRunOption(WithRuntimeMaxSteps(1)))
_, err = r.Invoke(ctx, "how are you", WithRuntimeMaxSteps(WithRuntimeMaxSteps(1)))
assert.Error(t, err)
assert.Equal(t, ErrExceedMaxSteps, err)

Expand Down Expand Up @@ -288,12 +288,12 @@ func TestNestedGraph(t *testing.T) {
}).Build()

// invoke
ri, err := r.Invoke(ctx, "london", WithNodeCallbacks(cb))
ri, err := r.Invoke(ctx, "london", WithCallbacks(cb))
assert.NoError(t, err)
t.Log(ri)

// stream
rs, err := r.Stream(ctx, "london", WithNodeCallbacks(cb))
rs, err := r.Stream(ctx, "london", WithCallbacks(cb))
assert.NoError(t, err)
for {
ri, err = rs.Recv()
Expand All @@ -310,7 +310,7 @@ func TestNestedGraph(t *testing.T) {
_ = sw.Send("london", nil)
sw.Close()

rc, err := r.Collect(ctx, sr, WithNodeCallbacks(cb))
rc, err := r.Collect(ctx, sr, WithCallbacks(cb))
assert.NoError(t, err)
t.Log(rc)

Expand All @@ -319,7 +319,7 @@ func TestNestedGraph(t *testing.T) {
_ = sw.Send("london", nil)
sw.Close()

rt, err := r.Transform(ctx, sr, WithNodeCallbacks(cb))
rt, err := r.Transform(ctx, sr, WithCallbacks(cb))
assert.NoError(t, err)
for {
ri, err = rt.Recv()
Expand Down
4 changes: 0 additions & 4 deletions compose/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ func initGraphCallbacks(ctx context.Context, info *nodeInfo, meta *executorMeta,

var cbs []callbacks.Handler
for i := range opts {
if len(opts[i].graphHandler) != 0 {
cbs = append(cbs, opts[i].graphHandler...)
}

if len(opts[i].handler) != 0 && len(opts[i].keys) == 0 {
cbs = append(cbs, opts[i].handler...)
}
Expand Down

0 comments on commit 3c01c4c

Please sign in to comment.