Мой выходной класс имеет тип:
Код: Выделить всё
from langchain_core.pydantic_v1 import BaseModel
class Company(BaseModel):
industry: list[Industry]
customer: list[Customer]
Код: Выделить всё
from aenum import Enum
class Industry(Enum):
_init_ = 'value __doc__'
it = "Information Technology", "All kinds of computer stuff"
agriculture = "Agriculture", "Farming, irrigation, fertilizers etc."
class Customer(Enum):
_init_ = 'value __doc__'
B2C = "B2C", "Companies selling directly to consumers"
B2B = "B2B", "Companies selling to other businesses"
Если я использую файл . with_structured_output() или PydanticOutputParser им не удается передать строки документации от членов перечисления:
Код: Выделить всё
from langchain_core.output_parsers import PydanticOutputParser
parser = PydanticOutputParser(pydantic_object=Company)
parser.get_format_instructions()
# 'The output should be formatted as a JSON instance that conforms to the JSON schema below.
# As an example, for the schema {"properties": {"foo": {"title": "Foo", "description": "a list of strings", "type": "array", "items": {"type": "string"}}}, "required": ["foo"]}
# the object {"foo": ["bar", "baz"]} is a well-formatted instance of the schema. The object {"properties": {"foo": ["bar", "baz"]}} is not well-formatted.
# Here is the output schema:
# ```
# {"properties": {"industry": {"type": "array", "items": {"$ref": "#/definitions/Industry"}}, "customer": {"type": "array", "items": {"$ref": "#/definitions/Customer"}}}, "required": ["industry", "customer"], "definitions": {"Industry": {"title": "Industry", "description": "An enumeration.", "enum": ["Information Technology", "Agriculture"]}, "Customer": {"title": "Customer", "description": "An enumeration.", "enum": ["B2C", "B2B"]}}}
#```'
Подробнее здесь: https://stackoverflow.com/questions/785 ... -langchain