Skip to content

refactor(provider): enable maxInputTokens to be set by context length on Lemonade Server - #14

Open
matouka wants to merge 2 commits into
lemonade-sdk:mainfrom
matouka:feature/change-input-max-token-based-on-recipe
Open

refactor(provider): enable maxInputTokens to be set by context length on Lemonade Server#14
matouka wants to merge 2 commits into
lemonade-sdk:mainfrom
matouka:feature/change-input-max-token-based-on-recipe

Conversation

@matouka

@matouka matouka commented May 16, 2026

Copy link
Copy Markdown

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 imageInput field 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.

@matouka matouka changed the title refactor(provider): to allow for the maxInputTokens to be set by the … refactor(provider): enable maxInputTokens to be set by context length on Lemonade Server May 16, 2026

@danielholanda danielholanda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks good!

@danielholanda danielholanda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wait for fl0rianr to review before merging

@fl0rianr fl0rianr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants