Skip to content

Commit

Permalink
refactor: define ToolsNodeCallbackHandler and reduce callback templat… (
Browse files Browse the repository at this point in the history
#15)

refactor: define ToolsNodeCallbackHandler and reduce callback template boilerplate code

Change-Id: I6ce887165c0a1e0e576c8c40e3537457ccec3748
  • Loading branch information
shentongmartin authored Dec 24, 2024
1 parent 8392514 commit 1eb08b1
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 171 deletions.
8 changes: 4 additions & 4 deletions components/model/callback_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ type CallbackOutput struct {
// ConvCallbackInput converts the callback input to the model callback input.
func ConvCallbackInput(src callbacks.CallbackInput) *CallbackInput {
switch t := src.(type) {
case *CallbackInput:
case *CallbackInput: // when callback is triggered within component implementation, the input is usually already a typed *model.CallbackInput
return t
case []*schema.Message:
case []*schema.Message: // when callback is injected by graph node, not the component implementation itself, the input is the input of Chat Model interface, which is []*schema.Message
return &CallbackInput{
Messages: t,
}
Expand All @@ -88,9 +88,9 @@ func ConvCallbackInput(src callbacks.CallbackInput) *CallbackInput {
// ConvCallbackOutput converts the callback output to the model callback output.
func ConvCallbackOutput(src callbacks.CallbackOutput) *CallbackOutput {
switch t := src.(type) {
case *CallbackOutput:
case *CallbackOutput: // when callback is triggered within component implementation, the output is usually already a typed *model.CallbackOutput
return t
case *schema.Message:
case *schema.Message: // when callback is injected by graph node, not the component implementation itself, the output is the output of Chat Model interface, which is *schema.Message
return &CallbackOutput{
Message: t,
}
Expand Down
Loading

0 comments on commit 1eb08b1

Please sign in to comment.