GoogleCloudPlatform / vertex-ai-samples

Notebooks, code samples, sample apps, and other resources that demonstrate how to use, develop and manage machine learning and generative AI workflows using Google Cloud Vertex AI.
https://cloud.google.com/vertex-ai
Apache License 2.0
119 stars 28 forks source link

TypeError: GenerationConfig.__init__() got an unexpected keyword argument 'response_schema' #3322

Closed tytung2020 closed 1 month ago

tytung2020 commented 4 months ago

Expected Behavior

run without error, as the code below is from vertexai documentation: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/control-generated-output

Actual Behavior

returns the error : TypeError: GenerationConfig.init() got an unexpected keyword argument 'response_schema'

Steps to Reproduce the Problem

just run this code with your credentials

import vertexai
from dotenv import load_dotenv
import os
from vertexai.generative_models import GenerationConfig, GenerativeModel

# Load environment variables
load_dotenv()

# Set Google Application Credentials
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = ...

# Initialize Vertex AI
project_id = "..."
vertexai.init(project=project_id, location="us-central1")

response_schema = {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "recipe_name": {
                "type": "string",
            },
        },
        "required": ["recipe_name"],
    },
}

model = GenerativeModel("gemini-1.5-pro-001")

response = model.generate_content(
    "List a few popular cookie recipes",
    generation_config=GenerationConfig(
        response_mime_type="application/json", response_schema=response_schema
    ),
)

print(response.text)

Specifications

rohitpk commented 3 months ago

@tytung2020 , were you able to overcome this?

analyticsrepo01 commented 3 months ago

have u tried to upgrade vertex AI version pip3 install --upgrade "google-cloud-aiplatform" pip install --upgrade "google-cloud-aiplatform"