Skip to content

Commit bce2320

Browse files
committed
Also add the provider and model with using the gateway
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent ed21eba commit bce2320

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

pkg/httpclient/client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ func WithProxiedBaseURL(value string) Opt {
5454
}
5555
}
5656

57+
func WithProvider(provider string) Opt {
58+
return func(o *HTTPOptions) {
59+
o.Header.Set("X-Cagent-Provider", provider)
60+
}
61+
}
62+
63+
func WithModel(model string) Opt {
64+
return func(o *HTTPOptions) {
65+
o.Header.Set("X-Cagent-Model", model)
66+
}
67+
}
68+
5769
type userAgentTransport struct {
5870
httpOptions HTTPOptions
5971
rt http.RoundTripper

pkg/model/provider/anthropic/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
112112
option.WithBaseURL(gateway),
113113
option.WithHTTPClient(httpclient.NewHTTPClient(
114114
httpclient.WithProxiedBaseURL(defaultsTo(cfg.BaseURL, "https://api.anthropic.com/")),
115+
httpclient.WithProvider(cfg.Provider),
116+
httpclient.WithModel(cfg.Model),
115117
)),
116118
), nil
117119
}

pkg/model/provider/gemini/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
8484
Backend: genai.BackendGeminiAPI,
8585
HTTPClient: httpclient.NewHTTPClient(
8686
httpclient.WithProxiedBaseURL(defaultsTo(cfg.BaseURL, "https://generativelanguage.googleapis.com/")),
87+
httpclient.WithProvider(cfg.Provider),
88+
httpclient.WithModel(cfg.Model),
8789
),
8890
HTTPOptions: genai.HTTPOptions{
8991
BaseURL: gateway,

pkg/model/provider/openai/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
111111
openaiConfig.BaseURL = gateway + "/v1"
112112
openaiConfig.HTTPClient = httpclient.NewHTTPClient(
113113
httpclient.WithProxiedBaseURL(defaultsTo(cfg.BaseURL, "https://api.openai.com/v1")),
114+
httpclient.WithProvider(cfg.Provider),
115+
httpclient.WithModel(cfg.Model),
114116
)
115117

116118
return openai.NewClientWithConfig(openaiConfig), nil

0 commit comments

Comments
 (0)