google / generative-ai-go

Go SDK for Google Generative AI
Apache License 2.0
485 stars 46 forks source link

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

Closed jlcheng closed 2 months ago

jlcheng commented 2 months ago

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.

jmzwcn commented 2 months ago

yes, it is a new bug nearlyl

charieswei commented 2 months ago

Expect the authorities to fix this issue soon

vgjm commented 2 months ago

I met the same problem.

kkdai commented 2 months ago

v0.5.0 to v0.11.0 also reproduce this.

mattthewong commented 2 months ago

Same here.

aicoder01 commented 2 months ago

same problem.

jba commented 2 months ago

Thanks everyone, we're working on a fix.

douglarek commented 2 months ago

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.

Mersanko commented 2 months ago

currently experiencing the same issue.

jba commented 2 months ago

@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 2 months ago

First person to report success gets to close the issue!

jba commented 2 months ago

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 2 months ago

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

nayyara-airlangga commented 2 months ago

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

jlcheng commented 2 months ago

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 2 months ago

Yes, the problem was eventually fixed server-side.