chains: export ChainCallOptions so custom Chain implementations can read options#1495
Open
zxuhan wants to merge 1 commit into
Open
chains: export ChainCallOptions so custom Chain implementations can read options#1495zxuhan wants to merge 1 commit into
zxuhan wants to merge 1 commit into
Conversation
…ead options ChainCallOption was declared as func(*chainCallOption), where chainCallOption was unexported. Code outside the chains package could accept a ChainCallOption slice but had no way to invoke the functions or read the values the caller set, making it impossible to implement the Chain interface externally while respecting caller options. Export the struct as ChainCallOptions with exported Set flags and add ApplyChainCallOptions as the entry point for custom implementations. Internal uses in this package now go through ApplyChainCallOptions too. Fixes tmc#1085.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChainCallOptionis currently defined as:where
chainCallOptionis unexported. That makes it impossible to implement thechains.Chaininterface from outside thechainspackage while still respecting caller-supplied options — callers can pass a[]ChainCallOption, but a custom implementation has no way to construct a*chainCallOptionto invoke the functions against, and no way to read the resulting field values.This PR exports the struct as
ChainCallOptions(plural, to avoid colliding with the existingChainCallOptionfunction type), exports the*Setflags, and adds a publicApplyChainCallOptionshelper:Custom implementations can now write:
Internal usage (
NewLLMChain,GetLLMCallOptions) was switched over toApplyChainCallOptionsfor consistency.Compatibility
Renaming
chainCallOption→ChainCallOptionsand thexxxSetflags →XxxSetis non-breaking: external callers could not reference the private type, so no existing import path changes. TheChainCallOptionfunction type itself is unchanged at the signature level.Fixes #1085.
Test plan
go build ./...cleango vet ./chains/... ./agents/...cleanTestApplyChainCallOptions_ExternalChaininchains_test(external package) demonstrates implementingchains.Chainfrom outside and reading caller optionsTestApplyChainCallOptions_Emptycovers the zero-value pathchains/unit tests pass; only failing tests (TestLLMChainWithGoogleAI,TestConstitutionalChain) are pre-existing integration tests requiring external credentials