Skip to content

Commit

Permalink
genai: update discovery client and make tests more resilient (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben authored Jul 15, 2024
1 parent 15f2209 commit 71888e7
Show file tree
Hide file tree
Showing 4 changed files with 3,406 additions and 3,253 deletions.
3 changes: 3 additions & 0 deletions devtools/generate_discovery_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
# This script generates the "discovery" client for the GenerativeLanguage API.
# It is needed for file upload, which GAPIC clients don't support.

# Run this tool from the `genai` directory of this repository.

# The repo github.com/googleapis/google-api-go-client (corresponding to the Go import
# path google.golang.org/api) contains a program that generates a Go client from
# a discovery doc. It also contains all the clients generated from public discovery
# docs, but the generativelanguage doc isn't public. In fact, retrieving it requires
# an API key. We also don't want to put the discovery client in that repo, because
# we don't want it to be public either; that would only confuse users.


if [[ $GEMINI_API_KEY = '' ]]; then
echo >&2 "need to set GEMINI_API_KEY"
exit 1
Expand Down
10 changes: 4 additions & 6 deletions genai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,8 @@ func TestLive(t *testing.T) {
t.Errorf("got %q, want %q", got, want)
}
gotr := res.Candidates[0].FinishReason
wantr := FinishReasonStop
if gotr != wantr {
t.Errorf("got %s, want %s", gotr, wantr)
if gotr != FinishReasonStop && gotr != FinishReasonMaxTokens {
t.Errorf("got %s, want 'stop' or 'max tokens'", gotr)
}
})
t.Run("max-tokens-streaming", func(t *testing.T) {
Expand All @@ -214,9 +213,8 @@ func TestLive(t *testing.T) {
t.Errorf("got %q, want %q", got, want)
}
gotr := res.Candidates[0].FinishReason
wantr := FinishReasonStop
if gotr != wantr {
t.Errorf("got %s, want %s", gotr, wantr)
if gotr != FinishReasonStop && gotr != FinishReasonMaxTokens {
t.Errorf("got %s, want 'stop' or 'max tokens'", gotr)
}
})
t.Run("count-tokens", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 71888e7

Please sign in to comment.