Skip to content

Commit 2c8fad4

Browse files
committed
feat: add Type() to Provider interface and configurable instance Name
1 parent b97c9d4 commit 2c8fad4

File tree

8 files changed

+39
-5
lines changed

8 files changed

+39
-5
lines changed

bridge.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ func newInterceptionProcessor(p provider.Provider, cbs *circuitbreaker.ProviderC
198198
InitiatorID: actor.ID,
199199
Metadata: actor.Metadata,
200200
Model: interceptor.Model(),
201-
Provider: p.Name(),
201+
Provider: p.Type(),
202+
ProviderName: p.Name(),
202203
UserAgent: r.UserAgent(),
203204
Client: string(client),
204205
ClientSessionID: sessionID,

config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const (
99
)
1010

1111
type Anthropic struct {
12+
// Name is the provider instance name. If empty, defaults to ProviderAnthropic.
13+
Name string
1214
BaseURL string
1315
Key string
1416
APIDumpDir string
@@ -32,6 +34,8 @@ type AWSBedrock struct {
3234
}
3335

3436
type OpenAI struct {
37+
// Name is the provider instance name. If empty, defaults to ProviderOpenAI.
38+
Name string
3539
BaseURL string
3640
Key string
3741
APIDumpDir string
@@ -69,6 +73,8 @@ func DefaultCircuitBreaker() CircuitBreaker {
6973
}
7074

7175
type Copilot struct {
76+
// Name is the provider instance name. If empty, defaults to ProviderCopilot.
77+
Name string
7278
BaseURL string
7379
APIDumpDir string
7480
CircuitBreaker *CircuitBreaker

internal/testutil/mockprovider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type MockProvider struct {
1717
InterceptorFunc func(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (intercept.Interceptor, error)
1818
}
1919

20+
func (m *MockProvider) Type() string { return m.Name_ }
2021
func (m *MockProvider) Name() string { return m.Name_ }
2122
func (m *MockProvider) BaseURL() string { return m.URL }
2223
func (m *MockProvider) RoutePrefix() string { return fmt.Sprintf("/%s", m.Name_) }

provider/anthropic.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ var anthropicIsFailure = func(statusCode int) bool {
4848
}
4949

5050
func NewAnthropic(cfg config.Anthropic, bedrockCfg *config.AWSBedrock) *Anthropic {
51+
if cfg.Name == "" {
52+
cfg.Name = config.ProviderAnthropic
53+
}
5154
if cfg.BaseURL == "" {
5255
cfg.BaseURL = "https://api.anthropic.com/"
5356
}
@@ -68,10 +71,14 @@ func NewAnthropic(cfg config.Anthropic, bedrockCfg *config.AWSBedrock) *Anthropi
6871
}
6972
}
7073

71-
func (p *Anthropic) Name() string {
74+
func (p *Anthropic) Type() string {
7275
return config.ProviderAnthropic
7376
}
7477

78+
func (p *Anthropic) Name() string {
79+
return p.cfg.Name
80+
}
81+
7582
func (p *Anthropic) RoutePrefix() string {
7683
return fmt.Sprintf("/%s", p.Name())
7784
}

provider/copilot.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ type Copilot struct {
5252
var _ Provider = &Copilot{}
5353

5454
func NewCopilot(cfg config.Copilot) *Copilot {
55+
if cfg.Name == "" {
56+
cfg.Name = config.ProviderCopilot
57+
}
5558
if cfg.BaseURL == "" {
5659
cfg.BaseURL = copilotBaseURL
5760
}
@@ -67,10 +70,14 @@ func NewCopilot(cfg config.Copilot) *Copilot {
6770
}
6871
}
6972

70-
func (p *Copilot) Name() string {
73+
func (p *Copilot) Type() string {
7174
return config.ProviderCopilot
7275
}
7376

77+
func (p *Copilot) Name() string {
78+
return p.cfg.Name
79+
}
80+
7481
func (p *Copilot) BaseURL() string {
7582
return p.cfg.BaseURL
7683
}

provider/openai.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type OpenAI struct {
3737
var _ Provider = &OpenAI{}
3838

3939
func NewOpenAI(cfg config.OpenAI) *OpenAI {
40+
if cfg.Name == "" {
41+
cfg.Name = config.ProviderOpenAI
42+
}
4043
if cfg.BaseURL == "" {
4144
cfg.BaseURL = "https://api.openai.com/v1/"
4245
}
@@ -56,10 +59,14 @@ func NewOpenAI(cfg config.OpenAI) *OpenAI {
5659
}
5760
}
5861

59-
func (p *OpenAI) Name() string {
62+
func (p *OpenAI) Type() string {
6063
return config.ProviderOpenAI
6164
}
6265

66+
func (p *OpenAI) Name() string {
67+
return p.cfg.Name
68+
}
69+
6370
func (p *OpenAI) RoutePrefix() string {
6471
// Route prefix includes version to match default OpenAI base URL.
6572
// More detailed explanation: https://github.com/coder/aibridge/pull/174#discussion_r2782320152

provider/provider.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ var UnknownRoute = errors.New("unknown route")
4444
// OpenAI includes the version '/v1' in the base url while Anthropic does not.
4545
// More details/examples: https://github.com/coder/aibridge/pull/174#discussion_r2782320152
4646
type Provider interface {
47-
// Name returns the provider's name.
47+
// Type returns the provider type: "copilot", "openai", or "anthropic".
48+
// Multiple provider instances can share the same type.
49+
Type() string
50+
// Name returns the provider instance name.
51+
// Defaults to Type() when not explicitly configured.
4852
Name() string
4953
// BaseURL defines the base URL endpoint for this provider's API.
5054
BaseURL() string

recorder/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type InterceptionRecord struct {
3333
Metadata Metadata
3434
Model string
3535
Provider string
36+
ProviderName string
3637
StartedAt time.Time
3738
ClientSessionID *string
3839
Client string

0 commit comments

Comments
 (0)