-
fix(ollama): accept float-encoded integer options (fixes #9837) (#9849)
发布于
2026-05-16 16:38:19 +00:00 fix(ollama): accept float-encoded integer options (num_ctx, top_k, ...)
Home Assistant's Ollama integration encodes integer options as JSON
floats (e.g."num_ctx": 8192.0). Stdlibjson.Unmarshalrefuses to
decode a number with fractional notation into anintfield, so the
entire request was rejected with HTTP 400 before reaching the backend:Unmarshal type error: expected=int, got=number 8192.0,
field=options.num_ctxAdd a custom
UnmarshalJSONonOllamaOptionsthat routes the int
fields (top_k,num_predict,seed,repeat_last_n,num_ctx)
through*json.Number, then converts viaInt64()with aFloat64()
fallback. Public field types are unchanged, so endpoint code is
untouched. Float fields andstopcontinue to parse via the default
path.Fixes #9837
Assisted-by: Claude Code:claude-opus-4-7
Signed-off-by: Ettore Di Giacinto mudler@localai.io
Co-authored-by: Ettore Di Giacinto mudler@localai.io下载附件