Skip to content

Commit defb278

Browse files
asimclaude
andauthored
update AI provider documentation (#2897)
* feat: add prometheus monitoring wrapper Reintroduces the Prometheus metrics wrapper previously available in the plugins repository, updated for go-micro v5. Exposes request count and latency histograms for handlers, subscribers, and outgoing client calls via NewHandlerWrapper, NewSubscriberWrapper, NewCallWrapper and NewClientWrapper, labelled with service/endpoint/status. Options cover namespace, subsystem, const labels, histogram buckets and a custom registerer; duplicate collectors (e.g. from multiple wrappers sharing the same config) are reused transparently via a cached metrics bundle. Fixes #2893 * fix(registry/etcd): clear lease/register caches on KeepAlive channel closure When the etcd client's long-lived KeepAlive channel closes (e.g. because the lease expired on the server side during a network partition), the previous cleanup only removed the channel bookkeeping. The stale entries in `leases` and `register` caused the next registerNode() heartbeat to hit the "unchanged hash" short-circuit and skip re-registration entirely, so the service permanently disappeared from etcd. Extract the cleanup into handleKeepAliveClosed and also drop the cached lease id and hash so the next heartbeat performs a full Grant+Put and the service recovers within one RegisterInterval. Regression introduced by #2822; fix is symmetric with the existing synchronous KeepAliveOnce recovery path that propagates rpctypes.ErrLeaseNotFound. * docs: add AI provider integration guide and Supported AI Providers section Add a step-by-step guide for AI infrastructure companies to implement ai.Model and contribute a provider to go-micro. Covers the full lifecycle: skeleton, tool call handling, tests, registration, and PR checklist. Add a "Supported AI Providers" section to the project README that lists current providers (Anthropic, OpenAI) in a table and links to the integration guide with a call-to-action for new providers and sponsors. Streamline the "Adding a New Provider" section in ai/README.md to point to the new guide instead of duplicating a full code listing. * Update contribution guidelines in README.md Removed Discord contact information for platform contributions. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 15cc876 commit defb278

3 files changed

Lines changed: 383 additions & 58 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ Package reference: https://pkg.go.dev/go-micro.dev/v5
376376
- [Getting Started](internal/website/docs/getting-started.md)
377377
- [Data Model](internal/website/docs/model.md)
378378
- [MCP & AI Agents](internal/website/docs/mcp.md)
379+
- [AI Provider Integration](internal/website/docs/guides/ai-provider-guide.md)
379380
- [Plugins Overview](internal/website/docs/plugins.md)
380381
- [Learn by Example](internal/website/docs/examples/index.md)
381382
- [Deployment Guide](internal/website/docs/deployment.md)
@@ -388,6 +389,26 @@ Package reference: https://pkg.go.dev/go-micro.dev/v5
388389
- [TLS Security Migration](internal/website/docs/TLS_SECURITY_UPDATE.md)
389390
- [Security Migration Guide](internal/website/docs/SECURITY_MIGRATION.md)
390391

392+
## Supported AI Providers
393+
394+
Go Micro’s `ai` package gives every provider the same interface: `Init`, `Generate`, `Stream`, and functional options. Swap providers with a single import.
395+
396+
| Provider | Import | Default Model |
397+
|----------|--------|---------------|
398+
| **Anthropic** | `go-micro.dev/v5/ai/anthropic` | `claude-sonnet-4-20250514` |
399+
| **OpenAI** | `go-micro.dev/v5/ai/openai` | `gpt-4o` |
400+
401+
Any provider that exposes an OpenAI-compatible API can also be used directly:
402+
403+
```go
404+
m := ai.New("openai",
405+
ai.WithAPIKey("your-key"),
406+
ai.WithBaseURL("https://api.yourprovider.com"),
407+
)
408+
```
409+
410+
**Want to add your platform?** See the [AI Provider Integration Guide](internal/website/docs/guides/ai-provider-guide.md) for how to implement `ai.Model` and submit a PR. We welcome both code contributions and sponsorships from AI infrastructure companies — reach out via a [GitHub issue](https://github.com/micro/go-micro/issues).
411+
391412
## Adopters
392413

393414
- [Sourse](https://sourse.eu) - Work in the field of earth observation, including embedded Kubernetes running onboard aircraft, and we’ve built a mission management SaaS platform using Go Micro.

ai/README.md

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -165,70 +165,21 @@ m := ai.New(provider, ai.WithAPIKey("..."))
165165

166166
## Adding a New Provider
167167

168-
1. Create a new package under `ai/`:
168+
See the full **[AI Provider Integration Guide](../internal/website/docs/guides/ai-provider-guide.md)** for a step-by-step walkthrough, checklist, and design notes.
169169

170-
```go
171-
package myprovider
172-
173-
import "go-micro.dev/v5/ai"
174-
175-
func init() {
176-
ai.Register("myprovider", func(opts ...ai.Option) ai.Model {
177-
return NewProvider(opts...)
178-
})
179-
}
180-
181-
type Provider struct {
182-
opts ai.Options
183-
}
170+
Quick summary:
184171

185-
func NewProvider(opts ...ai.Option) *Provider {
186-
options := ai.NewOptions(opts...)
187-
// Set defaults
188-
if options.Model == "" {
189-
options.Model = "my-default-model"
190-
}
191-
if options.BaseURL == "" {
192-
options.BaseURL = "https://api.myprovider.com"
193-
}
194-
return &Provider{opts: options}
195-
}
196-
197-
func (p *Provider) Init(opts ...ai.Option) error {
198-
for _, o := range opts {
199-
o(&p.opts)
200-
}
201-
return nil
202-
}
203-
204-
func (p *Provider) Options() ai.Options {
205-
return p.opts
206-
}
207-
208-
func (p *Provider) String() string {
209-
return "myprovider"
210-
}
211-
212-
func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
213-
// Implement your provider logic
214-
// - Build API request
215-
// - Make HTTP call
216-
// - Parse response
217-
// - Handle tools if ToolHandler is set
218-
return &ai.Response{}, nil
219-
}
220-
221-
func (p *Provider) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
222-
return nil, fmt.Errorf("streaming not implemented")
223-
}
224-
```
225-
226-
2. Import your provider:
172+
1. Create `ai/yourprovider/yourprovider.go` implementing `ai.Model`.
173+
2. Call `ai.Register("yourprovider", ...)` in `init()`.
174+
3. Add tests in `ai/yourprovider/yourprovider_test.go`.
175+
4. Users enable the provider with a blank import:
227176

228177
```go
229-
import _ "go-micro.dev/v5/ai/myprovider"
178+
import _ "go-micro.dev/v5/ai/yourprovider"
230179
```
231180

181+
We welcome contributions and sponsorships from AI infrastructure companies — see the guide for details.
182+
232183
## Comparison with Other Packages
233184

234185
The ai package follows the same patterns as other go-micro packages:

0 commit comments

Comments
 (0)