Create New Provider
This skill guides you through adding a new provider implementation to an existing package.
Prerequisites
- •Ensure the package supports the provider pattern (e.g.,
pkg/llms,pkg/vectorstores). - •Identify the interface to implement (usually in
pkg/<package>/ifaceorpkg/<package>/<package>.go).
Steps
- •
Create Provider Directory
- •Create
pkg/<package>/providers/<provider_name>/. - •Create
pkg/<package>/providers/<provider_name>/<provider_name>.go.
- •Create
- •
Implement Interface
- •Define a struct
Provider(or similar) that implements the interface. - •Implement the
New(options ...)factory function.
- •Define a struct
- •
Add Configuration
- •Define a config struct.
- •Use
mapstructuretags for decoding.
- •
Register Global Factory
- •In
pkg/<package>/registry.go(orfactory.go), add the init block or manual registration for your new provider.
- •In
- •
Add Testing
- •Create
pkg/<package>/providers/<provider_name>/<provider_name>_test.go. - •Use
test_utilsfor mocks.
- •Create
Example File Structure
code
pkg/llms/providers/anthropic/ ├── anthropic.go # Implementation ├── config.go # Config struct └── anthropic_test.go # Tests