refactor(provider): enable maxInputTokens to be set by context length on Lemonade Server - #14
Conversation
…configured context size.
danielholanda
left a comment
There was a problem hiding this comment.
Please wait for fl0rianr to review before merging
fl0rianr
left a comment
There was a problem hiding this comment.
@danielholanda I was totally unaware my input is needed here. Just look into here by chance wondering why it wasn't merged yet.
@matouka Thanks! The direction makes sense, but I think this might need a small correction before mergeing
recipe_options.ctx_size is the model context window, while VS Code’s maxInputTokens is only the prompt/input budget and maxOutputTokens is advertised separately. The previous env-based path subtracts DEFAULT_MAX_OUTPUT_TOKENS from the context length, but this PR sets maxInputTokens directly to ctx_size. That can over-advertise the available context by up to 16k tokens, e.g. ctx_size=200000 becomes 200000 input + 16000 output.
I’d suggest deriving per-model budgets like:
const rawCtxSize = model?.recipe_options?.ctx_size;
const contextLength =
typeof rawCtxSize === "number" && Number.isFinite(rawCtxSize) && rawCtxSize > 0
? rawCtxSize
: resolveContextLength();
const modelMaxOutput = Math.min(DEFAULT_MAX_OUTPUT_TOKENS, Math.max(1, contextLength - 1));
const modelMaxInput = Math.max(1, contextLength - modelMaxOutput);and then using modelMaxInput / modelMaxOutput in the LanguageModelChatInformation.
And yes, I want to see this merged.
Sorry, new here to using Lemonade server. I'm not 100% sure if this is valid, or if it's just my setting. When I set my context explicitly on Lemonade Server, it's returned something like this from the models endpoint:
{ "data": [ { "checkpoint": "unsloth/Qwen3.6-35B-A3B-GGUF:Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf", "checkpoints": { "main": "unsloth/Qwen3.6-35B-A3B-GGUF:Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf", "mmproj": "unsloth/Qwen3.6-35B-A3B-GGUF:mmproj-F16.gguf" }, "created": 1234567890, "id": "Qwen3.6-35B-A3B-GGUF", "labels": [ "vision", "tool-calling", "hot" ], "object": "model", "owned_by": "lemonade", "recipe": "llamacpp", "recipe_options": { "ctx_size": 200000 }, "size": 22.4, "suggested": true }, ], "object": "list" }I removed some fields in the sample
So I thought why not at least attempt to pull in the allowable input tokens rather than having to set one single value, then used for all models, through an env setting.
Also, judging by the object returned, it looked like you should also be able to update the
imageInputfield using the labels. However, when I manually set it to true, the model didn't seem to make any use of it, so I haven't touched that.