eyurtsev / kor

LLM(😽)
https://eyurtsev.github.io/kor/
MIT License
1.6k stars 88 forks source link

AttributeError: 'FieldInfo' object has no attribute 'field_info' #209

Closed intellectoglobal closed 1 year ago

intellectoglobal commented 1 year ago

attributeError Traceback (most recent call last)

Cell In[12], line 1

----> 1 testschema, test_validator = from_pydantic(

  2         Model,

  3         description="test",

  4 
 13         many=False,

 14     )

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/kor/adapters.py:151, in from_pydantic(model_class, description, examples, many)

133 def from_pydantic(

134     model_class: Type[BaseModel],

135     *,

(...)

138     many: bool = False,

139 ) -> Tuple[Object, Validator]:

140     """Convert a pydantic model to Kor internal representation.

141

142     Args:

(...)

149         A tuple of the Kor internal representation of the model and a validator.

150     """

--> 151 schema = _translate_pydantic_to_kor(

152         model_class,

153         description=description,

154         examples=examples,

155         many=many,

156     )

157     validator = PydanticValidator(model_class, schema.many)

158     return schema, validator

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/kor/adapters.py:51, in _translate_pydantic_to_kor(model_class, name, description, examples, many)

 49 attributes: List[Union[ExtractionSchemaNode, Selection, "Object"]] = []

 50 for field_name, field in model_class.__fields__.items():

---> 51 field_info = field.field_info

 52     extra = field_info.extra

 53     if "examples" in extra:

AttributeError: 'FieldInfo' object has no attribute 'field_info'

my code : something wrong with model : class Test(BaseModel): abc: str = Field( ..., description="test.", examples=[

        ("hi test", "test"),
    ],
)
cdfc: str = Field(
    ...,
    description=" test calculation.",
    examples=[
        (" Risk-Based ", "Risk"),
    ],
)

this is dummy code but you get the idea of implementation and structure, not sure what am missing. help me out.
intellectoglobal commented 1 year ago

I tested it in 3.9 it working, I will test it again with 3.10

eyurtsev commented 1 year ago

This looks like a pydantic issue -- I assume you're using pydantic 2 rather than pydantic 1? Kor is not pydantic v2 compatible yet

eyurtsev commented 1 year ago

https://github.com/eyurtsev/kor/issues/206

vignxs commented 1 year ago

you're right, it was pydantic v2.2 was causing the issue and then I downgraded it to 1.10, it started working