providers: add opt-out build tags to reduce binary size#222
Draft
ljuti wants to merge 1 commit intocharmbracelet:mainfrom
Draft
providers: add opt-out build tags to reduce binary size#222ljuti wants to merge 1 commit intocharmbracelet:mainfrom
ljuti wants to merge 1 commit intocharmbracelet:mainfrom
Conversation
Add opt-out build tags so users can exclude providers they don't use. All providers compile by default (no breaking change). Pass -tags to exclude heavy dependency trees: go build -tags "nogoogle,noaws,noazure,novercel,noopenrouter,nokronk" Tags: nogoogle — google provider + anthropic vertex support noaws — bedrock provider + anthropic bedrock support noazure — azure provider novercel — vercel provider noopenrouter — openrouter provider nokronk — kronk provider Anthropic's bedrock.go and google.go are gated behind !noaws and !nogoogle respectively. Bedrock/Vertex configuration is extracted from anthropic.go into build-tagged files with error-returning stubs. Binary size impact (stripped, anthropic+openai+openaicompat only): Before: 32 MB After: 12 MB (63% reduction)
e01f1ec to
32c5d69
Compare
Contributor
Author
|
@andreynering Opening this as a draft PR because I'm not sure if this is a direction that you want to go with the library. Feel free to reject and close if not aligned with project goals. I'm building and maintaining an internal toolset that uses Fantasy and I'd like to keep the dependencies as clean as possible. Currently, my plan is to internally support only |
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.
Add opt-out build tags so users can exclude providers they don't use, reducing binary size significantly.
All providers compile by default — no breaking change. Pass
-tagsto exclude heavy dependency trees:go build -tags "nogoogle,noaws,noazure,novercel,noopenrouter,nokronk" ./...Tags
nogoogleproviders/google+ anthropic vertex supportnoawsproviders/bedrock+ anthropic bedrock supportnoazureproviders/azurenovercelproviders/vercelnoopenrouterproviders/openrouternokronkproviders/kronkImplementation
.gofile in each optional provider package gets//go:build !no<name>providertests/files that import optional providers get matching tagsbedrock.go/google.gogated behind!noaws/!nogoogleLanguageModelconfiguration extracted into build-tagged files (bedrock_lm.go,vertex_lm.go) with error-returning stubs for when excludedanthropic.goheavy imports (AWS SDK, Google OAuth) removed from main fileBinary size impact
Stripped
-ldflags="-s -w"binary with anthropic + openai + openaicompat: