-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
So just using VertexAI libraries I can have the option to get back null values. However, when writing the equivalent code using pydanticAI I never get back null values:
Using vertex libraries:
from vertexai.generative_models import GenerativeModel, GenerationConfig
response_schema = {
"type": "object",
"properties": {
"age": {
"type": "INTEGER", "nullable": True
}
}
}
generation_config = GenerationConfig(
response_mime_type="application/json",
response_schema=response_schema
)
model = GenerativeModel("gemini-1.5-flash")
result = model.generate_content(
"The man was very old. what is the age of the old man?",
generation_config=generation_config
)
print(result.candidates[0].content.parts[0].text)
# "{\"age\": null}"
Using pydanticAI:
from pydantic_ai import Agent
from pydantic import BaseModel
from pydantic_ai.models.vertexai import VertexAIModel
class AgeModel(BaseModel):
age: int | None = None
gemini_model = VertexAIModel('gemini-1.5-flash')
prompt = "The man was very old. what is the age of the old man?"
agent = Agent(gemini_model, result_type=AgeModel)
age = agent.run_sync(prompt)
print(age.data)
# age=100
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working