-
Notifications
You must be signed in to change notification settings - Fork 156
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
Documentation for returning an array of objects #45
Comments
Hey @atakanokan json_schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"car": {
"type": "object",
"properties": {
"make": {"type": "string"},
"model": {"type": "string"},
"horsepower": {"type": "number"}
}
}
}
}
} This should give you an array of car objects as long as you include that instruction inside the prompt. |
This doesn't work, at least not in version 0.12.0. Here's the traceback:
It seems that Jsonformer is ignoring the 'items' key and instead is looking just for 'properties. Or am i doing it wrongly? Thank you. |
@botka1998 a few more details:
I am not getting the error message from above anymore, but neither do i get the array. Here is the response:
Do you have any suggestions about what i should be doing differently? Thank you. |
Hey @mpetruc can you please share your json schema definition? Since it’s throwing a keyError, the schema is most likely invalid |
@botka1998 Here it is:
But like i said, after updating the call function i'm not getting the error anymore. It's just that i'm still getting only one item returned, as before. Thank you! |
Ok, I think the JSON schema i was using was wrong. Here's a very simple example of how it should really look like:
This is the schema structure expected by the original call function in main.py. So now i am using this type of schema with the original main.py as it gets installed from @botka1998 branch. However, i'm still not able to consistently get the arrays with prompts like this:
Calling the Jsonformer like this:
I rarely get more than 1 item generated, and never more than 3. Here's one example of response:
I tried using several models: mistral 7b, a couple llama3 fine tunes, openbmb/MiniCPM-2B-sft-fp32. I don't think i see a difference, they all terminate earlier than I expect them to. I also think that it's not the models' limitation because when i generate with the transformers' model.generate() method the response includes the specified number of items (10 in this case). Btw, the example above is obviously a toy example. What I'm really trying to use this for is for medication extraction, where i need to extract multiple drug names and their info from text snippets. So, what am i missing? Are you guys really able to get larger arrays consistently? Thank you. |
Hey @mpetruc sorry for the late and sporadic responses, I’m on holiday and away from my laptop.. I’m glad you figured out the schema part! Here’s my experience: Here’s what you could try: What I actually did in the fork: Note that this isn’t the best possible solution, before I added this, array generation didn’t work at all. I stopped working on this as soon as I got good results for my application. I am not a maintainer of the original repo and the owners are not interested in maintaining so i didn’t bother doing more than this PR.. Here’s the model i used: Here’s my prompt template
|
Thank you so much @botka1998 for the detailed, thoughtful response, and for taking the time to get back with me while you're on vacation! Much appreciated! |
@mpetruc @botka1998 A little guidance here please. Here is the schema i am using :
To extract line items from an invoice. A simple & straight forward use case, but the error thrown is |
Hey @projects-g I’m afk again so this is from memory, I can’t check this but… try it Make sure to start with an object that contains the array instead of the array immediately! json_schema = {
"type": "object",
"properties": {
"line_items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"item": {"type": "string"},
"quantity": {"type": "number"},
"price": {"type": "number"}
}
}
}
} |
Is there any way to return an array of objects (e.g. return multiple
car
objects):Here is an example I tried that gave the below error:
error:
The text was updated successfully, but these errors were encountered: