Skip to content

Commit 42aad70

Browse files
authored
Merge pull request #155 from artiz/claude/vlm-shim-openai-schema
dev: full OpenAI response schema in the VLM shim (#153)
2 parents 5fd2ce5 + 3a7a57a commit 42aad70

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)