Skip to content

Commit

Permalink
Add missing callback hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jul 20, 2023
1 parent 42ebf6f commit 70bd6f9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,26 @@ func ChatModelGenerate(ctx context.Context, model schema.ChatModel, messages sch
return nil, err
}

res, err := model.Generate(ctx, messages, func(o *schema.GenerateOptions) {
result, err := model.Generate(ctx, messages, func(o *schema.GenerateOptions) {
o.CallbackManger = rm
o.Stop = opts.Stop
o.Functions = opts.Functions
})
if err != nil {
if cbErr := rm.OnModelError(ctx, &schema.ModelErrorManagerInput{
Error: err,
}); cbErr != nil {
return nil, cbErr
}

return nil, err
}

return &schema.ModelResult{
Generations: res.Generations,
}, nil
if err := rm.OnModelEnd(ctx, &schema.ModelEndManagerInput{
Result: result,
}); err != nil {
return nil, err
}

return result, nil
}

0 comments on commit 70bd6f9

Please sign in to comment.