Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotImplementedError: parse_raw is not supported for pydantic 2 - how to do it with Pydantic 2? #228

Open
ChristianWeyer opened this issue Sep 22, 2023 · 4 comments

Comments

@ChristianWeyer
Copy link

Hi!

based on this:
https://eyurtsev.github.io/kor/schema_serialization.html#deserialization

I am trying to deserialize from a JSON schema into an Object like this:

with open("schema.json", "r") as f:
    schema = Object.parse_raw(f.read())

Here, I get an error:

python3.11/site-packages/kor/nodes.py", line 280, in parse_raw
    raise NotImplementedError(
NotImplementedError: parse_raw is not supported for pydantic 2

What would be the way to do this with Pydantic 2?
Thanks!

@eyurtsev
Copy link
Owner

I was thinking about moving the serialization logic into a standalone function and implement something that doesn't rely as much on pydantic internals (and have pydantic only do the validation), but there's no solution yet.

Let me know if you're interested in working on it or have a solution in mind already.

@ChristianWeyer
Copy link
Author

For now, I could move back to Pydantic 1...

@eyurtsev
Copy link
Owner

eyurtsev commented Oct 6, 2023

@ChristianWeyer Linked PR that adds support for pydantic v2. It's a breaking change w/ respect to format, could you check whether you'll be able to make it work w/ your data?

@Brandl
Copy link

Brandl commented Mar 1, 2024

What is the progress on this, any updates?

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

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'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants