Hello ! I need some help using structured outputs. I am trying to process the Table of Contents (TOC) of a corpus of pdf documents. I have a simple json schema called TOC Response, like so:
class TOCEntry(BaseModel):
entry: str # Define the ‘entry’ field as a string
nom_page: int # Define the ‘nom_page’ field as an integer
class TOCResponse(BaseModel):
toc_entries: List[TOCEntry]
I am sending messages to API as part of a payload (below), but when I include response_format in the payload, I get an error message saying “Object of type ModelMetaclass is not JSON serializable”.
Thank you so much ! I am afraid my code is a bit clunky as I jerry rigged from my earlier code to insert the response_format into the payload I was using, please see below, but it appears to be working in that it provides me with the json I need. It seems very expensive in terms of tokens and charges though, if there is a way to economize I would truly appreciate as I need to process hundreds of documents :