Skip to content

Commit 3a7a57a

Browse files
artizclaude
andcommitted
dev: full OpenAI response schema in the VLM shim (#153)
Python docling validates chat-completion responses with a pydantic OpenAiApiResponse model that requires id/created (and reads usage); the shim payload lacked them, so the reference side of the corpus run failed on every request while docling.rs (which only reads choices[0]) worked. Emit the full envelope. Refs #153 Signed-off-by: artiz <artem.kustikov@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EY5KAiquN4YpVf2PXEQkVT
1 parent e983bd2 commit 3a7a57a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

scripts/dev/granite_vlm_server.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@ def do_POST(self): # noqa: N802 (http.server API)
105105
int(req.get("max_tokens", 8192)),
106106
)
107107
print(f"page converted in {time.time() - started:.1f}s, {len(text)} chars", flush=True)
108+
# id/created/usage: Python docling validates the response against a
109+
# full OpenAI schema (pydantic OpenAiApiResponse) and rejects a
110+
# payload without them; docling.rs only reads choices[0].
108111
payload = json.dumps(
109112
{
113+
"id": f"chatcmpl-{int(time.time() * 1000)}",
110114
"object": "chat.completion",
115+
"created": int(time.time()),
111116
"model": req.get("model", "granite-docling"),
112117
"choices": [
113118
{
@@ -116,6 +121,11 @@ def do_POST(self): # noqa: N802 (http.server API)
116121
"finish_reason": "stop",
117122
}
118123
],
124+
"usage": {
125+
"prompt_tokens": 0,
126+
"completion_tokens": 0,
127+
"total_tokens": 0,
128+
},
119129
}
120130
).encode()
121131
self.send_response(200)

0 commit comments

Comments
 (0)