eyurtsev / kor

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

Added more attributes in schema but encountered validation error #225

Closed Feya closed 11 months ago

Feya commented 11 months ago

Error message: validation error for Text id <built-in function id> is not a valid identifier. Please only use lower cased a-z, _ or the digits 0-9 (type=value_error)

Defined schema as

schema = Object(
    id = "travel_destination",
    description = "A source or destination for travel",
    attributes = [
        Text(
            id="city_name",
            description="The name of a city.",
        ),
        Text(
           id='country'
           description='The country of the city.",
        )
    ],
    examples = [])

I got the above error message.

eyurtsev commented 11 months ago

Try upgrading to version 1 -- it should have the validation on id removed

Feya commented 11 months ago

Thank you for your reply. After kor has been updated to v1.0.0, another error occured "UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain" when I tried to use the demo code

    chain = create_extraction_chain(llm,schema,encoder_or_encoder_class='json')
    output = chain.predict_and_parse(text=text)['data']

Could you please show me how to modify code to solve the issue? Thank you very much!

Feya commented 11 months ago

I've changed

output = chain.predict_and_parse(text=text)['data']

to output = chain.run(text=text)['data'] and that works!

Feya commented 11 months ago

reference : https://github.com/gkamradt/langchain-tutorials/blob/main/data_generation/Expert%20Structured%20Output%20(Using%20Kor).ipynb