eyurtsev / kor

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

No validation or parsing on pydantic v2 #268

Closed Brandl closed 6 months ago

Brandl commented 7 months ago

I have touched on this in #228, though this might be an entirely unrelated issue:

I wrote a short progam, but there are neither errors nor parsed entities in the output, so I needed to do parsing myself:

class EntityExtraction(BaseModel):
    name: Optional[List[str]] = Field(
        default=None,
        description="names (e.g., 'Luke Skywalker', 'Obi-Wan Kenobi')."
    )
    location: Optional[List[str]] = Field(
        default=None,
        description="Location (e.g., 'Death Star', 'Coruscant')."
    )

schema, validator = from_pydantic(EntityExtraction)
chain = create_extraction_chain(llm, schema, encoder_or_encoder_class="json", validator=validator)
json_encoder = JSONEncoder(use_tags=True)
result = chain.invoke(text_input.text)
return json_encoder.decode(result['text']['raw'])

Is this a bug, or am I missing something obvious here?