Failing to Import Book via API
dacox opened this issue · 4 comments
Describe the bug
I am trying to create a book using the API, so that I can easily import lots of query/doc pairs for human raters to evaluate
To Reproduce
requests.post(f'{quepid_uri}/api/import/books.json', headers=headers, data=data).json()
{'status': 500, 'error': 'Internal Server Error'}
21:13:00 web.1 | I, [2024-04-25T21:13:00.430675 #37] INFO -- : [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] Started POST "/api/import/books.json" for 10.24.28.7 at 2024-04-25 21:13:00 +0000
21:13:00 web.1 | I, [2024-04-25T21:13:00.431928 #37] INFO -- : [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] Processing by Api::V1::Import::BooksController#create as JSON
21:13:00 web.1 | I, [2024-04-25T21:13:00.431982 #37] INFO -- : [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] Parameters: {"team_id"=>"1", "book"=>"query_doc_pairs"}
21:13:00 web.1 | W, [2024-04-25T21:13:00.432325 #37] WARN -- : [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] Can't verify CSRF token authenticity.
21:13:00 web.1 | I, [2024-04-25T21:13:00.438121 #37] INFO -- : [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] Completed 500 Internal Server Error in 6ms (ActiveRecord: 2.8ms | Allocations: 587)
21:13:00 web.1 | F, [2024-04-25T21:13:00.439035 #37] FATAL -- : [c8f04562-fc08-4ccf-b47c-8a7faa3bf071]
21:13:00 web.1 | [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] NoMethodError (undefined method `permit!' for "query_doc_pairs":String):
21:13:00 web.1 | [c8f04562-fc08-4ccf-b47c-8a7faa3bf071]
21:13:00 web.1 | [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] app/controllers/api/v1/import/books_controller.rb:87:in `book_params'
21:13:00 web.1 | [c8f04562-fc08-4ccf-b47c-8a7faa3bf071] app/controllers/api/v1/import/books_controller.rb:15:in `create'
I'm using PAT token.
and my JSON is formatted thusly:
{
"book": {
"name": "Media Quality/Suitability",
"show_rank": false,
"support_implicit_judgements": false,
"scorer": {
"communal": true,
"code": "var k = 10 // @Rank\nvar missing_rating = 0; // pessimistic assumption\n\nvar ideal = topRatings(k) // could return less than k if less than k docs have ratings\nvar scores = Array(k);\nfor (var i = 0; i < k; i++) {\n if (!ideal[i]) {\n ideal[i] = missing_rating;\n }\n if (hasDocRating(i)) {\n scores[i] = (docRating(i));\n } else {\n scores[i] = missing_rating;\n }\n}\n\nfunction DCG(vals, k) {\n var dcg = 0;\n for (var i = 0; i < k; i++) {\n var d = Math.log2(i + 2);\n var n = Math.pow(2, vals[i]) - 1;\n dcg += d ? (n / d) : 0;\n }\n return dcg;\n}\n\nfunction nDCG(vals, ideal, k) {\n var n = DCG(vals, k);\n var d = DCG(ideal, k);\n return d ? (n / d) : 0;\n}\n\nsetScore(nDCG(scores, ideal, k));\n\n",
"name": "nDCG@10",
"scale": [
0,
1,
2,
3
],
"owned": false,
"show_scale_labels": true,
"scale_with_labels": {
"0": "Poor",
"1": "Fair",
"2": "Good",
"3": "Perfect"
},
"teams": []
},
"selection_strategy": {
"name": "Multiple Raters",
"description": "Allows you to have up to three ratings for each query/doc pair. Gives higher quality ratings, however with more work."
},
"query_doc_pairs": [
{
"query_text": "AI",
"doc_id": "7d17d91b-1840-4214-a581-899847a5b4ef",
"position": 1,
"document_fields": {
},
"judgments": []
}
]
},
"team_id": 1
}
Expected behavior
200 OK - for the book to be created
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
taking a looksee today...
Okay, got to the bottom of the problem, and it turned out to be not what I thought! In your json, change to judgements
... I got cute and used the british spelling ;-).
Here is a gist of the script that I used.. https://gist.github.com/epugh/258f66c3672b62ccf14357b915e8fd01
Let me know if this works for you!!! If it doesn't, please reopen the ticket.
i do wish we had some sort of easy validation of JSON keys in Rails
Okay, got to the bottom of the problem, and it turned out to be not what I thought! In your json, change to
judgements
... I got cute and used the british spelling ;-).Here is a gist of the script that I used.. https://gist.github.com/epugh/258f66c3672b62ccf14357b915e8fd01
Let me know if this works for you!!! If it doesn't, please reopen the ticket.
😆 Wow! Glad it was a simple fix, I still didn't see the problem until I looked at the spelling side by side.
Thanks!