weave icon indicating copy to clipboard operation
weave copied to clipboard

Google genai client with vertexai=True doesn't work

Open matthewrj opened this issue 9 months ago • 0 comments

Running the following taken from the docs with vertexai set to true fails:

from google import genai
import weave

weave.init(project_name="google-genai")
google_client = genai.Client(
    vertexai=True, project="<PROJECT_ID>", location="us-central1"
)


class CityVisitRecommender(weave.Model):
    model: str

    @weave.op()
    def predict(self, city: str) -> str:
        response = google_client.models.generate_content(
            model=self.model,
            contents="You are a helpful assistant meant to suggest all budget-friendly places to visit in a city",
        )
        return response.text


city_recommender = CityVisitRecommender(model="gemini-1.5-flash")
print(city_recommender.predict("New York"))
print(city_recommender.predict("San Francisco"))
print(city_recommender.predict("Los Angeles"))

I get the following error:

Task failed: ValidationError: 1 validation error for EndedCallSchemaForInsert
summary.usage.ObjectRef(entity='pharos-health', project='google-genai', name='CityVisitRecommender', _digest='4gtYrBxPh5Cyuv9IQZJoDGLCDvXDXphIVSSdwDVX4U4', _extra=('attr', 'model')).[key]
  Input should be a valid string [type=string_type, input_value=ObjectRef(entity='pharos-...extra=('attr', 'model')), input_type=ObjectRef]
    For further information visit https://errors.pydantic.dev/2.11/v/string_type

Traces are stuck unfinished and only have inputs, no outputs.

Setting disable_autopatch=True prevents the error.

matthewrj avatar May 14 '25 20:05 matthewrj