In the Tagging and Extraction chapter of this course, we use pydantic and typing to define the function definition. What I’m noticing is that the function definition of the notebook used in the course is very different from the function definition that I get when I use my own notebook using my own installed version of langchain.
For example, when I run this: print(json.dumps(convert_pydantic_to_openai_function(Information), indent=4))
, in the course notebook I get this:
{
"name": "Information",
"description": "Information to extract.",
"parameters": {
"title": "Information",
"description": "Information to extract.",
"type": "object",
"properties": {
"people": {
"title": "People",
"description": "List of info about people",
"type": "array",
"items": {
"title": "Person",
"description": "Information about a person.",
"type": "object",
"properties": {
"name": {
"title": "Name",
"description": "person's name",
"type": "string"
},
"age": {
"title": "Age",
"description": "person's age",
"type": "integer"
}
},
"required": [
"name"
]
}
}
},
"required": [
"people"
]
}
}
In my local notebook using langchain version 0.0.316, I get this:
{
"name": "Information",
"description": "Information to extract.",
"parameters": {
"$defs": {
"Person": {
"description": "Information about a person.",
"properties": {
"name": {
"description": "person's name",
"title": "Name",
"type": "string"
},
"age": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"description": "person's age",
"title": "Age"
}
},
"required": [
"name",
"age"
],
"title": "Person",
"type": "object"
}
},
"description": "Information to extract.",
"properties": {
"people": {
"description": "List of info about people",
"items": {
"description": "Information about a person.",
"properties": {
"name": {
"description": "person's name",
"title": "Name",
"type": "string"
},
"age": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"description": "person's age",
"title": "Age"
}
},
"required": [
"name",
"age"
],
"title": "Person",
"type": "object"
},
"title": "People",
"type": "array"
}
},
"required": [
"people"
],
"title": "Information",
"type": "object"
}
}
Notice the big difference between the 2. My local version of langchain is a lot more verbose, as it includes $def
and the shape of age
is also very different.
Anyone know why there’s a difference? Both function definitions seem to work, but are there any pitfalls of either? The more verbose one will use up a lot more tokens, so I prefer the more concise one. Any way to get langchain version 0.0.316 to behave like the concise one?