Replies: 3 comments 9 replies
-
Union[A, B, C], then you can use pattern matching. |
Beta Was this translation helpful? Give feedback.
-
Jason - have a look at https://github.com/zby/instructor/blob/main/examples/union/run.py Unfortunately I had to get back to checking the type of the returned object instead of using the process methods - because I need to keep state between calls and I don't know how to do that in the previous version. I get a lot of errors of the wrong data structure. They are caught by instructor - but I think there are too many such errors - maybe the structure is too difficult now? Also the messages array at the end does not look right - it seems that instructor does not add the corrected message there - only the wrong one is saved. Here is an example output:
|
Beta Was this translation helpful? Give feedback.
-
I'm using Unions to facilitate allowing the LLM to choose which type of entity to create, but then I tried to use it with Google's genai and that doesn't support Unions. I implemented a Google safe class that has a type field and a field for each possible type with a default_factor that makes it with an identifier that indicates it wasn't generated. the description of each field instructs it to only generate the one that matches the type. It is less reliable, only getting it right some of the time. I will experiment with the instructions to see if I can make it more reliable. definitely not as using Unions. I also had to modify the sub classes to not have optional fields, for str fields, I give it a default of "" and say Optional in the description. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say I have the classic pattern of a search and lookup functions - search finds the page, lookup looks up a fragment on that page containing a keyword. The LLM needs to decide if for the next step it wants to search for another page or lookup another part of the current page. How that can be achieved with instructor?
For reference here is the current schema that I pass to the 'tools' parameter:
Beta Was this translation helpful? Give feedback.
All reactions