ContextWindowFromHeaders reads X-Context-Window. Returns 0 when missing, malformed, or out of sane range; the caller reads 0 as "use the fallback". Local Ollama never sets it, so it keeps its config.yaml value.
(h http.Header)
| 116 | // malformed, or out of sane range; the caller reads 0 as "use the fallback". |
| 117 | // Local Ollama never sets it, so it keeps its config.yaml value. |
| 118 | func ContextWindowFromHeaders(h http.Header) int { |
| 119 | raw := h.Get(headerCtxWindow) |
| 120 | if raw == "" { |
| 121 | return 0 |
| 122 | } |
| 123 | n, err := strconv.Atoi(raw) |
| 124 | if err != nil || n < ctxWindowMin || n > ctxWindowMaxSane { |
| 125 | return 0 |
| 126 | } |
| 127 | return n |
| 128 | } |
no outgoing calls