eyurtsev / kor

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

Support for gradual migration of Pydantic V1 -> V2 #274

Closed Strryke closed 1 month ago

Strryke commented 4 months ago

Hi! I'm migrating a big codebase over from pydantic v1 to v2 and my initial approach is to upgrade to V2 and then change all imports to import from pydantic.v1 and slowly migrate things over.

Kor is throwing an error for me for the from_pydantic function as it seems to look for which version of pydantic is installed and use that one accordingly. I'm wondering if there's any way to have V2 installed but make Kor use V1 instead? thanks!

Argument of type "type[SupportTicket]" cannot be assigned to parameter "model_class" of type "type[BaseModel]" in function "from_pydantic" "type[SupportTicket]" is incompatible with "type[BaseModel]"

eyurtsev commented 4 months ago

It's not very difficult to do, but not top priority for me right now. I'm happy tor review a PR for this change if you're interested.

How many pydantic classes do you have that are being fed into Kor?

Strryke commented 4 months ago

Hey! i would be happy to open a PR for this change. my first thought would be to modify the _translate_pydantic_to_kor and from_pydantic function and allow it take take in a user's argument. let me know if this is a correct approach, thanks!

eyurtsev commented 4 months ago

It should be based on isinstance checks in the appropriate places instead of if checks on the pydantic major version.

All changes should be internal without any user facing API picking up additional variables