google/generative-ai-go

proto: (line 34:3): unknown field "usageMetadata"

jlcheng opened this issue · 16 comments

Description of the bug:

When using the StartChat() and SendMessage() API, one gets the "proto: (line 34:3): unknown field "usageMetadata"
" error.

You can reproduce the problem with:

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/google/generative-ai-go/genai"
	"google.golang.org/api/option"
)

func main() {
	ctx := context.Background()
	client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY")))
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()
	model := client.GenerativeModel("gemini-1.0-pro")
	cs := model.StartChat()

	msg := "hello"
	fmt.Printf("== Me: %s\n== Model:\n", msg)
	_, err = cs.SendMessage(ctx, genai.Text(msg))
	if err != nil {
		log.Fatal(err)
	}
}

Actual vs expected behavior:

Actual behavior:
The SDK returns an error

Expected behavior:
No errors from the SDK.

Any other information you'd like to share?

Maybe the underlying problem has to do with a new field added to https://github.com/googleapis/googleapis/blob/master/google/ai/generativelanguage/v1beta/generative_service.proto?

The error message suggests it may be a new field named "usageMetadata" on the "GenerateContentResponse" message. I don't see it referenced in the generative_service.proto, so maybe it's not published yet? I am reporting it here mainly because it surfaced through the Go SDK.

yes, it is a new bug nearlyl

Expect the authorities to fix this issue soon

vgjm commented

I met the same problem.

v0.5.0 to v0.11.0 also reproduce this.

Same here.

same problem.

jba commented

Thanks everyone, we're working on a fix.

I don't know why this issue was marked closed after submitting a commit. Does everyone need to update to the latest master branch? Shouldn't the correct solution be to publish a release and wait for confirmation from the issue raiser? A normal release of a Golang SDK, for some reason, inexplicably not working. Seriously, this is so frustrating.

currently experiencing the same issue.

jba commented

@douglarek Good point, I should not have written "Fixes" in the PR.
I've now pushed the v0.11.1 tag.
Please update your projects with go get github.com/google/generative-ai-go@v0.11.1.

jba commented

First person to report success gets to close the issue!

jba commented

Seriously, this is so frustrating.

@douglarek, I totally agree. But this cuts across languages. It's an issue with the underlying service, and trust me, Google is taking this very seriously.

jba commented

Also, the fix will work for any future problems of a similar kind (service proto fields being sent before clients know about them).

@jba just tested the fix using different prompts. It works fine now. Nice idea on future-proofing for unknown fields from upstream

FWIW, the Go program I used no longer has this error even without recompiling the code. It is possible that something upstream changed as well. Regardless, I can no longer reproduce the problem. Many thanks for everyone who helped fix this!

jba commented

Yes, the problem was eventually fixed server-side.