-
Notifications
You must be signed in to change notification settings - Fork 20.3k
propagate callbacks through load_summarize_chain #7565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
propagate callbacks through load_summarize_chain #7565
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this introduces the converse problem, of making it hard to create a map reduce docs chain with only callbacks on the MapReduceDocumentsChain.
maybe we call this arg something like shared_callbacks? and for the final map reduce chain we check if kwargs contains 'callbacks', and only used shared_callbacks if it doesn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that kind of flexibility thing that people want? I think this is an area where I'm a little confused on best practices in langchain.
What I feel like I'm seeing in most of the codebase is that callbacks are passed into agent/chain/llm constructors or utility functions, and that means "all children of this object get the same callbacks" are passed down to child chains / llms / etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth noting that the docs call out this general pattern here:
The
callbacksargument is available on most objects throughout the API (Chains, Models, Tools, Agents, etc.) in two different places:
- Constructor callbacks: defined in the constructor, eg.
LLMChain(callbacks=[handler], tags=['a-tag']), which will be used for all calls made on that object, and will be scoped to that object only, eg. if you pass a handler to theLLMChainconstructor, it will not be used by the Model attached to that chain.- Request callbacks: defined in the
run()/apply()methods used for issuing a request, eg.chain.run(input, callbacks=[handler]), which will be used for that specific request only, and all sub-requests that it contains (eg. a call to an LLMChain triggers a call to a Model, which uses the same handler passed in thecall()method).The
verboseargument is available on most objects throughout the API (Chains, Models, Tools, Agents, etc.) as a constructor argument, eg.LLMChain(verbose=True), and it is equivalent to passing aConsoleCallbackHandlerto thecallbacksargument of that object and all child objects. This is useful for debugging, as it will log all events to the console.
i.e. the notion of "shared" callbacks is the default rather than the exception.
This particular root function (load_summarize_chain) is technically not a constructor but it is doing a tremendous amount of scaffolding and calling constructors that would otherwise take callbacks.
The way this case seems to be addressed elsewhere in the codebase is to add a xxx_kwargs parameter, e.g. agent_kwargs. So here you could have doc_chain_kwargs but personally that feels like an awkward way to change this interface to support what would seem to me to be a somewhat esoteric case (supporting only callbacks on MapReduceDocumentsChain)
|
@d1sounds - this is an example of some of the callbacks propagation I've been working on |
64540f0 to
046b5f3
Compare
…uffDocumentsChain (#7853) This is another case, similar to #5572 and #7565 where the callbacks are getting dropped during construction of the chains. tagging @hwchase17 and @agola11 for callbacks propagation <!-- Thank you for contributing to LangChain! Replace this comment with: - Description: a description of the change, - Issue: the issue # it fixes (if applicable), - Dependencies: any dependencies required for this change, - Tag maintainer: for a quicker response, tag the relevant maintainer (see below), - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out! If you're adding a new integration, please include: 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. Maintainer responsibilities: - General / Misc / if you don't know who to tag: @baskaryan - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev - Models / Prompts: @hwchase17, @baskaryan - Memory: @hwchase17 - Agents / Tools / Toolkits: @hinthornw - Tracing / Callbacks: @agola11 - Async: @agola11 If no one reviews your PR within a few days, feel free to @-mention the same people again. See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md -->
hwchase17
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
This lets you pass callbacks when you create the summarize chain:
See #5572 for a similar surgical fix.
tagging @hwchase17 for callbacks work