-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vertexai: converting pydantic to vertex function breaks with allOf #95
Comments
Yep. Unfortunately it's an issue with underlying library: Pydantic models need to be constructed in a very specific way to avoid unsupported properties with Schema. Let me check how model can be constructed. |
It's related with: pydantic/pydantic#3896 And this generates a schema without allOf: from typings import Annotated
from langchain_core.pydantic_v1 import BaseModel, Field
class Node(BaseModel):
id: str
type: str
class Relationship(BaseModel):
source: Node
target: Node = Annotated[Node, "foo"]
Relationship.schema() |
what schema does that generate? |
{
"title": "Relationship",
"type": "object",
"properties": {
"source": {
"title": "Node",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
},
"target": {
"title": "Node",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
}
},
"required": [
"source",
"target"
]
} |
so the description is ignored altogether? |
Yep you are right, missed that. And my example was incorrect. So currently you can use that approach: class Node(BaseModel):
"""foo"""
id: str
type: str
class Relationship(BaseModel):
source: Node
target: Node or if class will be used for different fields: class Node(BaseModel):
id: str
type: str
class NodeTarget(Node):
"""foo"""
class Relationship(BaseModel):
source: Node
target: NodeTarget which produces: {
"title": "Relationship",
"type": "object",
"properties": {
"source": {
"title": "Node",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
},
"target": {
"title": "NodeTarget",
"description": "foo",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
}
},
"required": [
"source",
"target"
]
} |
pydantic json schema will include an allOf if a nested object has a description. for example
generates
notice difference between 'source' and 'target'.
When trying to use function-calling, the allOf leads to a protobuf error
using
The text was updated successfully, but these errors were encountered: