Skip to content

Commit 0dee490

Browse files
authored
feat(ai/generativelanguage/apiv1beta): add SetGoogleClientInfo for all clients (#10272)
Add exported SetGoogleClientInfo methods for all clients in the API. Also, add a script to generate the info.go file from the clients.
1 parent c34b840 commit 0dee490

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
3+
# Script to generate info.go.
4+
5+
outfile=${1:-/dev/stdout}
6+
7+
cat <<'EOF' > $outfile
8+
// Copyright 2023 Google LLC
9+
//
10+
// Licensed under the Apache License, Version 2.0 (the "License");
11+
// you may not use this file except in compliance with the License.
12+
// You may obtain a copy of the License at
13+
//
14+
// http://www.apache.org/licenses/LICENSE-2.0
15+
//
16+
// Unless required by applicable law or agreed to in writing, software
17+
// distributed under the License is distributed on an "AS IS" BASIS,
18+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
// See the License for the specific language governing permissions and
20+
// limitations under the License.
21+
22+
// SetGoogleClientInfo sets the name and version of the application in
23+
// the `x-goog-api-client` header passed on each request. Also passes any
24+
// provided key-value pairs. Intended for use by Google-written clients.
25+
//
26+
// Internal use only.
27+
28+
package generativelanguage
29+
30+
//go:generate ./gen_info.sh info.go
31+
32+
EOF
33+
34+
awk '/^func \(c \*[A-Z].*\) setGoogleClientInfo/ {
35+
printf("func (c %s SetGoogleClientInfo(keyval ...string) {\n", $3);
36+
printf(" c.setGoogleClientInfo(keyval...)\n");
37+
printf("}\n\n");
38+
}' *_client.go >> $outfile
39+
40+
gofmt -w $outfile

ai/generativelanguage/apiv1beta/info.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@
2020

2121
package generativelanguage
2222

23+
//go:generate ./gen_info.sh info.go
24+
25+
func (c *DiscussClient) SetGoogleClientInfo(keyval ...string) {
26+
c.setGoogleClientInfo(keyval...)
27+
}
28+
29+
func (c *FileClient) SetGoogleClientInfo(keyval ...string) {
30+
c.setGoogleClientInfo(keyval...)
31+
}
32+
2333
func (c *GenerativeClient) SetGoogleClientInfo(keyval ...string) {
2434
c.setGoogleClientInfo(keyval...)
2535
}
36+
37+
func (c *ModelClient) SetGoogleClientInfo(keyval ...string) {
38+
c.setGoogleClientInfo(keyval...)
39+
}
40+
41+
func (c *PermissionClient) SetGoogleClientInfo(keyval ...string) {
42+
c.setGoogleClientInfo(keyval...)
43+
}
44+
45+
func (c *RetrieverClient) SetGoogleClientInfo(keyval ...string) {
46+
c.setGoogleClientInfo(keyval...)
47+
}
48+
49+
func (c *TextClient) SetGoogleClientInfo(keyval ...string) {
50+
c.setGoogleClientInfo(keyval...)
51+
}

0 commit comments

Comments
 (0)