Skip to content

Commit e6d4d47

Browse files
authored
Merge pull request #894 from dgageot/generating-titles
Generating titles
2 parents c0de2cf + a93b97f commit e6d4d47

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

pkg/model/provider/anthropic/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,21 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
115115
baseURL := fmt.Sprintf("%s://%s%s/", url.Scheme, url.Host, url.Path)
116116

117117
// Configure a custom HTTP client to inject headers and query params used by the Gateway.
118-
httpClient := httpclient.NewHTTPClient(
118+
httpOptions := []httpclient.Opt{
119119
httpclient.WithProxiedBaseURL(defaultsTo(cfg.BaseURL, "https://api.anthropic.com/")),
120120
httpclient.WithProvider(cfg.Provider),
121121
httpclient.WithModel(cfg.Model),
122122
httpclient.WithQuery(url.Query()),
123-
)
123+
}
124+
if globalOptions.GeneratingTitle() {
125+
httpOptions = append(httpOptions, httpclient.WithHeader("X-Cagent-GeneratingTitle", "1"))
126+
}
124127

125128
client := anthropic.NewClient(
126129
option.WithAuthToken(authToken),
127130
option.WithAPIKey(authToken),
128131
option.WithBaseURL(baseURL),
129-
option.WithHTTPClient(httpClient),
132+
option.WithHTTPClient(httpclient.NewHTTPClient(httpOptions...)),
130133
)
131134

132135
return client, nil

pkg/model/provider/clone.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func CloneWithOptions(ctx context.Context, base Provider, opts ...options.Opt) P
1616
// Preserve existing options, then apply overrides. Later opts take precedence.
1717
baseOpts := options.FromModelOptions(config.ModelOptions)
1818
mergedOpts := append(baseOpts, opts...)
19+
mergedOpts = append(mergedOpts, options.WithGeneratingTitle())
1920

2021
clone, err := New(ctx, &config.ModelConfig, config.Env, mergedOpts...)
2122
if err != nil {

pkg/model/provider/gemini/client.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,20 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
8787
}
8888
baseURL := fmt.Sprintf("%s://%s%s/", url.Scheme, url.Host, url.Path)
8989

90+
httpOptions := []httpclient.Opt{
91+
httpclient.WithProxiedBaseURL(defaultsTo(cfg.BaseURL, "https://generativelanguage.googleapis.com/")),
92+
httpclient.WithProvider(cfg.Provider),
93+
httpclient.WithModel(cfg.Model),
94+
httpclient.WithQuery(url.Query()),
95+
}
96+
if globalOptions.GeneratingTitle() {
97+
httpOptions = append(httpOptions, httpclient.WithHeader("X-Cagent-GeneratingTitle", "1"))
98+
}
99+
90100
return genai.NewClient(ctx, &genai.ClientConfig{
91-
APIKey: authToken,
92-
Backend: genai.BackendGeminiAPI,
93-
HTTPClient: httpclient.NewHTTPClient(
94-
httpclient.WithProxiedBaseURL(defaultsTo(cfg.BaseURL, "https://generativelanguage.googleapis.com/")),
95-
httpclient.WithProvider(cfg.Provider),
96-
httpclient.WithModel(cfg.Model),
97-
httpclient.WithQuery(url.Query()),
98-
),
101+
APIKey: authToken,
102+
Backend: genai.BackendGeminiAPI,
103+
HTTPClient: httpclient.NewHTTPClient(httpOptions...),
99104
HTTPOptions: genai.HTTPOptions{
100105
BaseURL: baseURL,
101106
Headers: http.Header{

pkg/model/provider/openai/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,20 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
106106
baseURL := fmt.Sprintf("%s://%s%s/v1/", url.Scheme, url.Host, url.Path)
107107

108108
// Configure a custom HTTP client to inject headers and query params used by the Gateway.
109-
httpClient := httpclient.NewHTTPClient(
109+
httpOptions := []httpclient.Opt{
110110
httpclient.WithProxiedBaseURL(defaultsTo(cfg.BaseURL, "https://api.openai.com/v1")),
111111
httpclient.WithProvider(cfg.Provider),
112112
httpclient.WithModel(cfg.Model),
113113
httpclient.WithQuery(url.Query()),
114-
)
114+
}
115+
if globalOptions.GeneratingTitle() {
116+
httpOptions = append(httpOptions, httpclient.WithHeader("X-Cagent-GeneratingTitle", "1"))
117+
}
115118

116119
client := openai.NewClient(
117120
option.WithAPIKey(authToken),
118121
option.WithBaseURL(baseURL),
119-
option.WithHTTPClient(httpClient),
122+
option.WithHTTPClient(httpclient.NewHTTPClient(httpOptions...)),
120123
)
121124

122125
return &client, nil

pkg/model/provider/options/options.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
type ModelOptions struct {
88
gateway string
99
structuredOutput *latest.StructuredOutput
10+
generatingTitle bool
1011
}
1112

1213
func (c *ModelOptions) Gateway() string {
@@ -17,6 +18,10 @@ func (c *ModelOptions) StructuredOutput() *latest.StructuredOutput {
1718
return c.structuredOutput
1819
}
1920

21+
func (c *ModelOptions) GeneratingTitle() bool {
22+
return c.generatingTitle
23+
}
24+
2025
type Opt func(*ModelOptions)
2126

2227
func WithGateway(gateway string) Opt {
@@ -31,6 +36,12 @@ func WithStructuredOutput(structuredOutput *latest.StructuredOutput) Opt {
3136
}
3237
}
3338

39+
func WithGeneratingTitle() Opt {
40+
return func(cfg *ModelOptions) {
41+
cfg.generatingTitle = true
42+
}
43+
}
44+
3445
// FromModelOptions converts a concrete ModelOptions value into a slice of
3546
// Opt configuration functions. Later Opts override earlier ones when applied.
3647
func FromModelOptions(m ModelOptions) []Opt {
@@ -41,5 +52,8 @@ func FromModelOptions(m ModelOptions) []Opt {
4152
if m.structuredOutput != nil {
4253
out = append(out, WithStructuredOutput(m.structuredOutput))
4354
}
55+
if m.generatingTitle {
56+
out = append(out, WithGeneratingTitle())
57+
}
4458
return out
4559
}

0 commit comments

Comments
 (0)