Skip to content

Commit 287251a

Browse files
averikitschgemini-code-assist[bot]Yuan325
authored
feat: add user agent to embeddings generation (googleapis#2572)
## Description > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>
1 parent d9ebe5d commit 287251a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

internal/embeddingmodels/gemini/gemini.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package gemini
1717
import (
1818
"context"
1919
"fmt"
20+
"net/http"
2021

2122
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
2223
"github.com/googleapis/genai-toolbox/internal/util"
@@ -49,6 +50,16 @@ func (cfg Config) Initialize(ctx context.Context) (embeddingmodels.EmbeddingMode
4950
configs.APIKey = cfg.ApiKey
5051
}
5152

53+
ua, err := util.UserAgentFromContext(ctx)
54+
if err != nil {
55+
return nil, fmt.Errorf("failed to get user agent from context: %w", err)
56+
}
57+
configs.HTTPOptions = genai.HTTPOptions{
58+
Headers: http.Header{
59+
"User-Agent": []string{ua},
60+
},
61+
}
62+
5263
// Create new Gemini API client
5364
client, err := genai.NewClient(ctx, configs)
5465
if err != nil {

0 commit comments

Comments
 (0)