Skip to content

Commit f69f01d

Browse files
authored
genai: add FileState (#111)
This also required updating the gensupport package.
1 parent 47de201 commit f69f01d

File tree

8 files changed

+6276
-9177
lines changed

8 files changed

+6276
-9177
lines changed

genai/config.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,14 @@ types:
164164
name: URI
165165
MimeType:
166166
name: MIMEType
167-
State:
168-
omit: true
169-
167+
File_State:
168+
name: FileState
169+
docVerb: represents
170+
protoPrefix: File
171+
veneerPrefix: FileState
172+
valueNames:
173+
File_STATE_UNSPECIFIED: FileStateUnspecified
174+
170175
GenerateContentResponse_UsageMetadata:
171176
name: UsageMetadata
172177
fields:

genai/generativelanguagepb_veneer.gen.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ type File struct {
361361
Sha256Hash []byte
362362
// Output only. The uri of the `File`.
363363
URI string
364+
// Output only. Processing state of the File.
365+
State FileState
364366
}
365367

366368
func (v *File) toProto() *pb.File {
@@ -374,6 +376,7 @@ func (v *File) toProto() *pb.File {
374376
SizeBytes: v.SizeBytes,
375377
Sha256Hash: v.Sha256Hash,
376378
Uri: v.URI,
379+
State: pb.File_State(v.State),
377380
}
378381
}
379382

@@ -388,6 +391,7 @@ func (File) fromProto(p *pb.File) *File {
388391
SizeBytes: p.SizeBytes,
389392
Sha256Hash: p.Sha256Hash,
390393
URI: p.Uri,
394+
State: FileState(p.State),
391395
}
392396
}
393397

@@ -419,6 +423,34 @@ func (FileData) fromProto(p *pb.FileData) *FileData {
419423
}
420424
}
421425

426+
// FileState represents states for the lifecycle of a File.
427+
type FileState int32
428+
429+
const (
430+
// FileStateUnspecified means the default value. This value is used if the state is omitted.
431+
FileStateUnspecified FileState = 0
432+
// FileStateProcessing means file is being processed and cannot be used for inference yet.
433+
FileStateProcessing FileState = 1
434+
// FileStateActive means file is processed and available for inference.
435+
FileStateActive FileState = 2
436+
// FileStateFailed means file failed processing.
437+
FileStateFailed FileState = 10
438+
)
439+
440+
var namesForFileState = map[FileState]string{
441+
FileStateUnspecified: "FileStateUnspecified",
442+
FileStateProcessing: "FileStateProcessing",
443+
FileStateActive: "FileStateActive",
444+
FileStateFailed: "FileStateFailed",
445+
}
446+
447+
func (v FileState) String() string {
448+
if n, ok := namesForFileState[v]; ok {
449+
return n
450+
}
451+
return fmt.Sprintf("FileState(%d)", v)
452+
}
453+
422454
// FinishReason is defines the reason why the model stopped generating tokens.
423455
type FinishReason int32
424456

genai/internal/generativelanguage/v1beta/generativelanguage-api.json

Lines changed: 3550 additions & 3498 deletions
Large diffs are not rendered by default.

genai/internal/generativelanguage/v1beta/generativelanguage-gen.go

Lines changed: 2642 additions & 5674 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

genai/internal/gensupport/README

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
This directory was copied from github.com/googleapis/google-api-go-client/internal/gensupport.
22
It is needed for the discovery client in ../generativelanguage.
3+
4+
To update, first clone github.com/googleapis/google-api-go-client
5+
into a directory we will call DIR below.
6+
Then, from the repo root:
7+
```
8+
rm genai/internal/gensupport/*.go
9+
cp $DIR/internal/gensupport/*.go genai/internal/gensupport
10+
```
11+
Then edit the params.go and resumable.go files to replace the reference to `internal.Version`
12+
with the literal string from $DIR/internal/version.go, and remove the import of `internal`.

genai/internal/gensupport/params.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package gensupport
66

77
import (
8+
"net/http"
89
"net/url"
910

1011
"google.golang.org/api/googleapi"
@@ -55,3 +56,22 @@ func SetOptions(u URLParams, opts ...googleapi.CallOption) {
5556
u.Set(o.Get())
5657
}
5758
}
59+
60+
// SetHeaders sets common headers for all requests. The keyvals header pairs
61+
// should have a corresponding value for every key provided. If there is an odd
62+
// number of keyvals this method will panic.
63+
func SetHeaders(userAgent, contentType string, userHeaders http.Header, keyvals ...string) http.Header {
64+
reqHeaders := make(http.Header)
65+
reqHeaders.Set("x-goog-api-client", "gl-go/"+GoVersion()+" gdcl/"+"0.179.0")
66+
for i := 0; i < len(keyvals); i = i + 2 {
67+
reqHeaders.Set(keyvals[i], keyvals[i+1])
68+
}
69+
reqHeaders.Set("User-Agent", userAgent)
70+
if contentType != "" {
71+
reqHeaders.Set("Content-Type", contentType)
72+
}
73+
for k, v := range userHeaders {
74+
reqHeaders[k] = v
75+
}
76+
return reqHeaders
77+
}

genai/internal/gensupport/params_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package gensupport
66

77
import (
8+
"net/http"
89
"testing"
910

1011
"google.golang.org/api/googleapi"
@@ -18,3 +19,15 @@ func TestSetOptionsGetMulti(t *testing.T) {
1819
t.Fatalf("URLParams.Encode() = %q, want %q", got, want)
1920
}
2021
}
22+
23+
func TestSetHeaders(t *testing.T) {
24+
userAgent := "google-api-go-client/123"
25+
contentType := "application/json"
26+
userHeaders := make(http.Header)
27+
userHeaders.Set("baz", "300")
28+
got := SetHeaders(userAgent, contentType, userHeaders, "foo", "100", "bar", "200")
29+
30+
if len(got) != 6 {
31+
t.Fatalf("SetHeaders() = %q, want len(6)", got)
32+
}
33+
}

genai/internal/gensupport/resumable.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"sync"
1515
"time"
1616

17-
"github.com/google/generative-ai-go/genai/internal"
1817
"github.com/google/uuid"
1918
)
2019

@@ -83,7 +82,7 @@ func (rx *ResumableUpload) doUploadRequest(ctx context.Context, data io.Reader,
8382

8483
// TODO(b/274504690): Consider dropping gccl-invocation-id key since it
8584
// duplicates the X-Goog-Gcs-Idempotency-Token header (added in v0.115.0).
86-
baseXGoogHeader := "gl-go/" + GoVersion() + " gdcl/" + internal.Version
85+
baseXGoogHeader := "gl-go/" + GoVersion() + " gdcl/" + "0.179.0"
8786
invocationHeader := fmt.Sprintf("gccl-invocation-id/%s gccl-attempt-count/%d", rx.invocationID, rx.attempts)
8887
req.Header.Set("X-Goog-Api-Client", strings.Join([]string{baseXGoogHeader, invocationHeader}, " "))
8988

0 commit comments

Comments
 (0)