feat: improve compatiblity with certain apps (#72)

* feat: enable modern packaging via pyproject.toml

uvx --from (...) chatmock should just work !

* feat(ollama): add version endpoint

* feat(logging): improve verbose diagnostics

* fix(stream): always send stop chunk
This commit is contained in:
Magniquick
2025-11-19 15:32:20 +05:30
committed by GitHub
parent a4b9ae9471
commit 13b1dddf75
11 changed files with 541 additions and 81 deletions

View File

@@ -389,6 +389,7 @@ def sse_translate_chat(
think_open = False
think_closed = False
saw_output = False
sent_stop_chunk = False
saw_any_summary = False
pending_summary_paragraph = False
upstream_usage = None
@@ -738,6 +739,7 @@ def sse_translate_chat(
"choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}],
}
yield f"data: {json.dumps(chunk)}\n\n".encode("utf-8")
sent_stop_chunk = True
elif kind == "response.failed":
err = evt.get("response", {}).get("error", {}).get("message", "response.failed")
chunk = {"error": {"message": err}}
@@ -757,6 +759,17 @@ def sse_translate_chat(
yield f"data: {json.dumps(close_chunk)}\n\n".encode("utf-8")
think_open = False
think_closed = True
if not sent_stop_chunk:
chunk = {
"id": response_id,
"object": "chat.completion.chunk",
"created": created,
"model": model,
"choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}],
}
yield f"data: {json.dumps(chunk)}\n\n".encode("utf-8")
sent_stop_chunk = True
if include_usage and upstream_usage:
try:
usage_chunk = {