-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
83 lines (83 loc) · 2.68 KB
/
doc.go
File metadata and controls
83 lines (83 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Package llmprovider provides LLM provider abstractions and utilities for Go applications.
//
// This package defines the core LLMProvider interface and common utilities for
// building LLM provider implementations, including circuit breakers, health monitoring,
// retry logic, and lazy loading.
//
// # Core Components
//
// - LLMProvider: Interface that all provider implementations must satisfy
// - CircuitBreaker: Fault tolerance for provider failures
// - HealthMonitor: Health monitoring and status tracking
// - RetryConfig: Configurable retry logic with exponential backoff
// - LazyProvider: Lazy initialization of providers
//
// # Provider Interface
//
// All providers implement the LLMProvider interface:
//
// type LLMProvider interface {
// Complete(ctx context.Context, req *models.LLMRequest) (*models.LLMResponse, error)
// CompleteStream(ctx context.Context, req *models.LLMRequest) (<-chan *models.LLMResponse, error)
// HealthCheck() error
// GetCapabilities() *models.ProviderCapabilities
// ValidateConfig(config map[string]interface{}) (bool, []string)
// }
//
// # Circuit Breaker Pattern
//
// The circuit breaker prevents cascading failures when providers are unhealthy:
//
// - Closed: Normal operation, requests pass through
// - Open: Provider is failing, requests are short-circuited
// - Half-Open: Testing if provider has recovered
//
// # Health Monitoring
//
// HealthMonitor tracks provider health with configurable thresholds and intervals,
// providing real-time health status and automatic failure detection.
//
// # Retry Logic
//
// Configurable retry with exponential backoff, jitter, and HTTP status code detection
// for retryable errors (429, 500, 502, 503, 504).
//
// # Example Usage
//
// import (
// "context"
// "digital.vasic.llmprovider"
// "digital.vasic.llmprovider/pkg/models"
// )
//
// func main() {
// provider := // create your provider implementation
// cb := llmprovider.NewDefaultCircuitBreaker("my-provider", provider)
//
// req := &models.LLMRequest{
// Prompt: "Hello, world!",
// MaxTokens: 100,
// }
//
// resp, err := cb.Complete(context.Background(), req)
// if err != nil {
// log.Fatal(err)
// }
//
// fmt.Println(resp.Text)
// }
//
// # Dependencies
//
// This module depends on:
//
// - digital.vasic.models: For LLMRequest, LLMResponse, and ProviderCapabilities types
// - github.com/sirupsen/logrus: For logging in circuit breaker
// - Standard library: context, sync, time, net/http, etc.
//
// # Module Information
//
// Module path: digital.vasic.llmprovider
// License: MIT
// Repository: https://github.com/vasic-digital/llmprovider
package llmprovider